-
-
Notifications
You must be signed in to change notification settings - Fork 915
chore: bump phpstan version #7239
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: main
Are you sure you want to change the base?
Conversation
12d82b6
to
739f51c
Compare
@@ -17,7 +17,6 @@ parameters: | |||
excludePaths: | |||
# uses larastan | |||
- src/Laravel | |||
- src/Symfony/Bundle/Command/OpenApiCommand.php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those files doesn't exists and are reported by PHPStan v2 now.
@@ -75,6 +71,15 @@ parameters: | |||
# Expected, due to backward compatibility | |||
- '#Method GraphQL\\Type\\Definition\\WrappingType::getWrappedType\(\) invoked with 1 parameter, 0 required\.#' | |||
- '#Access to an undefined property GraphQL\\Type\\Definition\\NamedType&GraphQL\\Type\\Definition\\Type::\$name\.#' | |||
- "#Call to function method_exists\\(\\) with GraphQL\\\\Type\\\\Definition\\\\Type&GraphQL\\\\Type\\\\Definition\\\\WrappingType and 'getInnermostType' will always evaluate to true\\.#" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of method_exists call added for BC, so I updated the ignored errors.
# Allow extra assertions in tests: https://github.com/phpstan/phpstan-strict-rules/issues/130 | ||
- '#^Call to (static )?method PHPUnit\\Framework\\Assert::.* will always evaluate to true\.$#' | ||
|
||
# TODO For PHPStan 2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a list of errors which I'd like to fix in following PR.
@@ -56,10 +56,6 @@ public function provide(Operation $operation, array $uriVariables = [], array $c | |||
$manager = $this->managerRegistry->getManagerForClass($entityClass); | |||
|
|||
$repository = $manager->getRepository($entityClass); | |||
if (!method_exists($repository, 'createQueryBuilder')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$repository is always an EntityRepository according to PHPStan and I think it's right.
@@ -65,10 +65,6 @@ public function provide(Operation $operation, array $uriVariables = [], array $c | |||
} | |||
|
|||
$repository = $manager->getRepository($entityClass); | |||
if (!method_exists($repository, 'createQueryBuilder')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same idea
@@ -41,6 +41,7 @@ public function testParameterFactory(): void | |||
$filterLocator->method('get')->willReturn(new class implements FilterInterface { | |||
public function getDescription(string $resourceClass): array | |||
{ | |||
// @phpstan-ignore-next-line return.type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we're passing volontary a wrong type to check it's handle in the method.
@@ -101,7 +101,7 @@ public function normalize(mixed $object, ?string $format = null, array $context | |||
*/ | |||
protected function normalizeRawCollection(iterable $object, ?string $format = null, array $context = []): array|\ArrayObject | |||
{ | |||
if (!$object && ($context[Serializer::EMPTY_ARRAY_AS_OBJECT] ?? false) && \is_array($object)) { | |||
if ([] === $object && ($context[Serializer::EMPTY_ARRAY_AS_OBJECT] ?? false)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!$object already enforce it's []
.
But I rewrote the condition to be explicit
@@ -1163,9 +1163,10 @@ private function createAndValidateAttributeValue(string $attribute, mixed $value | |||
} | |||
|
|||
if ( | |||
($t instanceof CollectionType && $collectionValueType instanceof ObjectType && (null !== ($className = $collectionValueType->getClassName()))) | |||
|| ($t instanceof LegacyType && $t->isCollection() && null !== $collectionValueType && null !== ($className = $collectionValueType->getClassName())) | |||
($t instanceof CollectionType && $collectionValueType instanceof ObjectType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this condition (null !== ($className = $collectionValueType->getClassName()))
is always true cause getClassName
returns a string.
So we need to remove it from the condition, and it force declaring the variable after the if.
@@ -91,9 +91,6 @@ private function normalizeJson(mixed $document): object|array | |||
} | |||
|
|||
$document = json_encode($document, \JSON_THROW_ON_ERROR); | |||
if (!\is_string($document)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$document is always a string because of JSON_THROW_ON_ERROR
@@ -47,7 +47,6 @@ public static function getResources(): array | |||
public function testRequest(): void | |||
{ | |||
$client = self::createClient(); | |||
$client->getKernelBrowser(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless call
1f70618
to
299f4cb
Compare
299f4cb
to
6837010
Compare
Hi @soyuka,
I wanted to bump PHPStan level to 6 and saw it was still using v1 ; so I started by bumping to v2.
Since there is lot of new errors I used the following strategy
Then I'll provide PR to fix some identifiers error, but I think it's better to split PR for readability.