diff --git a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php index b8f3b5e3b0f..cb0793e8cc6 100644 --- a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php +++ b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php @@ -38,36 +38,27 @@ class CommitOrderCalculator * * @var array */ - private $nodeList = []; + private array $nodeList = []; /** * Volatile variable holding calculated nodes during sorting process. * * @psalm-var list */ - private $sortedNodeList = []; + private array $sortedNodeList = []; /** * Checks for node (vertex) existence in graph. - * - * @param string $hash - * - * @return bool */ - public function hasNode($hash) + public function hasNode(string $hash): bool { return isset($this->nodeList[$hash]); } /** * Adds a new node (vertex) to the graph, assigning its hash and value. - * - * @param string $hash - * @param object $node - * - * @return void */ - public function addNode($hash, $node) + public function addNode(string $hash, object $node): void { $vertex = new stdClass(); @@ -81,14 +72,8 @@ public function addNode($hash, $node) /** * Adds a new dependency (edge) to the graph using their hashes. - * - * @param string $fromHash - * @param string $toHash - * @param int $weight - * - * @return void */ - public function addDependency($fromHash, $toHash, $weight) + public function addDependency(string $fromHash, string $toHash, int $weight): void { $vertex = $this->nodeList[$fromHash]; $edge = new stdClass(); @@ -108,7 +93,7 @@ public function addDependency($fromHash, $toHash, $weight) * * @psalm-return list */ - public function sort() + public function sort(): array { foreach ($this->nodeList as $vertex) { if ($vertex->state !== self::NOT_VISITED) { diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index acc2eaac4cb..4415a0c9514 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -36,11 +36,6 @@ abstract class AbstractHydrator */ protected ?ResultSetMapping $_rsm = null; - /** - * The EntityManager instance. - */ - protected EntityManagerInterface $_em; - /** * The dbms Platform instance. */ @@ -77,10 +72,12 @@ abstract class AbstractHydrator */ protected array $_hints = []; + protected EntityManagerInterface $_em; + /** * Initializes a new instance of a class derived from AbstractHydrator. */ - public function __construct(EntityManagerInterface $em) + public function __construct(protected EntityManagerInterface $em) { $this->_em = $em; $this->_platform = $em->getConnection()->getDatabasePlatform(); @@ -291,9 +288,7 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon if ($value !== null && isset($cacheKeyInfo['enumType'])) { $enumType = $cacheKeyInfo['enumType']; if (is_array($value)) { - $value = array_map(static function ($value) use ($enumType): BackedEnum { - return $enumType::from($value); - }, $value); + $value = array_map(static fn ($value): BackedEnum => $enumType::from($value), $value); } else { $value = $enumType::from($value); } @@ -486,9 +481,7 @@ protected function hydrateColumnInfo(string $key): ?array private function getDiscriminatorValues(ClassMetadata $classMetadata): array { $values = array_map( - function (string $subClass): string { - return (string) $this->getClassMetadata($subClass)->discriminatorValue; - }, + fn (string $subClass): string => (string) $this->getClassMetadata($subClass)->discriminatorValue, $classMetadata->subClasses ); diff --git a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php index 7d71e826845..ea34ed573f4 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php @@ -6,8 +6,8 @@ use Doctrine\ORM\Mapping\ClassMetadata; +use function array_key_last; use function count; -use function end; use function is_array; use function key; use function reset; @@ -124,9 +124,7 @@ protected function hydrateRowData(array $row, array &$result): void $baseElement[$relationAlias][] = $element; } - end($baseElement[$relationAlias]); - - $this->_identifierMap[$path][$id[$parent]][$id[$dqlAlias]] = key($baseElement[$relationAlias]); + $this->_identifierMap[$path][$id[$parent]][$id[$dqlAlias]] = array_key_last($baseElement[$relationAlias]); } } } else { @@ -269,7 +267,6 @@ private function updateResultPointer( return; } - end($coll); - $this->_resultPointers[$dqlAlias] =& $coll[key($coll)]; + $this->_resultPointers[$dqlAlias] =& $coll[array_key_last($coll)]; } } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index c05dcf974bf..c970610569c 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -27,25 +27,24 @@ class ObjectHydrator extends AbstractHydrator { /** @var mixed[] */ - private $identifierMap = []; + private array $identifierMap = []; /** @var mixed[] */ - private $resultPointers = []; + private array $resultPointers = []; /** @var mixed[] */ - private $idTemplate = []; + private array $idTemplate = []; - /** @var int */ - private $resultCounter = 0; + private int $resultCounter = 0; /** @var mixed[] */ - private $rootAliases = []; + private array $rootAliases = []; /** @var mixed[] */ - private $initializedCollections = []; + private array $initializedCollections = []; /** @var mixed[] */ - private $existingCollections = []; + private array $existingCollections = []; protected function prepare(): void { @@ -148,12 +147,11 @@ protected function hydrateAllData(): array /** * Initializes a related collection. * - * @param object $entity The entity to which the collection belongs. * @param string $fieldName The name of the field on the entity that holds the collection. * @param string $parentDqlAlias Alias of the parent fetch joining this collection. */ private function initRelatedCollection( - $entity, + object $entity, ClassMetadata $class, string $fieldName, string $parentDqlAlias @@ -203,11 +201,9 @@ private function initRelatedCollection( * @param string $dqlAlias The DQL alias of the entity's class. * @psalm-param array $data The instance data. * - * @return object - * * @throws HydrationException */ - private function getEntity(array $data, string $dqlAlias) + private function getEntity(array $data, string $dqlAlias): object { $className = $this->resultSetMapping()->aliasMap[$dqlAlias]; @@ -252,10 +248,8 @@ private function getEntity(array $data, string $dqlAlias) /** * @psalm-param class-string $className * @psalm-param array $data - * - * @return mixed */ - private function getEntityFromIdentityMap(string $className, array $data) + private function getEntityFromIdentityMap(string $className, array $data): object|bool { // TODO: Abstract this code and UnitOfWork::createEntity() equivalent? $class = $this->_metadataCache[$className]; diff --git a/lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php b/lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php index 852f8dfa4a1..bd109686a68 100644 --- a/lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php +++ b/lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php @@ -16,30 +16,17 @@ */ final class HydrationCompleteHandler { - /** @var ListenersInvoker */ - private $listenersInvoker; - - /** @var EntityManagerInterface */ - private $em; - /** @var mixed[][] */ - private $deferredPostLoadInvocations = []; + private array $deferredPostLoadInvocations = []; - /** - * Constructor for this object - */ - public function __construct(ListenersInvoker $listenersInvoker, EntityManagerInterface $em) + public function __construct(private ListenersInvoker $listenersInvoker, private EntityManagerInterface $em) { - $this->listenersInvoker = $listenersInvoker; - $this->em = $em; } /** * Method schedules invoking of postLoad entity to the very end of current hydration cycle. - * - * @param object $entity */ - public function deferPostLoadInvoking(ClassMetadata $class, $entity): void + public function deferPostLoadInvoking(ClassMetadata $class, object $entity): void { $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postLoad); diff --git a/psalm-baseline.xml b/psalm-baseline.xml index d39b0577456..f22d66c1977 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -265,6 +265,9 @@ $index + + $index + $result[$resultKey] $result[$resultKey]