Skip to content

Commit

Permalink
Fix type errors in AnnotationDriver (doctrine#9274)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Dec 29, 2021
1 parent 70dcffa commit 98d7704
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 787 deletions.
2 changes: 2 additions & 0 deletions lib/Doctrine/ORM/Cache/DefaultCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use InvalidArgumentException;
use LogicException;

use function assert;
use function sprintf;

use const DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -91,6 +92,7 @@ public function setTimestampRegion(TimestampRegion $region)
*/
public function buildCachedEntityPersister(EntityManagerInterface $em, EntityPersister $persister, ClassMetadata $metadata)
{
assert($metadata->cache !== null);
$region = $this->getRegion($metadata->cache);
$usage = $metadata->cache['usage'];

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/AssociationOverrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ final class AssociationOverrides implements Annotation
/**
* Mapping overrides of relationship properties.
*
* @var array<\Doctrine\ORM\Mapping\AssociationOverride>
* @var array<AssociationOverride>
*/
public $overrides = [];

/**
* @param array<mixed>|AssociationOverride $overrides
* @param array<AssociationOverride>|AssociationOverride $overrides
*/
public function __construct($overrides)
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/AttributeOverrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ final class AttributeOverrides implements Annotation
/**
* One or more field or property mapping overrides.
*
* @var array<\Doctrine\ORM\Mapping\AttributeOverride>
* @var array<AttributeOverride>
*/
public $overrides = [];

/**
* @param array<mixed>|AttributeOverride $overrides
* @param array<AttributeOverride>|AttributeOverride $overrides
*/
public function __construct($overrides)
{
Expand Down
15 changes: 9 additions & 6 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
* 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)
* @extends AbstractClassMetadataFactory<ClassMetadata>
*/
class ClassMetadataFactory extends AbstractClassMetadataFactory
{
Expand Down Expand Up @@ -90,14 +88,16 @@ protected function initialize()
protected function onNotFoundMetadata($className)
{
if (! $this->evm->hasListeners(Events::onClassMetadataNotFound)) {
return;
return null;
}

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

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

return $eventArgs->getFoundMetadata();
return $classMetadata;
}

/**
Expand Down Expand Up @@ -642,6 +642,9 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void
}
}

/**
* @psalm-return ClassMetadata::GENERATOR_TYPE_SEQUENCE|ClassMetadata::GENERATOR_TYPE_IDENTITY
*/
private function determineIdGeneratorStrategy(AbstractPlatform $platform): int
{
if (
Expand Down Expand Up @@ -736,7 +739,7 @@ protected function getDriver()
*/
protected function isEntity(ClassMetadataInterface $class)
{
return isset($class->isMappedSuperclass) && $class->isMappedSuperclass === false;
return ! $class->isMappedSuperclass;
}

private function getTargetPlatform(): Platforms\AbstractPlatform
Expand Down
21 changes: 13 additions & 8 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\Instantiator\Instantiator;
use Doctrine\Instantiator\InstantiatorInterface;
use Doctrine\ORM\Cache\Exception\NonCacheableEntityAssociation;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Id\AbstractIdGenerator;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\ReflectionService;
Expand Down Expand Up @@ -300,7 +301,7 @@ class ClassMetadataInfo implements ClassMetadata
* (Optional).
*
* @var string|null
* @psalm-var ?class-string
* @psalm-var ?class-string<EntityRepository>
*/
public $customRepositoryClassName;

Expand Down Expand Up @@ -395,14 +396,15 @@ class ClassMetadataInfo implements ClassMetadata
* READ-ONLY: The inheritance mapping type used by the class.
*
* @var int
* @psalm-var self::$INHERITANCE_TYPE_*
* @psalm-var self::INHERITANCE_TYPE_*
*/
public $inheritanceType = self::INHERITANCE_TYPE_NONE;

/**
* READ-ONLY: The Id generator type used by the class.
*
* @var int
* @psalm-var self::GENERATOR_TYPE_*
*/
public $generatorType = self::GENERATOR_TYPE_NONE;

Expand Down Expand Up @@ -668,8 +670,8 @@ class ClassMetadataInfo implements ClassMetadata
*/
public $versionField;

/** @var mixed[] */
public $cache = null;
/** @var mixed[]|null */
public $cache;

/**
* The ReflectionClass instance of the mapped class.
Expand Down Expand Up @@ -2150,6 +2152,7 @@ public function getIdentifierColumnNames()
* Sets the type of Id generator to use for the mapped class.
*
* @param int $generatorType
* @psalm-param self::GENERATOR_TYPE_* $generatorType
*
* @return void
*/
Expand Down Expand Up @@ -2376,6 +2379,7 @@ public function setParentClasses(array $classNames)
* Sets the inheritance type used by the class and its subclasses.
*
* @param int $type
* @psalm-param self::INHERITANCE_TYPE_* $type
*
* @return void
*
Expand Down Expand Up @@ -2921,8 +2925,8 @@ protected function _storeAssociationMapping(array $assocMapping)
/**
* Registers a custom repository class for the entity class.
*
* @param string $repositoryClassName The class name of the custom mapper.
* @psalm-param class-string $repositoryClassName
* @param string|null $repositoryClassName The class name of the custom mapper.
* @psalm-param class-string<EntityRepository>|null $repositoryClassName
*
* @return void
*/
Expand Down Expand Up @@ -3589,17 +3593,18 @@ public function getAssociationsByTargetClass($targetClass)

/**
* @param string|null $className
* @psalm-param ?class-string $className
* @psalm-param string|class-string|null $className
*
* @return string|null null if the input value is null
* @psalm-return class-string|null
*/
public function fullyQualifiedClassName($className)
{
if (empty($className)) {
return $className;
}

if ($className !== null && strpos($className, '\\') === false && $this->namespace) {
if (strpos($className, '\\') === false && $this->namespace) {
return $this->namespace . '\\' . $className;
}

Expand Down
10 changes: 8 additions & 2 deletions lib/Doctrine/ORM/Mapping/DiscriminatorMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
#[Attribute(Attribute::TARGET_CLASS)]
final class DiscriminatorMap implements Annotation
{
/** @var array<string> */
/**
* @var array<string, string>
* @psalm-var array<string, class-string>
*/
public $value;

/** @param array<string> $value */
/**
* @param array<string, string> $value
* @psalm-param array<string, class-string> $value
*/
public function __construct(array $value)
{
$this->value = $value;
Expand Down
Loading

0 comments on commit 98d7704

Please sign in to comment.