Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 15 additions & 103 deletions src/AuditReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,7 @@ private function createEntity($className, array $columnMap, array $data, $revisi
$type = Type::getType(self::getMappingValue($classMetadata->fieldMappings[$field], 'type'));
$value = $type->convertToPHPValue($value, $this->platform);

/** @psalm-suppress DeprecatedProperty */
$reflField = $classMetadata->propertyAccessors[$field] ?? $classMetadata->reflFields[$field];
\assert(null !== $reflField);
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$reflField->setValue($entity, $value);
$classMetadata->setFieldValue($entity, $field, $value);
}
}

Expand Down Expand Up @@ -985,14 +978,7 @@ private function createEntity($className, array $columnMap, array $data, $revisi
}
}

/** @psalm-suppress DeprecatedProperty */
$reflField = $classMetadata->propertyAccessors[$field] ?? $classMetadata->reflFields[$field];
\assert(null !== $reflField);
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$reflField->setValue($entity, $value);
$classMetadata->setFieldValue($entity, $field, $value);
} elseif (
0 !== ($assoc['type'] & ClassMetadata::ONE_TO_MANY)
&& null !== $mappedBy
Expand All @@ -1003,14 +989,7 @@ private function createEntity($className, array $columnMap, array $data, $revisi
$foreignKeys = [];
foreach ($targetClass->associationMappings[$mappedBy]['sourceToTargetKeyColumns'] as $local => $foreign) {
$field = $classMetadata->getFieldForColumn($foreign);
/** @psalm-suppress DeprecatedProperty */
$reflField = $classMetadata->propertyAccessors[$field] ?? $classMetadata->reflFields[$field];
\assert(null !== $reflField);
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$foreignKeys[$local] = $reflField->getValue($entity);
$foreignKeys[$local] = $classMetadata->getFieldValue($entity, $field);
}

$collection = new AuditedCollection(
Expand All @@ -1035,30 +1014,14 @@ private function createEntity($className, array $columnMap, array $data, $revisi
}
}

/** @psalm-suppress DeprecatedProperty */
$reflField = $classMetadata->propertyAccessors[$assoc['fieldName']] ?? $classMetadata->reflFields[$assoc['fieldName']];
\assert(null !== $reflField);
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$reflField->setValue($entity, $collection);
$classMetadata->setFieldValue($entity, $assoc['fieldName'], $collection);
} elseif (self::isManyToMany($assoc)) {
if (self::isManyToManyOwningSideMapping($assoc)) {
$whereId = [$this->config->getRevisionFieldName().' = ?'];
$values = [$revision];
foreach (self::getRelationToSourceKeyColumns($assoc) as $sourceKeyJoinColumn => $sourceKeyColumn) {
$whereId[] = "{$sourceKeyJoinColumn} = ?";

/** @psalm-suppress DeprecatedProperty */
$reflField = $classMetadata->propertyAccessors['id'] ?? $classMetadata->reflFields['id'];
\assert(null !== $reflField);

/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$values[] = $reflField->getValue($entity);
$values[] = $classMetadata->getFieldValue($entity, 'id');
}

$whereSQL = implode(' AND ', $whereId);
Expand Down Expand Up @@ -1106,10 +1069,6 @@ private function createEntity($className, array $columnMap, array $data, $revisi
}
}
} else {
/** @psalm-suppress DeprecatedProperty */
$reflField = $classMetadata->propertyAccessors[$assoc['fieldName']] ?? $classMetadata->reflFields[$assoc['fieldName']];
\assert(null !== $reflField);

if ($this->loadNativeCollections) {
$collection = new PersistentCollection(
$this->em,
Expand All @@ -1120,29 +1079,14 @@ private function createEntity($className, array $columnMap, array $data, $revisi
$this->getEntityPersister($targetEntity)
->loadManyToManyCollection($assoc, $entity, $collection);

/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$reflField->setValue($entity, $collection);
$classMetadata->setFieldValue($entity, $assoc['fieldName'], $collection);
} else {
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$reflField->setValue($entity, new ArrayCollection());
$classMetadata->setFieldValue($entity, $assoc['fieldName'], new ArrayCollection());
}
}
}
/** @psalm-suppress DeprecatedProperty */
$reflField = $classMetadata->propertyAccessors[$field] ?? $classMetadata->reflFields[$field];
\assert(null !== $reflField);

/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$reflField->setValue($entity, $collection);

$classMetadata->setFieldValue($entity, $field, $collection);
} elseif (isset($targetClass->associationMappings[$mappedBy])) {
$targetAssoc = $targetClass->associationMappings[$mappedBy];
$whereId = [$this->config->getRevisionFieldName().' = ?'];
Expand All @@ -1162,14 +1106,7 @@ private function createEntity($className, array $columnMap, array $data, $revisi
)) {
foreach ($targetAssoc['relationToTargetKeyColumns'] as $targetKeyJoinColumn => $targetKeyColumn) {
$whereId[] = "{$targetKeyJoinColumn} = ?";
/** @psalm-suppress DeprecatedProperty */
$reflField = $classMetadata->propertyAccessors['id'] ?? $classMetadata->reflFields['id'];
\assert(null !== $reflField);
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$values[] = $reflField->getValue($entity);
$values[] = $classMetadata->getFieldValue($entity, 'id');
}

$whereSQL = implode(' AND ', $whereId);
Expand Down Expand Up @@ -1216,10 +1153,6 @@ private function createEntity($className, array $columnMap, array $data, $revisi
}
}
} else {
/** @psalm-suppress DeprecatedProperty */
$reflField = $classMetadata->propertyAccessors[$assoc['fieldName']] ?? $classMetadata->reflFields[$assoc['fieldName']];
\assert(null !== $reflField);

if ($this->loadNativeCollections) {
$collection = new PersistentCollection(
$this->em,
Expand All @@ -1230,38 +1163,17 @@ private function createEntity($className, array $columnMap, array $data, $revisi
$this->getEntityPersister($assoc['targetEntity'])
->loadManyToManyCollection($assoc, $entity, $collection);

/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$reflField->setValue($entity, $collection);
$classMetadata->setFieldValue($entity, $assoc['fieldName'], $collection);
} else {
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$reflField->setValue($entity, new ArrayCollection());
$classMetadata->setFieldValue($entity, $assoc['fieldName'], new ArrayCollection());
}
}
/** @psalm-suppress DeprecatedProperty */
$reflField = $classMetadata->propertyAccessors[$field] ?? $classMetadata->reflFields[$field];
\assert(null !== $reflField);
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$reflField->setValue($entity, $collection);

$classMetadata->setFieldValue($entity, $field, $collection);
}
} else {
// Inject collection
/** @psalm-suppress DeprecatedProperty */
$reflField = $classMetadata->propertyAccessors[$field] ?? $classMetadata->reflFields[$field];
\assert(null !== $reflField);
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$reflField->setValue($entity, new ArrayCollection());
$classMetadata->setFieldValue($entity, $field, new ArrayCollection());
}
}

