Skip to content

Commit 8bf37a9

Browse files
Better way to deal with deprecations (#658)
1 parent 3fc53a9 commit 8bf37a9

2 files changed

Lines changed: 19 additions & 135 deletions

File tree

src/AuditReader.php

Lines changed: 15 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -880,14 +880,7 @@ private function createEntity($className, array $columnMap, array $data, $revisi
880880
$type = Type::getType(self::getMappingValue($classMetadata->fieldMappings[$field], 'type'));
881881
$value = $type->convertToPHPValue($value, $this->platform);
882882

883-
/** @psalm-suppress DeprecatedProperty */
884-
$reflField = $classMetadata->propertyAccessors[$field] ?? $classMetadata->reflFields[$field];
885-
\assert(null !== $reflField);
886-
/**
887-
* @psalm-suppress InternalMethod
888-
* @phpstan-ignore-next-line method.internalInterface
889-
*/
890-
$reflField->setValue($entity, $value);
883+
$classMetadata->setFieldValue($entity, $field, $value);
891884
}
892885
}
893886

@@ -985,14 +978,7 @@ private function createEntity($className, array $columnMap, array $data, $revisi
985978
}
986979
}
987980

988-
/** @psalm-suppress DeprecatedProperty */
989-
$reflField = $classMetadata->propertyAccessors[$field] ?? $classMetadata->reflFields[$field];
990-
\assert(null !== $reflField);
991-
/**
992-
* @psalm-suppress InternalMethod
993-
* @phpstan-ignore-next-line method.internalInterface
994-
*/
995-
$reflField->setValue($entity, $value);
981+
$classMetadata->setFieldValue($entity, $field, $value);
996982
} elseif (
997983
0 !== ($assoc['type'] & ClassMetadata::ONE_TO_MANY)
998984
&& null !== $mappedBy
@@ -1003,14 +989,7 @@ private function createEntity($className, array $columnMap, array $data, $revisi
1003989
$foreignKeys = [];
1004990
foreach ($targetClass->associationMappings[$mappedBy]['sourceToTargetKeyColumns'] as $local => $foreign) {
1005991
$field = $classMetadata->getFieldForColumn($foreign);
1006-
/** @psalm-suppress DeprecatedProperty */
1007-
$reflField = $classMetadata->propertyAccessors[$field] ?? $classMetadata->reflFields[$field];
1008-
\assert(null !== $reflField);
1009-
/**
1010-
* @psalm-suppress InternalMethod
1011-
* @phpstan-ignore-next-line method.internalInterface
1012-
*/
1013-
$foreignKeys[$local] = $reflField->getValue($entity);
992+
$foreignKeys[$local] = $classMetadata->getFieldValue($entity, $field);
1014993
}
1015994

1016995
$collection = new AuditedCollection(
@@ -1035,30 +1014,14 @@ private function createEntity($className, array $columnMap, array $data, $revisi
10351014
}
10361015
}
10371016

1038-
/** @psalm-suppress DeprecatedProperty */
1039-
$reflField = $classMetadata->propertyAccessors[$assoc['fieldName']] ?? $classMetadata->reflFields[$assoc['fieldName']];
1040-
\assert(null !== $reflField);
1041-
/**
1042-
* @psalm-suppress InternalMethod
1043-
* @phpstan-ignore-next-line method.internalInterface
1044-
*/
1045-
$reflField->setValue($entity, $collection);
1017+
$classMetadata->setFieldValue($entity, $assoc['fieldName'], $collection);
10461018
} elseif (self::isManyToMany($assoc)) {
10471019
if (self::isManyToManyOwningSideMapping($assoc)) {
10481020
$whereId = [$this->config->getRevisionFieldName().' = ?'];
10491021
$values = [$revision];
10501022
foreach (self::getRelationToSourceKeyColumns($assoc) as $sourceKeyJoinColumn => $sourceKeyColumn) {
10511023
$whereId[] = "{$sourceKeyJoinColumn} = ?";
1052-
1053-
/** @psalm-suppress DeprecatedProperty */
1054-
$reflField = $classMetadata->propertyAccessors['id'] ?? $classMetadata->reflFields['id'];
1055-
\assert(null !== $reflField);
1056-
1057-
/**
1058-
* @psalm-suppress InternalMethod
1059-
* @phpstan-ignore-next-line method.internalInterface
1060-
*/
1061-
$values[] = $reflField->getValue($entity);
1024+
$values[] = $classMetadata->getFieldValue($entity, 'id');
10621025
}
10631026

10641027
$whereSQL = implode(' AND ', $whereId);
@@ -1106,10 +1069,6 @@ private function createEntity($className, array $columnMap, array $data, $revisi
11061069
}
11071070
}
11081071
} else {
1109-
/** @psalm-suppress DeprecatedProperty */
1110-
$reflField = $classMetadata->propertyAccessors[$assoc['fieldName']] ?? $classMetadata->reflFields[$assoc['fieldName']];
1111-
\assert(null !== $reflField);
1112-
11131072
if ($this->loadNativeCollections) {
11141073
$collection = new PersistentCollection(
11151074
$this->em,
@@ -1120,29 +1079,14 @@ private function createEntity($className, array $columnMap, array $data, $revisi
11201079
$this->getEntityPersister($targetEntity)
11211080
->loadManyToManyCollection($assoc, $entity, $collection);
11221081

1123-
/**
1124-
* @psalm-suppress InternalMethod
1125-
* @phpstan-ignore-next-line method.internalInterface
1126-
*/
1127-
$reflField->setValue($entity, $collection);
1082+
$classMetadata->setFieldValue($entity, $assoc['fieldName'], $collection);
11281083
} else {
1129-
/**
1130-
* @psalm-suppress InternalMethod
1131-
* @phpstan-ignore-next-line method.internalInterface
1132-
*/
1133-
$reflField->setValue($entity, new ArrayCollection());
1084+
$classMetadata->setFieldValue($entity, $assoc['fieldName'], new ArrayCollection());
11341085
}
11351086
}
11361087
}
1137-
/** @psalm-suppress DeprecatedProperty */
1138-
$reflField = $classMetadata->propertyAccessors[$field] ?? $classMetadata->reflFields[$field];
1139-
\assert(null !== $reflField);
1140-
1141-
/**
1142-
* @psalm-suppress InternalMethod
1143-
* @phpstan-ignore-next-line method.internalInterface
1144-
*/
1145-
$reflField->setValue($entity, $collection);
1088+
1089+
$classMetadata->setFieldValue($entity, $field, $collection);
11461090
} elseif (isset($targetClass->associationMappings[$mappedBy])) {
11471091
$targetAssoc = $targetClass->associationMappings[$mappedBy];
11481092
$whereId = [$this->config->getRevisionFieldName().' = ?'];
@@ -1162,14 +1106,7 @@ private function createEntity($className, array $columnMap, array $data, $revisi
11621106
)) {
11631107
foreach ($targetAssoc['relationToTargetKeyColumns'] as $targetKeyJoinColumn => $targetKeyColumn) {
11641108
$whereId[] = "{$targetKeyJoinColumn} = ?";
1165-
/** @psalm-suppress DeprecatedProperty */
1166-
$reflField = $classMetadata->propertyAccessors['id'] ?? $classMetadata->reflFields['id'];
1167-
\assert(null !== $reflField);
1168-
/**
1169-
* @psalm-suppress InternalMethod
1170-
* @phpstan-ignore-next-line method.internalInterface
1171-
*/
1172-
$values[] = $reflField->getValue($entity);
1109+
$values[] = $classMetadata->getFieldValue($entity, 'id');
11731110
}
11741111

11751112
$whereSQL = implode(' AND ', $whereId);
@@ -1216,10 +1153,6 @@ private function createEntity($className, array $columnMap, array $data, $revisi
12161153
}
12171154
}
12181155
} else {
1219-
/** @psalm-suppress DeprecatedProperty */
1220-
$reflField = $classMetadata->propertyAccessors[$assoc['fieldName']] ?? $classMetadata->reflFields[$assoc['fieldName']];
1221-
\assert(null !== $reflField);
1222-
12231156
if ($this->loadNativeCollections) {
12241157
$collection = new PersistentCollection(
12251158
$this->em,
@@ -1230,38 +1163,17 @@ private function createEntity($className, array $columnMap, array $data, $revisi
12301163
$this->getEntityPersister($assoc['targetEntity'])
12311164
->loadManyToManyCollection($assoc, $entity, $collection);
12321165

1233-
/**
1234-
* @psalm-suppress InternalMethod
1235-
* @phpstan-ignore-next-line method.internalInterface
1236-
*/
1237-
$reflField->setValue($entity, $collection);
1166+
$classMetadata->setFieldValue($entity, $assoc['fieldName'], $collection);
12381167
} else {
1239-
/**
1240-
* @psalm-suppress InternalMethod
1241-
* @phpstan-ignore-next-line method.internalInterface
1242-
*/
1243-
$reflField->setValue($entity, new ArrayCollection());
1168+
$classMetadata->setFieldValue($entity, $assoc['fieldName'], new ArrayCollection());
12441169
}
12451170
}
1246-
/** @psalm-suppress DeprecatedProperty */
1247-
$reflField = $classMetadata->propertyAccessors[$field] ?? $classMetadata->reflFields[$field];
1248-
\assert(null !== $reflField);
1249-
/**
1250-
* @psalm-suppress InternalMethod
1251-
* @phpstan-ignore-next-line method.internalInterface
1252-
*/
1253-
$reflField->setValue($entity, $collection);
1171+
1172+
$classMetadata->setFieldValue($entity, $field, $collection);
12541173
}
12551174
} else {
12561175
// Inject collection
1257-
/** @psalm-suppress DeprecatedProperty */
1258-
$reflField = $classMetadata->propertyAccessors[$field] ?? $classMetadata->reflFields[$field];
1259-
\assert(null !== $reflField);
1260-
/**
1261-
* @psalm-suppress InternalMethod
1262-
* @phpstan-ignore-next-line method.internalInterface
1263-
*/
1264-
$reflField->setValue($entity, new ArrayCollection());
1176+
$classMetadata->setFieldValue($entity, $field, new ArrayCollection());
12651177
}
12661178
}
12671179

