Skip to content

Commit d781779

Browse files
committed
Merge branch '2.11.x' into 3.0.x
* 2.11.x: Fix type errors in AnnotationDriver (doctrine#9274)
2 parents 3f2cc10 + 98d7704 commit d781779

14 files changed

+188
-714
lines changed

lib/Doctrine/ORM/Cache/DefaultCacheFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use InvalidArgumentException;
2626
use LogicException;
2727

28+
use function assert;
2829
use function sprintf;
2930

3031
use const DIRECTORY_SEPARATOR;
@@ -91,6 +92,7 @@ public function setTimestampRegion(TimestampRegion $region)
9192
*/
9293
public function buildCachedEntityPersister(EntityManagerInterface $em, EntityPersister $persister, ClassMetadata $metadata)
9394
{
95+
assert($metadata->cache !== null);
9496
$region = $this->getRegion($metadata->cache);
9597
$usage = $metadata->cache['usage'];
9698

lib/Doctrine/ORM/Mapping/AssociationOverrides.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ final class AssociationOverrides implements Annotation
2121
/**
2222
* Mapping overrides of relationship properties.
2323
*
24-
* @var array<\Doctrine\ORM\Mapping\AssociationOverride>
24+
* @var array<AssociationOverride>
2525
*/
2626
public $overrides = [];
2727

2828
/**
29-
* @param array<mixed>|AssociationOverride $overrides
29+
* @param array<AssociationOverride>|AssociationOverride $overrides
3030
*/
3131
public function __construct($overrides)
3232
{

lib/Doctrine/ORM/Mapping/AttributeOverrides.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ final class AttributeOverrides implements Annotation
2121
/**
2222
* One or more field or property mapping overrides.
2323
*
24-
* @var array<\Doctrine\ORM\Mapping\AttributeOverride>
24+
* @var array<AttributeOverride>
2525
*/
2626
public $overrides = [];
2727

2828
/**
29-
* @param array<mixed>|AttributeOverride $overrides
29+
* @param array<AttributeOverride>|AttributeOverride $overrides
3030
*/
3131
public function __construct($overrides)
3232
{

lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@
4444
* metadata mapping information of a class which describes how a class should be mapped
4545
* to a relational database.
4646
*
47-
* @method ClassMetadata[] getAllMetadata()
48-
* @method ClassMetadata[] getLoadedMetadata()
49-
* @method ClassMetadata getMetadataFor($className)
47+
* @extends AbstractClassMetadataFactory<ClassMetadata>
5048
*/
5149
class ClassMetadataFactory extends AbstractClassMetadataFactory
5250
{
@@ -89,14 +87,16 @@ protected function initialize()
8987
protected function onNotFoundMetadata($className)
9088
{
9189
if (! $this->evm->hasListeners(Events::onClassMetadataNotFound)) {
92-
return;
90+
return null;
9391
}
9492

9593
$eventArgs = new OnClassMetadataNotFoundEventArgs($className, $this->em);
9694

9795
$this->evm->dispatchEvent(Events::onClassMetadataNotFound, $eventArgs);
96+
$classMetadata = $eventArgs->getFoundMetadata();
97+
assert($classMetadata instanceof ClassMetadata);
9898

99-
return $eventArgs->getFoundMetadata();
99+
return $classMetadata;
100100
}
101101

102102
/**
@@ -631,6 +631,9 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void
631631
}
632632
}
633633

634+
/**
635+
* @psalm-return ClassMetadata::GENERATOR_TYPE_SEQUENCE|ClassMetadata::GENERATOR_TYPE_IDENTITY
636+
*/
634637
private function determineIdGeneratorStrategy(AbstractPlatform $platform): int
635638
{
636639
if (
@@ -725,7 +728,7 @@ protected function getDriver()
725728
*/
726729
protected function isEntity(ClassMetadataInterface $class)
727730
{
728-
return isset($class->isMappedSuperclass) && $class->isMappedSuperclass === false;
731+
return ! $class->isMappedSuperclass;
729732
}
730733

731734
private function getTargetPlatform(): Platforms\AbstractPlatform

lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\Instantiator\Instantiator;
1616
use Doctrine\Instantiator\InstantiatorInterface;
1717
use Doctrine\ORM\Cache\Exception\NonCacheableEntityAssociation;
18+
use Doctrine\ORM\EntityRepository;
1819
use Doctrine\ORM\Id\AbstractIdGenerator;
1920
use Doctrine\Persistence\Mapping\ClassMetadata;
2021
use Doctrine\Persistence\Mapping\ReflectionService;
@@ -281,7 +282,7 @@ class ClassMetadataInfo implements ClassMetadata
281282
* (Optional).
282283
*
283284
* @var string|null
284-
* @psalm-var ?class-string
285+
* @psalm-var ?class-string<EntityRepository>
285286
*/
286287
public $customRepositoryClassName;
287288

@@ -376,14 +377,15 @@ class ClassMetadataInfo implements ClassMetadata
376377
* READ-ONLY: The inheritance mapping type used by the class.
377378
*
378379
* @var int
379-
* @psalm-var self::$INHERITANCE_TYPE_*
380+
* @psalm-var self::INHERITANCE_TYPE_*
380381
*/
381382
public $inheritanceType = self::INHERITANCE_TYPE_NONE;
382383

383384
/**
384385
* READ-ONLY: The Id generator type used by the class.
385386
*
386387
* @var int
388+
* @psalm-var self::GENERATOR_TYPE_*
387389
*/
388390
public $generatorType = self::GENERATOR_TYPE_NONE;
389391

@@ -649,8 +651,8 @@ class ClassMetadataInfo implements ClassMetadata
649651
*/
650652
public $versionField;
651653

652-
/** @var mixed[] */
653-
public $cache = null;
654+
/** @var mixed[]|null */
655+
public $cache;
654656

655657
/**
656658
* The ReflectionClass instance of the mapped class.
@@ -2130,6 +2132,7 @@ public function getIdentifierColumnNames()
21302132
* Sets the type of Id generator to use for the mapped class.
21312133
*
21322134
* @param int $generatorType
2135+
* @psalm-param self::GENERATOR_TYPE_* $generatorType
21332136
*
21342137
* @return void
21352138
*/
@@ -2318,6 +2321,7 @@ public function setParentClasses(array $classNames)
23182321
* Sets the inheritance type used by the class and its subclasses.
23192322
*
23202323
* @param int $type
2324+
* @psalm-param self::INHERITANCE_TYPE_* $type
23212325
*
23222326
* @return void
23232327
*
@@ -2863,8 +2867,8 @@ protected function _storeAssociationMapping(array $assocMapping)
28632867
/**
28642868
* Registers a custom repository class for the entity class.
28652869
*
2866-
* @param string $repositoryClassName The class name of the custom mapper.
2867-
* @psalm-param class-string $repositoryClassName
2870+
* @param string|null $repositoryClassName The class name of the custom mapper.
2871+
* @psalm-param class-string<EntityRepository>|null $repositoryClassName
28682872
*
28692873
* @return void
28702874
*/
@@ -3531,17 +3535,18 @@ public function getAssociationsByTargetClass($targetClass)
35313535

35323536
/**
35333537
* @param string|null $className
3534-
* @psalm-param ?class-string $className
3538+
* @psalm-param string|class-string|null $className
35353539
*
35363540
* @return string|null null if the input value is null
3541+
* @psalm-return class-string|null
35373542
*/
35383543
public function fullyQualifiedClassName($className)
35393544
{
35403545
if (empty($className)) {
35413546
return $className;
35423547
}
35433548

3544-
if ($className !== null && strpos($className, '\\') === false && $this->namespace) {
3549+
if (strpos($className, '\\') === false && $this->namespace) {
35453550
return $this->namespace . '\\' . $className;
35463551
}
35473552

lib/Doctrine/ORM/Mapping/DiscriminatorMap.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@
1515
#[Attribute(Attribute::TARGET_CLASS)]
1616
final class DiscriminatorMap implements Annotation
1717
{
18-
/** @var array<string> */
18+
/**
19+
* @var array<string, string>
20+
* @psalm-var array<string, class-string>
21+
*/
1922
public $value;
2023

21-
/** @param array<string> $value */
24+
/**
25+
* @param array<string, string> $value
26+
* @psalm-param array<string, class-string> $value
27+
*/
2228
public function __construct(array $value)
2329
{
2430
$this->value = $value;

0 commit comments

Comments
 (0)