Expand Down
36 changes: 4 additions & 32 deletions src/EventListener/LogRevisionsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,7 @@ public function postFlush(PostFlushEventArgs $eventArgs): void
throw new \RuntimeException('column name not found for'.$idField);
}

/** @psalm-suppress DeprecatedProperty */
$reflField = $meta->propertyAccessors[$idField] ?? $meta->reflFields[$idField];
\assert(null !== $reflField);
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$params[] = $reflField->getValue($entity);
$params[] = $meta->getFieldValue($entity, $idField);

$sql .= ' AND '.$columnName.' = ?';
}
Expand Down Expand Up @@ -347,14 +340,7 @@ private function getOriginalEntityData(EntityManagerInterface $em, object $entit
if ($class->isVersioned) {
$versionField = $class->versionField;
\assert(null !== $versionField);
/** @psalm-suppress DeprecatedProperty */
$reflField = $class->propertyAccessors[$versionField] ?? $class->reflFields[$versionField];
\assert(null !== $reflField);
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$data[$versionField] = $reflField->getValue($entity);
$data[$versionField] = $class->getFieldValue($entity, $versionField);
}

return $data;
Expand All @@ -371,14 +357,7 @@ private function getManyToManyRelations(EntityManagerInterface $em, object $enti
$class = $em->getClassMetadata($entity::class);
foreach ($class->associationMappings as $field => $assoc) {
if (self::isManyToManyOwningSideMapping($assoc)) {
/** @psalm-suppress DeprecatedProperty */
$reflField = $class->propertyAccessors[$field] ?? $class->reflFields[$field];
\assert(null !== $reflField);
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$data[$field] = $reflField->getValue($entity);
$data[$field] = $class->getFieldValue($entity, $field);
}
}

Expand Down Expand Up @@ -690,14 +669,7 @@ private function recordRevisionForManyToManyEntity(
}

foreach (self::getRelationToTargetKeyColumns($assoc) as $targetColumn) {
/** @psalm-suppress DeprecatedProperty */
$reflField = $targetClass->propertyAccessors[$targetClass->fieldNames[$targetColumn]] ?? $targetClass->reflFields[$targetClass->fieldNames[$targetColumn]];
\assert(null !== $reflField);
/**
* @psalm-suppress InternalMethod
* @phpstan-ignore-next-line method.internalInterface
*/
$joinTableParams[] = $reflField->getValue($relatedEntity);
$joinTableParams[] = $targetClass->getFieldValue($relatedEntity, $targetClass->fieldNames[$targetColumn]);
$joinTableTypes[] = PersisterHelper::getTypeOfColumn($targetColumn, $targetClass, $em);
}
/** @psalm-suppress InvalidArgument for doctrine/dbal 3 type can be integer */
Expand Down