Skip to content

Commit

Permalink
Add isManyToMany and remove deprecated exception
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Jun 24, 2024
1 parent 2510acf commit 3c45b4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
28 changes: 1 addition & 27 deletions src/AuditReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\QuoteStrategy;
use Doctrine\ORM\ORMException as ORM2Exception;
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\Persisters\Entity\EntityPersister;
use SimpleThings\EntityAudit\Collection\AuditedCollection;
Expand Down Expand Up @@ -190,17 +189,12 @@ public function clearEntityCache(): void
* @throws NotAuditedException
* @throws Exception
* @throws ORMException
* @throws ORM2Exception
* @throws \RuntimeException
*
* @return object|null
*
* @psalm-suppress UndefinedDocblockClass
*
* @phpstan-param class-string<T> $className
* @phpstan-return T|null
*
* @phpstan-ignore throws.notThrowable
*/
public function find($className, $id, $revision, array $options = [])
{
Expand Down Expand Up @@ -389,15 +383,10 @@ public function findEntitesChangedAtRevision($revision)
* @throws NotAuditedException
* @throws Exception
* @throws ORMException
* @throws ORM2Exception
* @throws \RuntimeException
* @throws DeletedException
*
* @return ChangedEntity<object>[]
*
* @psalm-suppress UndefinedDocblockClass
*
* @phpstan-ignore throws.notThrowable
*/
public function findEntitiesChangedAtRevision($revision)
{
Expand Down Expand Up @@ -648,17 +637,12 @@ public function getCurrentRevision($className, $id)
* @throws NotAuditedException
* @throws Exception
* @throws ORMException
* @throws ORM2Exception
* @throws \RuntimeException
*
* @return array<string, array<string, mixed>>
*
* @psalm-suppress UndefinedDocblockClass
*
* @phpstan-param class-string $className
* @phpstan-return array<string, array{old: mixed, new: mixed, same: mixed}>
*
* @phpstan-ignore throws.notThrowable
*/
public function diff($className, $id, $oldRevision, $newRevision)
{
Expand Down Expand Up @@ -706,17 +690,12 @@ public function getEntityValues($className, $entity)
* @throws NotAuditedException
* @throws Exception
* @throws ORMException
* @throws ORM2Exception
* @throws DeletedException
*
* @return array<object|null>
*
* @psalm-suppress UndefinedDocblockClass
*
* @phpstan-param class-string<T> $className
* @phpstan-return array<T|null>
*
* @phpstan-ignore throws.notThrowable
*/
public function getEntityHistory($className, $id)
{
Expand Down Expand Up @@ -823,17 +802,12 @@ protected function getEntityPersister($className)
* @throws NotAuditedException
* @throws Exception
* @throws ORMException
* @throws ORM2Exception
* @throws \RuntimeException
*
* @return object
*
* @psalm-suppress UndefinedDocblockClass
*
* @phpstan-param class-string<T> $className
* @phpstan-return T
*
* @phpstan-ignore throws.notThrowable
*/
private function createEntity($className, array $columnMap, array $data, $revision)
{
Expand Down Expand Up @@ -1041,7 +1015,7 @@ private function createEntity($className, array $columnMap, array $data, $revisi
$reflField = $classMetadata->reflFields[$assoc['fieldName']];
\assert(null !== $reflField);
$reflField->setValue($entity, $collection);
} elseif (0 !== ($assoc['type'] & ClassMetadata::MANY_TO_MANY)) {
} elseif (self::isManyToMany($assoc)) {
if (self::isManyToManyOwningSideMapping($assoc)) {
$whereId = [$this->config->getRevisionFieldName().' = ?'];
$values = [$revision];
Expand Down
20 changes: 15 additions & 5 deletions src/Utils/ORMCompatibilityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ final protected static function getMappingJoinTableNameValue(array|ManyToManyOwn
final protected static function isManyToManyOwningSideMapping(array|AssociationMapping $mapping): bool
{
if ($mapping instanceof AssociationMapping) {
return $mapping instanceof ManyToManyOwningSideMapping;
return $mapping->isManyToMany() && $mapping->isOwningSide();
}

return true === $mapping['isOwningSide']
&& ($mapping['type'] & ClassMetadata::MANY_TO_MANY) > 0;
return true === $mapping['isOwningSide'] && ($mapping['type'] & ClassMetadata::MANY_TO_MANY) > 0;
}

/**
Expand All @@ -130,8 +129,7 @@ final protected static function isToOneOwningSide(array|AssociationMapping $mapp
return $mapping->isToOneOwningSide();
}

return ($mapping['type'] & ClassMetadata::TO_ONE) > 0
&& true === $mapping['isOwningSide'];
return ($mapping['type'] & ClassMetadata::TO_ONE) > 0 && true === $mapping['isOwningSide'];
}

/**
Expand All @@ -146,6 +144,18 @@ final protected static function isToOne(array|AssociationMapping $mapping): bool
return ($mapping['type'] & ClassMetadata::TO_ONE) > 0;
}

/**
* @param array<string, mixed>|AssociationMapping $mapping
*/
final protected static function isManyToMany(array|AssociationMapping $mapping): bool
{
if ($mapping instanceof AssociationMapping) {
return $mapping->isManyToMany();
}

return ($mapping['type'] & ClassMetadata::MANY_TO_MANY) > 0;
}

/**
* @param array<string, mixed>|ToOneOwningSideMapping $mapping
*
Expand Down

0 comments on commit 3c45b4c

Please sign in to comment.