src/EventListener/LogRevisionsListener.php

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,7 @@ public function postFlush(PostFlushEventArgs $eventArgs): void
198198
throw new \RuntimeException('column name not found for'.$idField);
199199
}
200200

201-
/** @psalm-suppress DeprecatedProperty */
202-
$reflField = $meta->propertyAccessors[$idField] ?? $meta->reflFields[$idField];
203-
\assert(null !== $reflField);
204-
/**
205-
* @psalm-suppress InternalMethod
206-
* @phpstan-ignore-next-line method.internalInterface
207-
*/
208-
$params[] = $reflField->getValue($entity);
201+
$params[] = $meta->getFieldValue($entity, $idField);
209202

210203
$sql .= ' AND '.$columnName.' = ?';
211204
}
@@ -347,14 +340,7 @@ private function getOriginalEntityData(EntityManagerInterface $em, object $entit
347340
if ($class->isVersioned) {
348341
$versionField = $class->versionField;
349342
\assert(null !== $versionField);
350-
/** @psalm-suppress DeprecatedProperty */
351-
$reflField = $class->propertyAccessors[$versionField] ?? $class->reflFields[$versionField];
352-
\assert(null !== $reflField);
353-
/**
354-
* @psalm-suppress InternalMethod
355-
* @phpstan-ignore-next-line method.internalInterface
356-
*/
357-
$data[$versionField] = $reflField->getValue($entity);
343+
$data[$versionField] = $class->getFieldValue($entity, $versionField);
358344
}
359345

360346
return $data;
@@ -371,14 +357,7 @@ private function getManyToManyRelations(EntityManagerInterface $em, object $enti
371357
$class = $em->getClassMetadata($entity::class);
372358
foreach ($class->associationMappings as $field => $assoc) {
373359
if (self::isManyToManyOwningSideMapping($assoc)) {
374-
/** @psalm-suppress DeprecatedProperty */
375-
$reflField = $class->propertyAccessors[$field] ?? $class->reflFields[$field];
376-
\assert(null !== $reflField);
377-
/**
378-
* @psalm-suppress InternalMethod
379-
* @phpstan-ignore-next-line method.internalInterface
380-
*/
381-
$data[$field] = $reflField->getValue($entity);
360+
$data[$field] = $class->getFieldValue($entity, $field);
382361
}
383362
}
384363

@@ -690,14 +669,7 @@ private function recordRevisionForManyToManyEntity(
690669
}
691670

692671
foreach (self::getRelationToTargetKeyColumns($assoc) as $targetColumn) {
693-
/** @psalm-suppress DeprecatedProperty */
694-
$reflField = $targetClass->propertyAccessors[$targetClass->fieldNames[$targetColumn]] ?? $targetClass->reflFields[$targetClass->fieldNames[$targetColumn]];
695-
\assert(null !== $reflField);
696-
/**
697-
* @psalm-suppress InternalMethod
698-
* @phpstan-ignore-next-line method.internalInterface
699-
*/
700-
$joinTableParams[] = $reflField->getValue($relatedEntity);
672+
$joinTableParams[] = $targetClass->getFieldValue($relatedEntity, $targetClass->fieldNames[$targetColumn]);
701673
$joinTableTypes[] = PersisterHelper::getTypeOfColumn($targetColumn, $targetClass, $em);
702674
}
703675
/** @psalm-suppress InvalidArgument for doctrine/dbal 3 type can be integer */

0 commit comments

Comments
 (0)