Skip to content

Commit 98d7704

Browse files
authored
Fix type errors in AnnotationDriver (doctrine#9274)
1 parent 70dcffa commit 98d7704

15 files changed

+231
-787
lines changed

lib/Doctrine/ORM/Cache/DefaultCacheFactory.php

+2
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

+2-2
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

+2-2
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

+9-6
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545
* metadata mapping information of a class which describes how a class should be mapped
4646
* to a relational database.
4747
*
48-
* @method ClassMetadata[] getAllMetadata()
49-
* @method ClassMetadata[] getLoadedMetadata()
50-
* @method ClassMetadata getMetadataFor($className)
48+
* @extends AbstractClassMetadataFactory<ClassMetadata>
5149
*/
5250
class ClassMetadataFactory extends AbstractClassMetadataFactory
5351
{
@@ -90,14 +88,16 @@ protected function initialize()
9088
protected function onNotFoundMetadata($className)
9189
{
9290
if (! $this->evm->hasListeners(Events::onClassMetadataNotFound)) {
93-
return;
91+
return null;
9492
}
9593

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

9896
$this->evm->dispatchEvent(Events::onClassMetadataNotFound, $eventArgs);
97+
$classMetadata = $eventArgs->getFoundMetadata();
98+
assert($classMetadata instanceof ClassMetadata);
9999

100-
return $eventArgs->getFoundMetadata();
100+
return $classMetadata;
101101
}
102102

103103
/**
@@ -642,6 +642,9 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void
642642
}
643643
}
644644

645+
/**
646+
* @psalm-return ClassMetadata::GENERATOR_TYPE_SEQUENCE|ClassMetadata::GENERATOR_TYPE_IDENTITY
647+
*/
645648
private function determineIdGeneratorStrategy(AbstractPlatform $platform): int
646649
{
647650
if (
@@ -736,7 +739,7 @@ protected function getDriver()
736739
*/
737740
protected function isEntity(ClassMetadataInterface $class)
738741
{
739-
return isset($class->isMappedSuperclass) && $class->isMappedSuperclass === false;
742+
return ! $class->isMappedSuperclass;
740743
}
741744

742745
private function getTargetPlatform(): Platforms\AbstractPlatform

lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

+13-8
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;
@@ -300,7 +301,7 @@ class ClassMetadataInfo implements ClassMetadata
300301
* (Optional).
301302
*
302303
* @var string|null
303-
* @psalm-var ?class-string
304+
* @psalm-var ?class-string<EntityRepository>
304305
*/
305306
public $customRepositoryClassName;
306307

@@ -395,14 +396,15 @@ class ClassMetadataInfo implements ClassMetadata
395396
* READ-ONLY: The inheritance mapping type used by the class.
396397
*
397398
* @var int
398-
* @psalm-var self::$INHERITANCE_TYPE_*
399+
* @psalm-var self::INHERITANCE_TYPE_*
399400
*/
400401
public $inheritanceType = self::INHERITANCE_TYPE_NONE;
401402

402403
/**
403404
* READ-ONLY: The Id generator type used by the class.
404405
*
405406
* @var int
407+
* @psalm-var self::GENERATOR_TYPE_*
406408
*/
407409
public $generatorType = self::GENERATOR_TYPE_NONE;
408410

@@ -668,8 +670,8 @@ class ClassMetadataInfo implements ClassMetadata
668670
*/
669671
public $versionField;
670672

671-
/** @var mixed[] */
672-
public $cache = null;
673+
/** @var mixed[]|null */
674+
public $cache;
673675

674676
/**
675677
* The ReflectionClass instance of the mapped class.
@@ -2150,6 +2152,7 @@ public function getIdentifierColumnNames()
21502152
* Sets the type of Id generator to use for the mapped class.
21512153
*
21522154
* @param int $generatorType
2155+
* @psalm-param self::GENERATOR_TYPE_* $generatorType
21532156
*
21542157
* @return void
21552158
*/
@@ -2376,6 +2379,7 @@ public function setParentClasses(array $classNames)
23762379
* Sets the inheritance type used by the class and its subclasses.
23772380
*
23782381
* @param int $type
2382+
* @psalm-param self::INHERITANCE_TYPE_* $type
23792383
*
23802384
* @return void
23812385
*
@@ -2921,8 +2925,8 @@ protected function _storeAssociationMapping(array $assocMapping)
29212925
/**
29222926
* Registers a custom repository class for the entity class.
29232927
*
2924-
* @param string $repositoryClassName The class name of the custom mapper.
2925-
* @psalm-param class-string $repositoryClassName
2928+
* @param string|null $repositoryClassName The class name of the custom mapper.
2929+
* @psalm-param class-string<EntityRepository>|null $repositoryClassName
29262930
*
29272931
* @return void
29282932
*/
@@ -3589,17 +3593,18 @@ public function getAssociationsByTargetClass($targetClass)
35893593

35903594
/**
35913595
* @param string|null $className
3592-
* @psalm-param ?class-string $className
3596+
* @psalm-param string|class-string|null $className
35933597
*
35943598
* @return string|null null if the input value is null
3599+
* @psalm-return class-string|null
35953600
*/
35963601
public function fullyQualifiedClassName($className)
35973602
{
35983603
if (empty($className)) {
35993604
return $className;
36003605
}
36013606

3602-
if ($className !== null && strpos($className, '\\') === false && $this->namespace) {
3607+
if (strpos($className, '\\') === false && $this->namespace) {
36033608
return $this->namespace . '\\' . $className;
36043609
}
36053610

lib/Doctrine/ORM/Mapping/DiscriminatorMap.php

+8-2
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)