From 7e379f6872ad79debc2be4625a48cc1c79d96d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 3 Jan 2023 22:55:49 +0100 Subject: [PATCH] Migrate files with the least changes to PHP 8 These are the lowest hanging fruits I could find after running Rector: I looked for files with a diff of 2 lines. I did not include some changes that I find controversial, such as marking some constants as final when we should maybe consider making classes themselves final. --- lib/Doctrine/ORM/Cache/DefaultCacheFactory.php | 2 +- lib/Doctrine/ORM/EntityRepository.php | 2 +- lib/Doctrine/ORM/Id/AssignedGenerator.php | 4 +--- lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php | 2 +- lib/Doctrine/ORM/Mapping/ChainTypedFieldMapper.php | 2 +- lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | 2 ++ lib/Doctrine/ORM/Mapping/Driver/AttributeReader.php | 2 +- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 3 ++- 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php index f9240f2a5f2..d9f082c9324 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php +++ b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php @@ -47,7 +47,7 @@ public function setFileLockRegionDirectory(string $fileLockRegionDirectory): voi $this->fileLockRegionDirectory = $fileLockRegionDirectory; } - public function getFileLockRegionDirectory(): string + public function getFileLockRegionDirectory(): string|null { return $this->fileLockRegionDirectory; } diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index bc5597877cc..71dd1e47437 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -196,7 +196,7 @@ protected function getClassMetadata(): ClassMetadata * * @psalm-return AbstractLazyCollection&Selectable */ - public function matching(Criteria $criteria): AbstractLazyCollection + public function matching(Criteria $criteria): AbstractLazyCollection&Selectable { $persister = $this->em->getUnitOfWork()->getEntityPersister($this->entityName); diff --git a/lib/Doctrine/ORM/Id/AssignedGenerator.php b/lib/Doctrine/ORM/Id/AssignedGenerator.php index 093049ec13c..6c3c8a21d6c 100644 --- a/lib/Doctrine/ORM/Id/AssignedGenerator.php +++ b/lib/Doctrine/ORM/Id/AssignedGenerator.php @@ -7,8 +7,6 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Exception\EntityMissingAssignedId; -use function get_class; - /** * Special generator for application-assigned identifiers (doesn't really generate anything). */ @@ -23,7 +21,7 @@ class AssignedGenerator extends AbstractIdGenerator */ public function generateId(EntityManagerInterface $em, object|null $entity): array { - $class = $em->getClassMetadata(get_class($entity)); + $class = $em->getClassMetadata($entity::class); $idFields = $class->getIdentifierFieldNames(); $identifier = []; diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 5c027270650..6dd8adee66d 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -45,7 +45,7 @@ class ObjectHydrator extends AbstractHydrator private array $initializedCollections = []; /** @var array */ - private $uninitializedCollections = []; + private array $uninitializedCollections = []; /** @var mixed[] */ private array $existingCollections = []; diff --git a/lib/Doctrine/ORM/Mapping/ChainTypedFieldMapper.php b/lib/Doctrine/ORM/Mapping/ChainTypedFieldMapper.php index 0a8544cec1e..e4a9a590f03 100644 --- a/lib/Doctrine/ORM/Mapping/ChainTypedFieldMapper.php +++ b/lib/Doctrine/ORM/Mapping/ChainTypedFieldMapper.php @@ -12,7 +12,7 @@ final class ChainTypedFieldMapper implements TypedFieldMapper * @readonly * @var TypedFieldMapper[] $typedFieldMappers */ - private array $typedFieldMappers; + private readonly array $typedFieldMappers; public function __construct(TypedFieldMapper ...$typedFieldMappers) { diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 926b85e09fd..366ed2bc37f 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -588,6 +588,8 @@ protected function initializeReflection(ClassMetadataInterface $class, Reflectio protected function getDriver(): MappingDriver { + assert($this->driver !== null); + return $this->driver; } diff --git a/lib/Doctrine/ORM/Mapping/Driver/AttributeReader.php b/lib/Doctrine/ORM/Mapping/Driver/AttributeReader.php index 2256e37a290..783b55f21fd 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AttributeReader.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AttributeReader.php @@ -60,7 +60,7 @@ public function getPropertyAttributes(ReflectionProperty $property): array * * @template T of MappingAttribute */ - public function getPropertyAttribute(ReflectionProperty $property, $attributeName) + public function getPropertyAttribute(ReflectionProperty $property, string $attributeName) { if ($this->isRepeatable($attributeName)) { throw new LogicException(sprintf( diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 1d1dfed0e70..29f37756eb3 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -10,6 +10,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\ParameterTypeInferer; use InvalidArgumentException; +use Stringable; use function array_map; use function implode; @@ -23,7 +24,7 @@ * * @abstract */ -abstract class SQLFilter +abstract class SQLFilter implements Stringable { /** * Parameters for the filter.