Skip to content

Commit

Permalink
Upgrade to PHPStan 2
Browse files Browse the repository at this point in the history
Some calls to assert() are no longer necessary.
  • Loading branch information
greg0ire committed Dec 7, 2024
1 parent 0ed0be0 commit d537075
Show file tree
Hide file tree
Showing 10 changed files with 2,240 additions and 880 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3,077 changes: 2,232 additions & 845 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions phpstan-params.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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>\.$~'
1 change: 0 additions & 1 deletion src/Cache/DefaultQueryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h
$region = $persister->getCacheRegion();

$cm = $this->em->getClassMetadata($entityName);
assert($cm instanceof ClassMetadata);

foreach ($result as $index => $entity) {
$identifier = $this->uow->getEntityIdentifier($entity);
Expand Down
10 changes: 5 additions & 5 deletions src/Cache/Persister/Entity/AbstractEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Doctrine\ORM\UnitOfWork;

use function array_merge;
use function assert;
use function serialize;
use function sha1;

Expand Down Expand Up @@ -614,9 +613,10 @@ public function refresh(array $id, $entity, $lockMode = null)
*/
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
);
}
}
2 changes: 0 additions & 2 deletions src/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,6 @@ private function inheritIdGeneratorMapping(ClassMetadataInfo $class, ClassMetada
*/
protected function wakeupReflection(ClassMetadataInterface $class, ReflectionService $reflService)
{
assert($class instanceof ClassMetadata);
$class->wakeupReflection($reflService);
}

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

Expand Down
2 changes: 0 additions & 2 deletions src/Mapping/DefaultTypedFieldMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public function validateAndComplete(array $mapping, ReflectionProperty $field):
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()])) {
Expand Down
8 changes: 0 additions & 8 deletions src/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
use LogicException;
use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;

use function assert;
use function class_exists;
use function constant;
use function defined;
Expand Down Expand Up @@ -310,8 +308,6 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
}

foreach ($reflectionClass->getProperties() as $property) {
assert($property instanceof ReflectionProperty);

if ($this->isRepeatedPropertyDeclaration($property, $metadata)) {
continue;
}
Expand All @@ -322,8 +318,6 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
// 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'],
[
Expand Down Expand Up @@ -569,7 +563,6 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
$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);
Expand All @@ -589,7 +582,6 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
// 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]);
}
Expand Down
9 changes: 1 addition & 8 deletions src/Tools/Console/Command/ClearCache/QueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

use function assert;
use function get_debug_type;
use function sprintf;

Expand Down Expand Up @@ -96,13 +95,7 @@ private function doExecute(InputInterface $input, OutputInterface $output): int

$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) {
Expand Down
3 changes: 0 additions & 3 deletions src/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
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;
Expand Down Expand Up @@ -327,7 +325,6 @@ static function (ClassMetadata $class) use ($idMapping): bool {
$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);
Expand Down

0 comments on commit d537075

Please sign in to comment.