From f4524a8bb0a95f544e4469d7940f7d558b8598d8 Mon Sep 17 00:00:00 2001 From: orklah Date: Fri, 25 Sep 2020 20:44:07 +0200 Subject: [PATCH] Fix psalm errors and upgrade strictness (#8209) * Fixes and improvements * fix param type --- lib/Doctrine/ORM/AbstractQuery.php | 12 ++++++++---- lib/Doctrine/ORM/Cache/DefaultCache.php | 3 --- .../Collection/AbstractCollectionPersister.php | 2 +- .../Persister/Entity/AbstractEntityPersister.php | 11 +++++------ .../NonStrictReadWriteCachedEntityPersister.php | 6 ++++++ lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php | 3 --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 -- lib/Doctrine/ORM/ORMException.php | 2 +- .../Persisters/Collection/ManyToManyPersister.php | 9 +++------ .../ORM/Persisters/Entity/BasicEntityPersister.php | 4 +++- lib/Doctrine/ORM/Query/Expr.php | 2 +- lib/Doctrine/ORM/Query/Expr/Composite.php | 2 +- lib/Doctrine/ORM/Query/SqlWalker.php | 4 +++- .../ORM/Repository/DefaultRepositoryFactory.php | 1 - .../ORM/Tools/AttachEntityListenersListener.php | 1 - .../ORM/Tools/Export/Driver/AbstractExporter.php | 8 ++++++++ lib/Doctrine/ORM/Tools/Pagination/Paginator.php | 2 -- .../ORM/Tools/ResolveTargetEntityListener.php | 1 - lib/Doctrine/ORM/Tools/SchemaTool.php | 1 - psalm.xml | 2 +- tests/Doctrine/Tests/Mocks/CacheRegionMock.php | 3 --- .../Tests/Models/ManyToManyPersister/ChildClass.php | 1 + .../Tests/Models/ManyToManyPersister/ParentClass.php | 1 + .../Tests/ORM/Functional/Ticket/DDC2138Test.php | 2 +- .../Tests/ORM/Functional/Ticket/GH7062Test.php | 1 + 25 files changed, 45 insertions(+), 41 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 71c32a6cb6..0bb2ce8d9b 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -72,6 +72,7 @@ abstract class AbstractQuery * The parameter map of this query. * * @var ArrayCollection|Parameter[] + * @psalm-var ArrayCollection */ protected $parameters; @@ -340,6 +341,8 @@ function (Query\Parameter $parameter) use ($key) : bool { * @param ArrayCollection|mixed[] $parameters * * @return static This query instance. + * + * @psalm-param ArrayCollection|mixed[] $parameters */ public function setParameters($parameters) { @@ -470,7 +473,7 @@ protected function getResultSetMapping() */ private function translateNamespaces(Query\ResultSetMapping $rsm) { - $translate = function ($alias) { + $translate = function ($alias) : string { return $this->_em->getClassMetadata($alias)->getName(); }; @@ -631,7 +634,7 @@ public function disableResultCache() : self /** * Defines how long the result cache will be active before expire. * - * @param integer $lifetime How long the cache entry is valid. + * @param int|null $lifetime How long the cache entry is valid. * * @return static This query instance. */ @@ -966,7 +969,8 @@ private function executeIgnoreQueryCache($parameters = null, $hydrationMode = nu $this->setParameters($parameters); } - $setCacheEntry = function() {}; + $setCacheEntry = static function () : void { + }; if ($this->_hydrationCacheProfile !== null) { [$cacheKey, $realCacheKey] = $this->getHydrationCacheId(); @@ -983,7 +987,7 @@ private function executeIgnoreQueryCache($parameters = null, $hydrationMode = nu $result = []; } - $setCacheEntry = function($data) use ($cache, $result, $cacheKey, $realCacheKey, $queryCacheProfile) { + $setCacheEntry = static function ($data) use ($cache, $result, $cacheKey, $realCacheKey, $queryCacheProfile) : void { $result[$realCacheKey] = $data; $cache->save($cacheKey, $result, $queryCacheProfile->getLifetime()); diff --git a/lib/Doctrine/ORM/Cache/DefaultCache.php b/lib/Doctrine/ORM/Cache/DefaultCache.php index 80fbd81438..9c93ddd7e1 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultCache.php @@ -60,9 +60,6 @@ class DefaultCache implements Cache */ private $defaultQueryCache; - /** - * {@inheritdoc} - */ public function __construct(EntityManagerInterface $em) { $this->em = $em; diff --git a/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php b/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php index c13c20774a..cad22555fe 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php @@ -144,7 +144,7 @@ public function getTargetEntityMetadata() * @param \Doctrine\ORM\PersistentCollection $collection * @param \Doctrine\ORM\Cache\CollectionCacheKey $key * - * @return \Doctrine\ORM\PersistentCollection|null + * @return object[]|null */ public function loadCollectionCache(PersistentCollection $collection, CollectionCacheKey $key) { diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php index 3fdc969630..a2fd0bfe3d 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php @@ -283,11 +283,11 @@ private function storeJoinedAssociations($entity) /** * Generates a string of currently query * - * @param array $query - * @param string $criteria - * @param array $orderBy - * @param integer $limit - * @param integer $offset + * @param string $query + * @param string[]|Criteria $criteria + * @param string[] $orderBy + * @param int $limit + * @param int $offset * * @return string */ @@ -548,7 +548,6 @@ public function loadManyToManyCollection(array $assoc, $sourceEntity, Persistent { $persister = $this->uow->getCollectionPersister($assoc); $hasCache = ($persister instanceof CachedPersister); - $key = null; if ( ! $hasCache) { return $this->persister->loadManyToManyCollection($assoc, $sourceEntity, $coll); diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php index a2844673be..4ced02192f 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php @@ -100,6 +100,12 @@ public function update($entity) $this->queuedCache['update'][] = $entity; } + /** + * @param object $entity + * @param bool $isChanged + * + * @return bool + */ private function updateCache($entity, $isChanged) { $class = $this->metadataFactory->getMetadataFor(get_class($entity)); diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index d864bf9ea8..e8963a9940 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -274,7 +274,6 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate annotations on properties/fields - /* @var $property \ReflectionProperty */ foreach ($class->getProperties() as $property) { if ($metadata->isMappedSuperclass && ! $property->isPrivate() || @@ -505,7 +504,6 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $hasMapping = false; $listenerClass = new \ReflectionClass($listenerClassName); - /* @var $method \ReflectionMethod */ foreach ($listenerClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { // find method callbacks. $callbacks = $this->getMethodCallbacks($method); @@ -525,7 +523,6 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate @HasLifecycleCallbacks annotation if (isset($classAnnotations[Mapping\HasLifecycleCallbacks::class])) { - /* @var $method \ReflectionMethod */ foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { foreach ($this->getMethodCallbacks($method) as $value) { $metadata->addLifecycleCallback($value[0], $value[1]); diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 2c42500356..b9cecf3393 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -677,7 +677,6 @@ private function _parseOptions(SimpleXMLElement $options) { $array = []; - /* @var $option SimpleXMLElement */ foreach ($options as $option) { if ($option->count()) { $value = $this->_parseOptions($option->children()); @@ -851,7 +850,6 @@ private function cacheToArray(SimpleXMLElement $cacheMapping) private function _getCascadeMappings(SimpleXMLElement $cascadeElement) { $cascades = []; - /* @var $action SimpleXmlElement */ foreach ($cascadeElement->children() as $action) { // According to the JPA specifications, XML uses "cascade-persist" // instead of "persist". Here, both variations diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index 2712ed9244..689b5be288 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -110,7 +110,7 @@ public static function unrecognizedField($field) * @param string $given * @param string $expected * - * @return \Doctrine\ORM\ORMInvalidArgumentException + * @return \Doctrine\ORM\ORMException */ public static function unexpectedAssociationValue($class, $association, $given, $expected) { diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 7a1dfb1af9..2cd6c3f6f2 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -373,9 +373,7 @@ protected function getOnConditionSQL($mapping) } /** - * {@inheritdoc} - * - * @override + * @return string */ protected function getDeleteSQL(PersistentCollection $collection) { @@ -393,10 +391,9 @@ protected function getDeleteSQL(PersistentCollection $collection) } /** - * {@inheritdoc} - * * Internal note: Order of the parameters must be the same as the order of the columns in getDeleteSql. - * @override + * + * @return mixed[] */ protected function getDeleteSQLParameters(PersistentCollection $collection) { diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 9a0d5944c0..9b8bdc92dc 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -2071,7 +2071,9 @@ protected function getJoinSQLForJoinColumns($joinColumns) } /** - * {@inheritdoc} + * @param string $columnName + * + * @return string */ public function getSQLColumnAlias($columnName) { diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index 59f833993c..0973a032ae 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -629,7 +629,7 @@ private function _quoteLiteral($literal) * @param integer|string $x Starting range value to be used in BETWEEN() function. * @param integer|string $y End point value to be used in BETWEEN() function. * - * @return Expr\Func A BETWEEN expression. + * @return string A BETWEEN expression. */ public function between($val, $x, $y) { diff --git a/lib/Doctrine/ORM/Query/Expr/Composite.php b/lib/Doctrine/ORM/Query/Expr/Composite.php index 6b8a04fa5c..635d8aa8fe 100644 --- a/lib/Doctrine/ORM/Query/Expr/Composite.php +++ b/lib/Doctrine/ORM/Query/Expr/Composite.php @@ -49,7 +49,7 @@ public function __toString() } /** - * @param string $part + * @param string|object $part * * @return string */ diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index edfc18eec8..f058830515 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2100,7 +2100,9 @@ public function walkInstanceOfExpression($instanceOfExpr) } /** - * {@inheritdoc} + * @param mixed $inParam + * + * @return string */ public function walkInParameter($inParam) { diff --git a/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php b/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php index 9d4da0d3b7..ddd4c1a63b 100644 --- a/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php +++ b/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php @@ -61,7 +61,6 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName */ private function createRepository(EntityManagerInterface $entityManager, $entityName) { - /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */ $metadata = $entityManager->getClassMetadata($entityName); $repositoryClassName = $metadata->customRepositoryClassName ?: $entityManager->getConfiguration()->getDefaultRepositoryClassName(); diff --git a/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php b/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php index b78ec9645e..f05c52226d 100644 --- a/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php +++ b/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php @@ -64,7 +64,6 @@ public function addEntityListener($entityClass, $listenerClass, $eventName, $lis */ public function loadClassMetadata(LoadClassMetadataEventArgs $event) { - /** @var ClassMetadata $metadata */ $metadata = $event->getClassMetadata(); if ( ! isset($this->entityListeners[$metadata->name])) { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php index efe8e7bcdc..5ed79f6e76 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php @@ -189,6 +189,8 @@ public function setExtension($extension) * @param int $type * * @return string + * + * @psalm-param ClassMetadataInfo::INHERITANCE_TYPE_* $type */ protected function _getInheritanceTypeString($type) { @@ -211,6 +213,8 @@ protected function _getInheritanceTypeString($type) * @param int $mode * * @return string + * + * @psalm-param ClassMetadataInfo::FETCH_* $mode */ protected function _getFetchModeString($mode) { @@ -230,6 +234,8 @@ protected function _getFetchModeString($mode) * @param int $policy * * @return string + * + * @psalm-param ClassMetadataInfo::CHANGETRACKING_* $policy */ protected function _getChangeTrackingPolicyString($policy) { @@ -249,6 +255,8 @@ protected function _getChangeTrackingPolicyString($policy) * @param int $type * * @return string + * + * @psalm-param ClassMetadataInfo::GENERATOR_TYPE_* $type */ protected function _getIdGeneratorTypeString($type) { diff --git a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php index 64cd9e243f..0008927363 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php +++ b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php @@ -190,7 +190,6 @@ public function getIterator() */ private function cloneQuery(Query $query) { - /* @var $cloneQuery Query */ $cloneQuery = clone $query; $cloneQuery->setParameters(clone $query->getParameters()); @@ -244,7 +243,6 @@ private function appendTreeWalker(Query $query, $walkerClass) */ private function getCountQuery() { - /* @var $countQuery Query */ $countQuery = $this->cloneQuery($this->query); if ( ! $countQuery->hasHint(CountWalker::HINT_DISTINCT)) { diff --git a/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php b/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php index 36f1f929bd..73b8fa7cee 100644 --- a/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php +++ b/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php @@ -96,7 +96,6 @@ public function onClassMetadataNotFound(OnClassMetadataNotFoundEventArgs $args) */ public function loadClassMetadata(LoadClassMetadataEventArgs $args) { - /* @var $cm \Doctrine\ORM\Mapping\ClassMetadata */ $cm = $args->getClassMetadata(); foreach ($cm->associationMappings as $mapping) { diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 3fd36b8afd..a1906bb863 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -832,7 +832,6 @@ public function getDropSchemaSQL(array $classes) foreach ($fullSchema->getTables() as $table) { if ( ! $schema->hasTable($table->getName())) { foreach ($table->getForeignKeys() as $foreignKey) { - /* @var $foreignKey \Doctrine\DBAL\Schema\ForeignKeyConstraint */ if ($schema->hasTable($foreignKey->getForeignTableName())) { $visitor->acceptForeignKey($table, $foreignKey); } diff --git a/psalm.xml b/psalm.xml index 2c61242af8..999fe8825d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,6 @@ getReturn(__FUNCTION__, true); } - /** - * {@inheritdoc} - */ public function clear() { $this->calls = []; diff --git a/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php b/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php index d3b9b16c1e..1733cd456a 100644 --- a/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php +++ b/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php @@ -40,6 +40,7 @@ class ChildClass * ) * * @var Collection|ParentClass[] + * @psalm-var Collection */ public $parents; diff --git a/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php b/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php index 3007a1013d..0b5a8050dd 100644 --- a/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php +++ b/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php @@ -28,6 +28,7 @@ class ParentClass * @ManyToMany(targetEntity=ChildClass::class, mappedBy="parents", orphanRemoval=true, cascade={"persist"}) * * @var Collection|ChildClass[] + * @psalm-var Collection */ public $children; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php index 960395e9c7..5bf2ddbcaa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php @@ -178,7 +178,7 @@ public function __construct(User $user, User $followedUser) } /** - * {@inheritdoc} + * @return User */ public function getUser() { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7062Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7062Test.php index 1d7a2d7cbd..47409ac8fe 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7062Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7062Test.php @@ -102,6 +102,7 @@ class GH7062Ranking * @OneToMany(targetEntity=GH7062RankingPosition::class, mappedBy="ranking", cascade={"all"}) * * @var Collection|GH7062RankingPosition[] + * @psalm-var Collection */ public $positions;