diff --git a/composer.json b/composer.json index 71771886d0c..ece1f0f3b57 100644 --- a/composer.json +++ b/composer.json @@ -42,13 +42,13 @@ "doctrine/annotations": "^1.13", "doctrine/coding-standard": "^9.0", "phpbench/phpbench": "^0.16.10 || ^1.0", - "phpstan/phpstan": "~1.4.10 || 1.8.0", + "phpstan/phpstan": "~1.4.10 || 1.8.2", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", "psr/log": "^1 || ^2 || ^3", "squizlabs/php_codesniffer": "3.7.1", "symfony/cache": "^4.4 || ^5.4 || ^6.0", "symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "vimeo/psalm": "4.24.0" + "vimeo/psalm": "4.25.0" }, "conflict": { "doctrine/annotations": "<1.13 || >= 2.0" diff --git a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php index 384664fa5e6..5e8baf18b29 100644 --- a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php @@ -12,6 +12,7 @@ use Doctrine\ORM\Utility\IdentifierFlattener; use function array_merge; +use function assert; use function is_array; use function is_object; use function reset; @@ -57,6 +58,7 @@ public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $e if ($metadata->requiresFetchAfterChange) { if ($metadata->isVersioned) { + assert($metadata->versionField !== null); $data[$metadata->versionField] = $metadata->getFieldValue($entity, $metadata->versionField); } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 81eaa99bb60..f6633bd4d59 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -748,7 +748,7 @@ class ClassMetadataInfo implements ClassMetadata /** * READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any). * - * @var mixed + * @var string|null */ public $versionField; @@ -3553,7 +3553,7 @@ public function setVersioned($bool) * Sets the name of the field that is to be used for versioning if this class is * versioned for optimistic locking. * - * @param string $versionField + * @param string|null $versionField * * @return void */ diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 7b74ea8bf9c..bb974993133 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -494,7 +494,8 @@ final protected function updateTable( } if ($versioned) { - $versionField = $this->class->versionField; + $versionField = $this->class->versionField; + assert($versionField !== null); $versionFieldType = $this->class->fieldMappings[$versionField]['type']; $versionColumn = $this->quoteStrategy->getColumnName($versionField, $this->class, $this->platform); diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index ebae750af07..da456187504 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -55,6 +55,7 @@ use function array_pop; use function array_sum; use function array_values; +use function assert; use function count; use function current; use function get_class; @@ -1615,6 +1616,8 @@ public function getEntityState($entity, $assume = null) case $class->isIdentifierNatural(): // Check for a version field, if available, to avoid a db lookup. if ($class->isVersioned) { + assert($class->versionField !== null); + return $class->getFieldValue($entity, $class->versionField) ? self::STATE_DETACHED : self::STATE_NEW; @@ -2064,6 +2067,7 @@ private function ensureVersionMatch( return; } + assert($class->versionField !== null); $reflField = $class->reflFields[$class->versionField]; $managedCopyVersion = $reflField->getValue($managedCopy); $entityVersion = $reflField->getValue($entity); @@ -2498,6 +2502,7 @@ public function lock($entity, int $lockMode, $lockVersion = null): void $entity->__load(); } + assert($class->versionField !== null); $entityVersion = $class->reflFields[$class->versionField]->getValue($entity); // phpcs:ignore SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedNotEqualOperator diff --git a/psalm-baseline.xml b/psalm-baseline.xml index ad0bb9a1798..3ef5bf9d05c 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + IterableResult @@ -281,13 +281,10 @@ - + $className $connection $entityName - ltrim($className, '\\') - ltrim($entityName, '\\') - ltrim($entityName, '\\') getMetadataCacheImpl @@ -696,10 +693,9 @@ $table $tableGeneratorDefinition - + $this->associationMappings $this->associationMappings - $this->discriminatorMap $this->entityListeners $this->fieldMappings $this->fullyQualifiedClassName($repositoryClassName) @@ -1028,6 +1024,10 @@ + + $className + $entityName + $className $className