diff --git a/lib/Doctrine/ORM/ORMInvalidArgumentException.php b/lib/Doctrine/ORM/ORMInvalidArgumentException.php index db20c3d994a..aa98cad1e39 100644 --- a/lib/Doctrine/ORM/ORMInvalidArgumentException.php +++ b/lib/Doctrine/ORM/ORMInvalidArgumentException.php @@ -24,43 +24,22 @@ */ class ORMInvalidArgumentException extends InvalidArgumentException { - /** - * @param object $entity - * - * @return ORMInvalidArgumentException - */ - public static function scheduleInsertForManagedEntity($entity) + public static function scheduleInsertForManagedEntity(object $entity): self { return new self('A managed+dirty entity ' . self::objToStr($entity) . ' can not be scheduled for insertion.'); } - /** - * @param object $entity - * - * @return ORMInvalidArgumentException - */ - public static function scheduleInsertForRemovedEntity($entity) + public static function scheduleInsertForRemovedEntity(object $entity): self { return new self('Removed entity ' . self::objToStr($entity) . ' can not be scheduled for insertion.'); } - /** - * @param object $entity - * - * @return ORMInvalidArgumentException - */ - public static function scheduleInsertTwice($entity) + public static function scheduleInsertTwice(object $entity): self { return new self('Entity ' . self::objToStr($entity) . ' can not be scheduled for insertion twice.'); } - /** - * @param string $className - * @param object $entity - * - * @return ORMInvalidArgumentException - */ - public static function entityWithoutIdentity($className, $entity) + public static function entityWithoutIdentity(string $className, object $entity): self { return new self( "The given entity of type '" . $className . "' (" . self::objToStr($entity) . ') has no identity/no ' . @@ -68,12 +47,7 @@ public static function entityWithoutIdentity($className, $entity) ); } - /** - * @param object $entity - * - * @return ORMInvalidArgumentException - */ - public static function readOnlyRequiresManagedEntity($entity) + public static function readOnlyRequiresManagedEntity(object $entity): self { return new self('Only managed entities can be marked or checked as read only. But ' . self::objToStr($entity) . ' is not'); } @@ -81,10 +55,8 @@ public static function readOnlyRequiresManagedEntity($entity) /** * @param array[][]|object[][] $newEntitiesWithAssociations non-empty an array * of [array $associationMapping, object $entity] pairs - * - * @return ORMInvalidArgumentException */ - public static function newEntitiesFoundThroughRelationships($newEntitiesWithAssociations) + public static function newEntitiesFoundThroughRelationships(array $newEntitiesWithAssociations): self { $errorMessages = array_map( static function (array $newEntityWithAssociation): string { @@ -106,96 +78,54 @@ static function (array $newEntityWithAssociation): string { ); } - /** - * @param object $entry - * @psalm-param AssociationMapping $associationMapping - * - * @return ORMInvalidArgumentException - */ - public static function newEntityFoundThroughRelationship(array $associationMapping, $entry) + /** @psalm-param AssociationMapping $associationMapping */ + public static function newEntityFoundThroughRelationship(array $associationMapping, object $entry): self { return new self(self::newEntityFoundThroughRelationshipMessage($associationMapping, $entry)); } - /** - * @param object $entry - * @psalm-param array $assoc - * - * @return ORMInvalidArgumentException - */ - public static function detachedEntityFoundThroughRelationship(array $assoc, $entry) + /** @psalm-param array $assoc */ + public static function detachedEntityFoundThroughRelationship(array $assoc, object $entry): self { return new self('A detached entity of type ' . $assoc['targetEntity'] . ' (' . self::objToStr($entry) . ') ' . " was found through the relationship '" . $assoc['sourceEntity'] . '#' . $assoc['fieldName'] . "' " . 'during cascading a persist operation.'); } - /** - * @param object $entity - * - * @return ORMInvalidArgumentException - */ - public static function entityNotManaged($entity) + public static function entityNotManaged(object $entity): self { return new self('Entity ' . self::objToStr($entity) . ' is not managed. An entity is managed if its fetched ' . 'from the database or registered as new through EntityManager#persist'); } - /** - * @param object $entity - * @param string $operation - * - * @return ORMInvalidArgumentException - */ - public static function entityHasNoIdentity($entity, $operation) + public static function entityHasNoIdentity(object $entity, string $operation): self { return new self('Entity has no identity, therefore ' . $operation . ' cannot be performed. ' . self::objToStr($entity)); } - /** - * @param object $entity - * @param string $operation - * - * @return ORMInvalidArgumentException - */ - public static function entityIsRemoved($entity, $operation) + public static function entityIsRemoved(object $entity, string $operation): self { return new self('Entity is removed, therefore ' . $operation . ' cannot be performed. ' . self::objToStr($entity)); } - /** - * @param object $entity - * @param string $operation - * - * @return ORMInvalidArgumentException - */ - public static function detachedEntityCannot($entity, $operation) + public static function detachedEntityCannot(object $entity, string $operation): self { return new self('Detached entity ' . self::objToStr($entity) . ' cannot be ' . $operation); } - /** - * @param string $context - * @param mixed $given - * @param int $parameterIndex - * - * @return ORMInvalidArgumentException - */ - public static function invalidObject($context, $given, $parameterIndex = 1) + public static function invalidObject(string $context, mixed $given, int $parameterIndex = 1): self { return new self($context . ' expects parameter ' . $parameterIndex . ' to be an entity object, ' . gettype($given) . ' given.'); } - /** @return ORMInvalidArgumentException */ - public static function invalidCompositeIdentifier() + public static function invalidCompositeIdentifier(): self { return new self('Binding an entity with a composite primary key to a query is not supported. ' . 'You should split the parameter into the explicit fields and bind them separately.'); } - /** @return ORMInvalidArgumentException */ - public static function invalidIdentifierBindingEntity(string $class) + public static function invalidIdentifierBindingEntity(string $class): self { return new self(sprintf( <<<'EXCEPTION' @@ -207,13 +137,8 @@ public static function invalidIdentifierBindingEntity(string $class) )); } - /** - * @param mixed[] $assoc - * @param mixed $actualValue - * - * @return self - */ - public static function invalidAssociation(ClassMetadata $targetClass, $assoc, $actualValue) + /** @param mixed[] $assoc */ + public static function invalidAssociation(ClassMetadata $targetClass, array $assoc, mixed $actualValue): self { $expectedType = $targetClass->getName(); diff --git a/lib/Doctrine/ORM/OptimisticLockException.php b/lib/Doctrine/ORM/OptimisticLockException.php index 527990fa954..63bff462d60 100644 --- a/lib/Doctrine/ORM/OptimisticLockException.php +++ b/lib/Doctrine/ORM/OptimisticLockException.php @@ -15,56 +15,40 @@ */ class OptimisticLockException extends Exception implements ORMException { - /** - * @param string $msg - * @param object|string|null $entity - */ - public function __construct($msg, private $entity, Throwable|null $previous = null) - { + public function __construct( + string $msg, + private object|string|null $entity, + Throwable|null $previous = null, + ) { parent::__construct($msg, 0, $previous); } /** * Gets the entity that caused the exception. - * - * @return object|string|null */ - public function getEntity() + public function getEntity(): object|string|null { return $this->entity; } - /** - * @param object|class-string $entity - * - * @return OptimisticLockException - */ - public static function lockFailed($entity) + /** @param object|class-string $entity */ + public static function lockFailed(object|string $entity): self { return new self('The optimistic lock on an entity failed.', $entity); } - /** - * @param object $entity - * @param int|string|DateTimeInterface $expectedLockVersion - * @param int|string|DateTimeInterface $actualLockVersion - * - * @return OptimisticLockException - */ - public static function lockFailedVersionMismatch($entity, $expectedLockVersion, $actualLockVersion) - { + public static function lockFailedVersionMismatch( + object $entity, + int|string|DateTimeInterface $expectedLockVersion, + int|string|DateTimeInterface $actualLockVersion, + ): self { $expectedLockVersion = $expectedLockVersion instanceof DateTimeInterface ? $expectedLockVersion->getTimestamp() : $expectedLockVersion; $actualLockVersion = $actualLockVersion instanceof DateTimeInterface ? $actualLockVersion->getTimestamp() : $actualLockVersion; return new self('The optimistic lock failed, version ' . $expectedLockVersion . ' was expected, but is actually ' . $actualLockVersion, $entity); } - /** - * @param string $entityName - * - * @return OptimisticLockException - */ - public static function notVersioned($entityName) + public static function notVersioned(string $entityName): self { return new self('Cannot obtain optimistic lock on unversioned entity ' . $entityName, null); }