From f5e7ddb21c9d5a3590958dd67808a6ed4e187ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 8 Feb 2023 20:07:39 +0100 Subject: [PATCH] Migrate the rest of the source code to PHP 8 syntax --- .../Mapping/DefaultEntityListenerResolver.php | 3 +-- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 22 +++++++------------ lib/Doctrine/ORM/OptimisticLockException.php | 2 +- lib/Doctrine/ORM/Query/AST/PathExpression.php | 2 +- .../ORM/Query/Exec/AbstractSqlExecutor.php | 2 +- .../Pagination/LimitSubqueryOutputWalker.php | 12 +++++----- lib/Doctrine/ORM/UnitOfWork.php | 5 ++--- psalm-baseline.xml | 10 --------- 8 files changed, 20 insertions(+), 38 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/DefaultEntityListenerResolver.php b/lib/Doctrine/ORM/Mapping/DefaultEntityListenerResolver.php index 34c8940faf8..0b3e7a26724 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultEntityListenerResolver.php +++ b/lib/Doctrine/ORM/Mapping/DefaultEntityListenerResolver.php @@ -4,7 +4,6 @@ namespace Doctrine\ORM\Mapping; -use function get_class; use function trim; /** @@ -29,7 +28,7 @@ public function clear(string|null $className = null): void public function register(object $object): void { - $this->instances[get_class($object)] = $object; + $this->instances[$object::class] = $object; } public function resolve(string $className): object diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 424cdde987e..4ba2e38d679 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -11,6 +11,7 @@ use Doctrine\ORM\Mapping\MappingException; use Doctrine\Persistence\Mapping\ClassMetadata as PersistenceClassMetadata; use Doctrine\Persistence\Mapping\Driver\FileDriver; +use Doctrine\Persistence\Mapping\Driver\FileLocator; use DOMDocument; use InvalidArgumentException; use LogicException; @@ -41,14 +42,14 @@ class XmlDriver extends FileDriver { public const DEFAULT_FILE_EXTENSION = '.dcm.xml'; - /** @var bool */ - private $isXsdValidationEnabled; - /** * {@inheritDoc} */ - public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION, bool $isXsdValidationEnabled = false) - { + public function __construct( + string|array|FileLocator $locator, + string $fileExtension = self::DEFAULT_FILE_EXTENSION, + private readonly bool $isXsdValidationEnabled = false, + ) { if (! extension_loaded('simplexml')) { throw new LogicException(sprintf( 'The XML metadata driver cannot be enabled because the SimpleXML PHP extension is missing.' @@ -73,8 +74,6 @@ public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENS )); } - $this->isXsdValidationEnabled = $isXsdValidationEnabled; - parent::__construct($locator, $fileExtension); } @@ -86,7 +85,7 @@ public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENS * * @template T of object */ - public function loadMetadataForClass($className, PersistenceClassMetadata $metadata) + public function loadMetadataForClass($className, PersistenceClassMetadata $metadata): void { $xmlRoot = $this->getElement($className); assert($xmlRoot instanceof SimpleXMLElement); @@ -962,12 +961,7 @@ private function validateMapping(string $file): void } } - /** - * @param mixed $element - * - * @return bool - */ - protected function evaluateBoolean($element) + protected function evaluateBoolean(mixed $element): bool { $flag = (string) $element; diff --git a/lib/Doctrine/ORM/OptimisticLockException.php b/lib/Doctrine/ORM/OptimisticLockException.php index 63bff462d60..f84e134b05e 100644 --- a/lib/Doctrine/ORM/OptimisticLockException.php +++ b/lib/Doctrine/ORM/OptimisticLockException.php @@ -17,7 +17,7 @@ class OptimisticLockException extends Exception implements ORMException { public function __construct( string $msg, - private object|string|null $entity, + private readonly object|string|null $entity, Throwable|null $previous = null, ) { parent::__construct($msg, 0, $previous); diff --git a/lib/Doctrine/ORM/Query/AST/PathExpression.php b/lib/Doctrine/ORM/Query/AST/PathExpression.php index 4f5ce93c976..4a56fcdf367 100644 --- a/lib/Doctrine/ORM/Query/AST/PathExpression.php +++ b/lib/Doctrine/ORM/Query/AST/PathExpression.php @@ -22,7 +22,7 @@ class PathExpression extends Node final public const TYPE_STATE_FIELD = 8; /** @psalm-var self::TYPE_*|null */ - public int|null $type; + public int|null $type = null; /** @psalm-param int-mask-of $expectedType */ public function __construct( diff --git a/lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php b/lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php index 0820b859a9c..1ec778cff79 100644 --- a/lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php @@ -21,7 +21,7 @@ abstract class AbstractSqlExecutor /** @var list|string */ protected array|string $sqlStatements; - protected QueryCacheProfile|null $queryCacheProfile; + protected QueryCacheProfile|null $queryCacheProfile = null; /** * Gets the SQL statements that are executed by the executor. diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php index feac361a217..c6826b54739 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php @@ -55,12 +55,12 @@ class LimitSubqueryOutputWalker extends SqlWalker { private const ORDER_BY_PATH_EXPRESSION = '/(? */ private array $orderByPathExpressions = []; diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index bb8f56830d1..ec59e1c266b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -55,7 +55,6 @@ use function array_filter; use function array_key_exists; use function array_map; -use function array_merge; use function array_pop; use function array_sum; use function array_values; @@ -983,7 +982,7 @@ public function recomputeSingleEntityChangeSet(ClassMetadata $class, object $ent if ($changeSet) { if (isset($this->entityChangeSets[$oid])) { - $this->entityChangeSets[$oid] = array_merge($this->entityChangeSets[$oid], $changeSet); + $this->entityChangeSets[$oid] = [...$this->entityChangeSets[$oid], ...$changeSet]; } elseif (! isset($this->entityInsertions[$oid])) { $this->entityChangeSets[$oid] = $changeSet; $this->entityUpdates[$oid] = $entity; @@ -2891,7 +2890,7 @@ private function performCallbackOnCachedPersister(callable $callback): void return; } - foreach (array_merge($this->persisters, $this->collectionPersisters) as $persister) { + foreach ([...$this->persisters, ...$this->collectionPersisters] as $persister) { if ($persister instanceof CachedPersister) { $callback($persister); } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index dfcfe4f68c5..379ea9a4f7b 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -659,10 +659,6 @@ 'region' => $region, ] - - $fileExtension - $locator - $metadata @@ -1188,7 +1184,6 @@ MultiTableDeleteExecutor - MultiTableDeleteExecutor $this->sqlStatements @@ -1206,7 +1201,6 @@ MultiTableUpdateExecutor - MultiTableUpdateExecutor $this->sqlStatements @@ -1219,9 +1213,6 @@ $this->sqlStatements - - SingleSelectExecutor - @@ -1235,7 +1226,6 @@ SingleTableDeleteUpdateExecutor - SingleTableDeleteUpdateExecutor