Skip to content

Commit

Permalink
Merge pull request #8644 from greg0ire/more-accurate-return-type
Browse files Browse the repository at this point in the history
Describe return types more accurately
  • Loading branch information
greg0ire authored Apr 22, 2021
2 parents 48612e6 + eb860a7 commit 996c1c7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 187 deletions.
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
* metadata mapping information of a class which describes how a class should be mapped
* to a relational database.
*
* @method ClassMetadata[] getAllMetadata()
* @method ClassMetadata[] getLoadedMetadata()
* @method ClassMetadata getMetadataFor($className)
*/
class ClassMetadataFactory extends AbstractClassMetadataFactory
{
Expand Down
12 changes: 6 additions & 6 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
use Doctrine\Common\Collections\Expr\Comparison;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\ResultStatement as DriverStatement;
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Statement;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
Expand Down Expand Up @@ -919,8 +919,8 @@ public function getManyToManyCollection(array $assoc, $sourceEntity, $offset = n
/**
* Loads an array of entities from a given DBAL statement.
*
* @param mixed[] $assoc
* @param Statement $stmt
* @param mixed[] $assoc
* @param DriverStatement $stmt
*
* @return mixed[]
*/
Expand All @@ -941,7 +941,7 @@ private function loadArrayFromStatement($assoc, $stmt)
* Hydrates a collection from a given DBAL statement.
*
* @param mixed[] $assoc
* @param Statement $stmt
* @param DriverStatement $stmt
* @param PersistentCollection $coll
*
* @return mixed[]
Expand Down Expand Up @@ -975,7 +975,7 @@ public function loadManyToManyCollection(array $assoc, $sourceEntity, Persistent
/**
* @psalm-param array<string, mixed> $assoc
*
* @return \Doctrine\DBAL\Driver\Statement
* @return DriverStatement
*
* @throws MappingException
*/
Expand Down Expand Up @@ -1770,7 +1770,7 @@ public function loadOneToManyCollection(array $assoc, $sourceEntity, PersistentC
* @param int|null $limit
* @psalm-param array<string, mixed> $assoc
*
* @return Statement
* @return DriverStatement
*/
private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null)
{
Expand Down
184 changes: 22 additions & 162 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$associationMappings\\.$#"
count: 1
path: lib/Doctrine/ORM/Cache/DefaultCache.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$rootEntityName\\.$#"
count: 1
path: lib/Doctrine/ORM/Cache/DefaultCache.php

-
message: "#^Method Doctrine\\\\ORM\\\\Cache\\\\DefaultCollectionHydrator\\:\\:loadCacheEntry\\(\\) should return array but returns null\\.$#"
count: 1
Expand Down Expand Up @@ -65,11 +55,6 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php

-
message: "#^Parameter \\#1 \\$metadata of method Doctrine\\\\ORM\\\\Cache\\\\EntityHydrator\\:\\:buildCacheEntry\\(\\) expects Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata, Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata given\\.$#"
count: 1
path: lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php

-
message: "#^Parameter \\#2 \\$key of method Doctrine\\\\ORM\\\\Cache\\\\EntityHydrator\\:\\:buildCacheEntry\\(\\) expects Doctrine\\\\ORM\\\\Cache\\\\EntityCacheKey, Doctrine\\\\ORM\\\\Cache\\\\CacheKey given\\.$#"
count: 1
Expand All @@ -90,11 +75,6 @@ parameters:
count: 2
path: lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$rootEntityName\\.$#"
count: 1
path: lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php

-
message: "#^Call to an undefined method Doctrine\\\\ORM\\\\Cache\\\\Persister\\\\CachedPersister&Doctrine\\\\ORM\\\\Persisters\\\\Collection\\\\CollectionPersister\\:\\:loadCollectionCache\\(\\)\\.$#"
count: 2
Expand All @@ -115,31 +95,11 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php

-
message: "#^Parameter \\#1 \\$metadata of method Doctrine\\\\ORM\\\\Cache\\\\EntityHydrator\\:\\:buildCacheEntry\\(\\) expects Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata, Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata given\\.$#"
count: 2
path: lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php

-
message: "#^Parameter \\#1 \\$metadata of method Doctrine\\\\ORM\\\\Cache\\\\EntityHydrator\\:\\:loadCacheEntry\\(\\) expects Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata, Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata given\\.$#"
count: 1
path: lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php

-
message: "#^Parameter \\#3 \\$entry of method Doctrine\\\\ORM\\\\Cache\\\\EntityHydrator\\:\\:loadCacheEntry\\(\\) expects Doctrine\\\\ORM\\\\Cache\\\\EntityCacheEntry, Doctrine\\\\ORM\\\\Cache\\\\CacheEntry given\\.$#"
count: 1
path: lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$rootEntityName\\.$#"
count: 1
path: lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php

-
message: "#^Parameter \\#1 \\$metadata of method Doctrine\\\\ORM\\\\Cache\\\\EntityHydrator\\:\\:buildCacheEntry\\(\\) expects Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata, Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata given\\.$#"
count: 1
path: lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php

-
message: "#^Call to an undefined method Doctrine\\\\ORM\\\\Cache\\\\Region\\:\\:lock\\(\\)\\.$#"
count: 2
Expand Down Expand Up @@ -175,41 +135,6 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$identifier\\.$#"
count: 5
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$isIdentifierComposite\\.$#"
count: 1
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$name\\.$#"
count: 10
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$rootEntityName\\.$#"
count: 3
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$subClasses\\.$#"
count: 1
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:newInstance\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:setIdentifierValues\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 2
Expand All @@ -225,11 +150,6 @@ parameters:
count: 3
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getClassMetadata\\(\\) should return Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata but returns Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
count: 1
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:getReference\\(\\) should return T\\|null but returns Doctrine\\\\Common\\\\Proxy\\\\Proxy\\.$#"
count: 1
Expand All @@ -240,11 +160,6 @@ parameters:
count: 1
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Parameter \\#2 \\$class of method Doctrine\\\\ORM\\\\EntityManager\\:\\:checkLockRequirements\\(\\) expects Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata, Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata given\\.$#"
count: 1
path: lib/Doctrine/ORM/EntityManager.php

-
message: "#^Result of && is always false\\.$#"
count: 1
Expand Down Expand Up @@ -395,11 +310,6 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$isEmbeddedClass\\.$#"
count: 1
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$isMappedSuperclass\\.$#"
count: 2
Expand All @@ -417,7 +327,7 @@ parameters:

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$name\\.$#"
count: 4
count: 3
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

-
Expand Down Expand Up @@ -590,19 +500,14 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

-
message: "#^Parameter \\#1 \\$subClass of method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataFactory\\:\\:addNestedEmbeddedClasses\\(\\) expects Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata, Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata given\\.$#"
count: 1
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

-
message: "#^Parameter \\#2 \\$class of method Doctrine\\\\ORM\\\\Mapping\\\\QuoteStrategy\\:\\:getSequenceName\\(\\) expects Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata, Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo given\\.$#"
count: 2
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

-
message: "#^Parameter \\#2 \\$parent of method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataFactory\\:\\:inheritIdGeneratorMapping\\(\\) expects Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo, Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata given\\.$#"
count: 2
count: 1
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

-
Expand Down Expand Up @@ -1240,31 +1145,11 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php

-
message: "#^Method Doctrine\\\\ORM\\\\Persisters\\\\Entity\\\\BasicEntityPersister\\:\\:getManyToManyStatement\\(\\) should return Doctrine\\\\DBAL\\\\Driver\\\\Statement but returns Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement&Doctrine\\\\DBAL\\\\Result\\.$#"
count: 1
path: lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php

-
message: "#^Method Doctrine\\\\ORM\\\\Persisters\\\\Entity\\\\BasicEntityPersister\\:\\:getOneToManyStatement\\(\\) should return Doctrine\\\\DBAL\\\\Statement but returns Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement&Doctrine\\\\DBAL\\\\Result\\.$#"
count: 1
path: lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php

-
message: "#^Parameter \\#1 \\$em of method Doctrine\\\\ORM\\\\Id\\\\AbstractIdGenerator\\:\\:generate\\(\\) expects Doctrine\\\\ORM\\\\EntityManager, Doctrine\\\\ORM\\\\EntityManagerInterface given\\.$#"
count: 1
path: lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php

-
message: "#^Parameter \\#2 \\$stmt of method Doctrine\\\\ORM\\\\Persisters\\\\Entity\\\\BasicEntityPersister\\:\\:loadArrayFromStatement\\(\\) expects Doctrine\\\\DBAL\\\\Statement, Doctrine\\\\DBAL\\\\Driver\\\\Statement given\\.$#"
count: 1
path: lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php

-
message: "#^Parameter \\#2 \\$stmt of method Doctrine\\\\ORM\\\\Persisters\\\\Entity\\\\BasicEntityPersister\\:\\:loadCollectionFromStatement\\(\\) expects Doctrine\\\\DBAL\\\\Statement, Doctrine\\\\DBAL\\\\Driver\\\\Statement given\\.$#"
count: 1
path: lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php

-
message: "#^Parameter \\#3 \\$hints of method Doctrine\\\\ORM\\\\Internal\\\\Hydration\\\\AbstractHydrator\\:\\:hydrateAll\\(\\) expects array\\<string, string\\>, array\\<string, Doctrine\\\\ORM\\\\PersistentCollection\\|true\\> given\\.$#"
count: 1
Expand Down Expand Up @@ -1345,26 +1230,6 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Query.php

-
message: "#^Call to function is_array\\(\\) with Doctrine\\\\Common\\\\Collections\\\\ArrayCollection&iterable will always evaluate to false\\.$#"
count: 1
path: lib/Doctrine/ORM/QueryBuilder.php

-
message: "#^Method Doctrine\\\\ORM\\\\QueryBuilder\\:\\:getEntityManager\\(\\) should return Doctrine\\\\ORM\\\\EntityManager but returns Doctrine\\\\ORM\\\\EntityManagerInterface\\.$#"
count: 1
path: lib/Doctrine/ORM/QueryBuilder.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$where$#"
count: 2
path: lib/Doctrine/ORM/QueryBuilder.php

-
message: "#^Parameter \\#2 \\$dqlPart of method Doctrine\\\\ORM\\\\QueryBuilder\\:\\:add\\(\\) expects array\\<'join'\\|int, array\\<int\\|string, object\\>\\|string\\>\\|object\\|string, array\\<string, Doctrine\\\\ORM\\\\Query\\\\Expr\\\\Join\\> given\\.$#"
count: 2
path: lib/Doctrine/ORM/QueryBuilder.php

-
message: "#^Access to an undefined property Doctrine\\\\ORM\\\\Query\\\\AST\\\\Node\\:\\:\\$value\\.$#"
count: 1
Expand Down Expand Up @@ -2110,6 +1975,26 @@ parameters:
count: 2
path: lib/Doctrine/ORM/Query/TreeWalkerChainIterator.php

-
message: "#^Call to function is_array\\(\\) with Doctrine\\\\Common\\\\Collections\\\\ArrayCollection&iterable will always evaluate to false\\.$#"
count: 1
path: lib/Doctrine/ORM/QueryBuilder.php

-
message: "#^Method Doctrine\\\\ORM\\\\QueryBuilder\\:\\:getEntityManager\\(\\) should return Doctrine\\\\ORM\\\\EntityManager but returns Doctrine\\\\ORM\\\\EntityManagerInterface\\.$#"
count: 1
path: lib/Doctrine/ORM/QueryBuilder.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$where$#"
count: 2
path: lib/Doctrine/ORM/QueryBuilder.php

-
message: "#^Parameter \\#2 \\$dqlPart of method Doctrine\\\\ORM\\\\QueryBuilder\\:\\:add\\(\\) expects array\\<'join'\\|int, array\\<int\\|string, object\\>\\|string\\>\\|object\\|string, array\\<string, Doctrine\\\\ORM\\\\Query\\\\Expr\\\\Join\\> given\\.$#"
count: 2
path: lib/Doctrine/ORM/QueryBuilder.php

-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
Expand Down Expand Up @@ -2295,31 +2180,6 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Tools/SchemaTool.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$associationMappings\\.$#"
count: 5
path: lib/Doctrine/ORM/Tools/SchemaValidator.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$containsForeignIdentifier\\.$#"
count: 1
path: lib/Doctrine/ORM/Tools/SchemaValidator.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$name\\.$#"
count: 12
path: lib/Doctrine/ORM/Tools/SchemaValidator.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:getIdentifierColumnNames\\(\\)\\.$#"
count: 5
path: lib/Doctrine/ORM/Tools/SchemaValidator.php

-
message: "#^Parameter \\#1 \\$class of method Doctrine\\\\ORM\\\\Tools\\\\SchemaValidator\\:\\:validateClass\\(\\) expects Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo, Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata given\\.$#"
count: 1
path: lib/Doctrine/ORM/Tools/SchemaValidator.php

-
message: "#^Parameter \\#2 \\$code of class Doctrine\\\\ORM\\\\Tools\\\\ToolsException constructor expects int, string given\\.$#"
count: 1
Expand Down
19 changes: 0 additions & 19 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@
<code>?T</code>
<code>getReference</code>
</InvalidReturnType>
<UndefinedInterfaceMethod occurrences="2">
<code>newInstance</code>
<code>setIdentifierValues</code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/Doctrine/ORM/EntityRepository.php">
<InvalidReturnStatement occurrences="3">
Expand Down Expand Up @@ -524,21 +520,6 @@
<code>$query</code>
</MoreSpecificImplementedParamType>
</file>
<file src="lib/Doctrine/ORM/Tools/SchemaValidator.php">
<InvalidReturnStatement occurrences="1">
<code>$errors</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="1">
<code>array&lt;string, list&lt;string&gt;&gt;</code>
</InvalidReturnType>
<UndefinedInterfaceMethod occurrences="5">
<code>getIdentifierColumnNames</code>
<code>getIdentifierColumnNames</code>
<code>getIdentifierColumnNames</code>
<code>getIdentifierColumnNames</code>
<code>getIdentifierColumnNames</code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/Doctrine/ORM/UnitOfWork.php">
<InvalidNullableReturnType occurrences="1">
<code>object</code>
Expand Down

0 comments on commit 996c1c7

Please sign in to comment.