Upgrade to PHPStan 2 (#11756)

Some calls to assert() are no longer necessary.
This commit is contained in:
Grégoire Paris
2024-12-07 20:42:54 +01:00
committed by GitHub
parent 0ed0be089c
commit 8ef9253999
12 changed files with 2442 additions and 1071 deletions

View File

@@ -44,8 +44,8 @@
"doctrine/coding-standard": "^9.0.2 || ^12.0",
"phpbench/phpbench": "^0.16.10 || ^1.0",
"phpstan/extension-installer": "~1.1.0 || ^1.4",
"phpstan/phpstan": "~1.4.10 || 1.12.6",
"phpstan/phpstan-deprecation-rules": "^1",
"phpstan/phpstan": "~1.4.10 || 2.0.3",
"phpstan/phpstan-deprecation-rules": "^1 || ^2",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.6",
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.7.2",

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,7 @@ parameters:
ignoreErrors:
# PHPStan doesn't understand our method_exists() safeguards.
- '/Call to function method_exists.*/'
- '/Call to an undefined method Doctrine\\DBAL\\Connection::createSchemaManager\(\)\./'
# Class name will change in DBAL 3.
- '/^Class Doctrine\\DBAL\\Platforms\\PostgreSQLPlatform not found\.$/'
@@ -46,6 +47,16 @@ parameters:
path: src/Query/AST/Functions/LocateFunction.php
# Won't get fixed in DBAL 2
-
message: '#.*deleteItem.*expects string.*#'
count: 1
path: src/Query.php
-
message: '#.*get(Drop|Create)SchemaS(ql|QL).*should return list.*but returns array.*#'
count: 2
path: src/Tools/SchemaTool.php
-
message: "#^Parameter \\#2 \\$start of method Doctrine\\\\DBAL\\\\Platforms\\\\AbstractPlatform\\:\\:getSubstringExpression\\(\\) expects int, string given\\.$#"
count: 1

View File

@@ -9,7 +9,3 @@ parameters:
Doctrine\ORM\Query\Parser:
- syntaxError
phpVersion: 80400
ignoreErrors:
# Remove on 3.0.x
- '~^Default value of the parameter #2 \$value \(array\{\}\) of method Doctrine\\ORM\\Query\\AST\\InstanceOfExpression\:\:__construct\(\) is incompatible with type non\-empty\-array<int, Doctrine\\ORM\\Query\\AST\\InputParameter\|string>\.$~'

View File

@@ -98,5 +98,5 @@ parameters:
path: src/Mapping/ClassMetadataFactory.php
-
message: '#^Parameter \#1 \$classNames of method Doctrine\\ORM\\Mapping\\ClassMetadataInfo\<object\>\:\:setParentClasses\(\) expects array\<int, class\-string\>, array\<string\> given\.$#'
message: '#^Parameter \#1 \$classNames of method Doctrine\\ORM\\Mapping\\ClassMetadataInfo\<object\>\:\:setParentClasses\(\) expects list\<class\-string\>, array\<string\> given\.$#'
path: src/Mapping/ClassMetadataFactory.php

View File

@@ -262,7 +262,6 @@ class DefaultQueryCache implements QueryCache
$region = $persister->getCacheRegion();
$cm = $this->em->getClassMetadata($entityName);
assert($cm instanceof ClassMetadata);
foreach ($result as $index => $entity) {
$identifier = $this->uow->getEntityIdentifier($entity);

View File

@@ -25,7 +25,6 @@ use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
use Doctrine\ORM\UnitOfWork;
use function array_merge;
use function assert;
use function serialize;
use function sha1;
@@ -614,9 +613,10 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
*/
protected function buildCollectionCacheKey(array $association, $ownerId)
{
$metadata = $this->metadataFactory->getMetadataFor($association['sourceEntity']);
assert($metadata instanceof ClassMetadata);
return new CollectionCacheKey($metadata->rootEntityName, $association['fieldName'], $ownerId);
return new CollectionCacheKey(
$this->metadataFactory->getMetadataFor($association['sourceEntity'])->rootEntityName,
$association['fieldName'],
$ownerId
);
}
}

View File

@@ -830,7 +830,6 @@ DEPRECATION
*/
protected function wakeupReflection(ClassMetadataInterface $class, ReflectionService $reflService)
{
assert($class instanceof ClassMetadata);
$class->wakeupReflection($reflService);
}
@@ -839,7 +838,6 @@ DEPRECATION
*/
protected function initializeReflection(ClassMetadataInterface $class, ReflectionService $reflService)
{
assert($class instanceof ClassMetadata);
$class->initializeReflection($reflService);
}

View File

@@ -68,8 +68,6 @@ final class DefaultTypedFieldMapper implements TypedFieldMapper
assert(is_a($type->getName(), BackedEnum::class, true));
$mapping['enumType'] = $type->getName();
$type = $reflection->getBackingType();
assert($type instanceof ReflectionNamedType);
}
if (isset($this->typedFieldMappings[$type->getName()])) {

View File

@@ -16,9 +16,7 @@ use Doctrine\Persistence\Mapping\Driver\ColocatedMappingDriver;
use LogicException;
use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;
use function assert;
use function class_exists;
use function constant;
use function defined;
@@ -310,8 +308,6 @@ class AttributeDriver extends CompatibilityAnnotationDriver
}
foreach ($reflectionClass->getProperties() as $property) {
assert($property instanceof ReflectionProperty);
if ($this->isRepeatedPropertyDeclaration($property, $metadata)) {
continue;
}
@@ -322,8 +318,6 @@ class AttributeDriver extends CompatibilityAnnotationDriver
// Evaluate #[Cache] attribute
$cacheAttribute = $this->reader->getPropertyAttribute($property, Mapping\Cache::class);
if ($cacheAttribute !== null) {
assert($cacheAttribute instanceof Mapping\Cache);
$mapping['cache'] = $metadata->getAssociationCacheDefaults(
$mapping['fieldName'],
[
@@ -569,7 +563,6 @@ class AttributeDriver extends CompatibilityAnnotationDriver
$listenerClass = new ReflectionClass($listenerClassName);
foreach ($listenerClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
assert($method instanceof ReflectionMethod);
// find method callbacks.
$callbacks = $this->getMethodCallbacks($method);
$hasMapping = $hasMapping ?: ! empty($callbacks);
@@ -589,7 +582,6 @@ class AttributeDriver extends CompatibilityAnnotationDriver
// Evaluate #[HasLifecycleCallbacks] attribute
if (isset($classAttributes[Mapping\HasLifecycleCallbacks::class])) {
foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
assert($method instanceof ReflectionMethod);
foreach ($this->getMethodCallbacks($method) as $value) {
$metadata->addLifecycleCallback($value[0], $value[1]);
}

View File

@@ -18,7 +18,6 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use function assert;
use function get_debug_type;
use function sprintf;
@@ -96,13 +95,7 @@ EOT
$ui->comment('Clearing <info>all</info> Query cache entries');
if ($cache) {
$result = $cache->clear();
} else {
assert($cacheDriver !== null);
$result = $cacheDriver->deleteAll();
}
$result = $cache ? $cache->clear() : $cacheDriver->deleteAll();
$message = $result ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
if ($input->getOption('flush') === true && ! $cache) {

View File

@@ -31,13 +31,11 @@ use function array_diff_key;
use function array_filter;
use function array_flip;
use function array_intersect_key;
use function assert;
use function count;
use function current;
use function func_num_args;
use function implode;
use function in_array;
use function is_array;
use function is_numeric;
use function method_exists;
use function strtolower;
@@ -327,7 +325,6 @@ class SchemaTool
$pkColumns[] = $this->quoteStrategy->getColumnName($identifierField, $class, $this->platform);
} elseif (isset($class->associationMappings[$identifierField])) {
$assoc = $class->associationMappings[$identifierField];
assert(is_array($assoc));
foreach ($assoc['joinColumns'] as $joinColumn) {
$pkColumns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);