Skip to content

Commit b48501a

Browse files
chore: bump phpstan version (#7239)
1 parent 4abf17b commit b48501a

File tree

28 files changed

+87
-61
lines changed

28 files changed

+87
-61
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,17 @@
142142
"illuminate/pagination": "^11.0 || ^12.0",
143143
"illuminate/routing": "^11.0 || ^12.0",
144144
"illuminate/support": "^11.0 || ^12.0",
145-
"jangregor/phpstan-prophecy": "^1.0",
145+
"jangregor/phpstan-prophecy": "^2.1.11",
146146
"justinrainbow/json-schema": "^5.2.11",
147147
"laravel/framework": "^11.0 || ^12.0",
148148
"orchestra/testbench": "^9.1",
149149
"phpspec/prophecy-phpunit": "^2.2",
150150
"phpstan/extension-installer": "^1.1",
151151
"phpstan/phpdoc-parser": "^1.29 || ^2.0",
152-
"phpstan/phpstan": "^1.10",
153-
"phpstan/phpstan-doctrine": "^1.0",
154-
"phpstan/phpstan-phpunit": "^1.0",
155-
"phpstan/phpstan-symfony": "^1.0",
152+
"phpstan/phpstan": "^2.1",
153+
"phpstan/phpstan-doctrine": "^2.0",
154+
"phpstan/phpstan-phpunit": "^2.0",
155+
"phpstan/phpstan-symfony": "^2.0",
156156
"phpunit/phpunit": "11.5.x-dev",
157157
"psr/log": "^1.0 || ^2.0 || ^3.0",
158158
"ramsey/uuid": "^4.7",

phpstan.neon.dist

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ parameters:
1717
excludePaths:
1818
# uses larastan
1919
- src/Laravel
20-
- src/Symfony/Bundle/Command/OpenApiCommand.php
2120
# Symfony config
2221
- tests/Fixtures/app/config/config_swagger.php
2322
# Symfony cache
@@ -33,10 +32,7 @@ parameters:
3332
- src/Doctrine/*/vendor/*
3433
- src/*/vendor/*
3534
# Symfony 6 support
36-
- src/OpenApi/Serializer/CacheableSupportsMethodInterface.php
37-
- src/Serializer/CacheableSupportsMethodInterface.php
3835
- tests/Hal/Serializer/ItemNormalizerTest.php
39-
- tests/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactoryTest.php
4036
- src/Symfony/Bundle/ArgumentResolver/CompatibleValueResolverInterface.php
4137
earlyTerminatingMethodCalls:
4238
PHPUnit\Framework\Constraint\Constraint:
@@ -75,6 +71,15 @@ parameters:
7571
# Expected, due to backward compatibility
7672
- '#Method GraphQL\\Type\\Definition\\WrappingType::getWrappedType\(\) invoked with 1 parameter, 0 required\.#'
7773
- '#Access to an undefined property GraphQL\\Type\\Definition\\NamedType&GraphQL\\Type\\Definition\\Type::\$name\.#'
74+
- "#Call to function method_exists\\(\\) with GraphQL\\\\Type\\\\Definition\\\\Type&GraphQL\\\\Type\\\\Definition\\\\WrappingType and 'getInnermostType' will always evaluate to true\\.#"
75+
- "#Call to function method_exists\\(\\) with Symfony\\\\Component\\\\Console\\\\Application and 'addCommand' will always evaluate to false\\.#"
76+
- "#Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component\\\\\\\\PropertyInfo\\\\\\\\PropertyInfoExtractor' and 'getType' will always evaluate to true\\.#"
77+
- "#Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component\\\\\\\\HttpFoundation\\\\\\\\Request' and 'getContentTypeFormat' will always evaluate to true\\.#"
78+
- '#Call to an undefined method Symfony\\Component\\HttpFoundation\\Request::getContentType\(\)\.#'
79+
- "#Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component\\\\\\\\Serializer\\\\\\\\Serializer' and 'getSupportedTypes' will always evaluate to true\\.#"
80+
- "#Call to function method_exists\\(\\) with Symfony\\\\Component\\\\Serializer\\\\Normalizer\\\\NormalizerInterface and 'getSupportedTypes' will always evaluate to true\\.#"
81+
- "#Call to function method_exists\\(\\) with Doctrine\\\\ODM\\\\MongoDB\\\\Configuration and 'setMetadataCache' will always evaluate to true\\.#"
82+
- "#Call to function method_exists\\(\\) with Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\|Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata and 'isChangeTrackingDef…' will always evaluate to true\\.#"
7883
-
7984
message: '#Instanceof between Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface and Symfony\\Component\\Serializer\\NameConverter\\MetadataAwareNameConverter will always evaluate to false\.#'
8085
paths:
@@ -90,4 +95,28 @@ parameters:
9095
-
9196
message: '#^Service "[^"]+" is private.$#'
9297
path: src
93-
- '#Call to an undefined method Symfony\\Component\\HttpFoundation\\Request::getContentType\(\)\.#'
98+
99+
# Allow extra assertions in tests: https://github.com/phpstan/phpstan-strict-rules/issues/130
100+
- '#^Call to (static )?method PHPUnit\\Framework\\Assert::.* will always evaluate to true\.$#'
101+
102+
# TODO For PHPStan 2.0
103+
-
104+
path: tests/
105+
identifier: function.alreadyNarrowedType
106+
-
107+
identifier: property.unusedType
108+
-
109+
identifier: return.unusedType
110+
-
111+
path: tests/
112+
identifier: void.pure
113+
-
114+
identifier: varTag.nativeType
115+
-
116+
identifier: isset.offset
117+
-
118+
identifier: trait.unused
119+
-
120+
identifier: instanceof.alwaysTrue
121+
-
122+
identifier: catch.neverThrown

src/Doctrine/Orm/State/CollectionProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5656
$manager = $this->managerRegistry->getManagerForClass($entityClass);
5757

5858
$repository = $manager->getRepository($entityClass);
59-
if (!method_exists($repository, 'createQueryBuilder')) {
59+
if (!method_exists($repository, 'createQueryBuilder')) { // @phpstan-ignore-line function.alreadyNarrowedType
6060
throw new RuntimeException('The repository class must have a "createQueryBuilder" method.');
6161
}
6262

src/Doctrine/Orm/State/ItemProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
6565
}
6666

6767
$repository = $manager->getRepository($entityClass);
68-
if (!method_exists($repository, 'createQueryBuilder')) {
68+
if (!method_exists($repository, 'createQueryBuilder')) { // @phpstan-ignore-line function.alreadyNarrowedType
6969
throw new RuntimeException('The repository class must have a "createQueryBuilder" method.');
7070
}
7171

src/Elasticsearch/Extension/SortExtension.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public function applyToCollection(array $requestBody, string $resourceClass, ?Op
4949
if (
5050
$operation
5151
&& null !== ($defaultOrder = $operation->getOrder())
52-
&& \is_array($defaultOrder)
5352
) {
5453
foreach ($defaultOrder as $property => $direction) {
5554
if (\is_int($property)) {

src/GraphQl/State/Provider/ReadProvider.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
8282
return $item;
8383
}
8484

85-
if (!\is_object($item)) {
86-
throw new \LogicException('Item from read provider should be a nullable object.');
87-
}
88-
8985
if (isset($context['graphql_context']) && !enum_exists($item::class)) {
9086
$context['graphql_context']['previous_object'] = clone $item;
9187
}
@@ -124,6 +120,9 @@ private function getNormalizedFilters(array $args): array
124120
$filters = $args;
125121

126122
foreach ($filters as $name => $value) {
123+
// Prevent numeric keys like `'1'`
124+
$name = (string) $name;
125+
127126
if (\is_array($value)) {
128127
if (strpos($name, '_list')) {
129128
$name = substr($name, 0, \strlen($name) - \strlen('_list'));
@@ -136,7 +135,7 @@ private function getNormalizedFilters(array $args): array
136135
$filters[$name] = $this->getNormalizedFilters($value);
137136
}
138137

139-
if (\is_string($name) && strpos($name, $this->nestingSeparator)) {
138+
if (strpos($name, $this->nestingSeparator)) {
140139
// Gives a chance to relations/nested fields.
141140
$index = array_search($name, array_keys($filters), true);
142141
$filters =

src/GraphQl/Tests/Serializer/SerializerContextBuilderTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ private function buildOperationFromContext(bool $isMutation, bool $isSubscriptio
7777
}
7878
}
7979

80-
\assert($operation instanceof Operation);
81-
8280
return $operation;
8381
}
8482

src/GraphQl/Tests/State/Processor/NormalizeProcessorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testProcess($body, $operation): void
4949
$serializerContext = ['resource_class' => $operation->getClass()];
5050
$normalizer = $this->createMock(NormalizerInterface::class);
5151
$serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class);
52-
$serializerContextBuilder->expects($this->once())->method('create')->with($operation->getClass(), $operation, $context, normalization: true)->willReturn($serializerContext);
52+
$serializerContextBuilder->expects($this->once())->method('create')->with($operation->getClass(), $operation, $context, true)->willReturn($serializerContext);
5353
$normalizer->expects($this->once())->method('normalize')->with($body, 'graphql', $serializerContext);
5454
$processor = new NormalizeProcessor($normalizer, $serializerContextBuilder, new Pagination());
5555
$processor->process($body, $operation, [], $context);
@@ -73,7 +73,7 @@ public function testProcessCollection($collection, $operation, $args, ?array $ex
7373
$normalizer = $this->prophesize(NormalizerInterface::class);
7474

7575
$serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class);
76-
$serializerContextBuilder->expects($this->once())->method('create')->with($operation->getClass(), $operation, $context, normalization: true)->willReturn($serializerContext);
76+
$serializerContextBuilder->expects($this->once())->method('create')->with($operation->getClass(), $operation, $context, true)->willReturn($serializerContext);
7777
foreach ($collection as $v) {
7878
$normalizer->normalize($v, 'graphql', $serializerContext)->willReturn(['normalized_item'])->shouldBeCalledOnce();
7979
}

src/GraphQl/Tests/State/Provider/DenormalizeProviderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testProvide(): void
3333
$decorated->expects($this->once())->method('provide')->willReturn($objectToPopulate);
3434
$denormalizer = $this->createMock(DenormalizerInterface::class);
3535
$serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class);
36-
$serializerContextBuilder->expects($this->once())->method('create')->with($operation->getClass(), $operation, $context, normalization: false)->willReturn($serializerContext);
36+
$serializerContextBuilder->expects($this->once())->method('create')->with($operation->getClass(), $operation, $context, false)->willReturn($serializerContext);
3737
$denormalizer->expects($this->once())->method('denormalize')->with(['test'], 'dummy', 'graphql', $serializerContext)->willReturn(new \stdClass());
3838
$provider = new DenormalizeProvider($decorated, $denormalizer, $serializerContextBuilder);
3939
$provider->provide($operation, [], $context);
@@ -49,7 +49,7 @@ public function testProvideWithObjectToPopulate(): void
4949
$decorated->expects($this->once())->method('provide')->willReturn($objectToPopulate);
5050
$denormalizer = $this->createMock(DenormalizerInterface::class);
5151
$serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class);
52-
$serializerContextBuilder->expects($this->once())->method('create')->with($operation->getClass(), $operation, $context, normalization: false)->willReturn($serializerContext);
52+
$serializerContextBuilder->expects($this->once())->method('create')->with($operation->getClass(), $operation, $context, false)->willReturn($serializerContext);
5353
$denormalizer->expects($this->once())->method('denormalize')->with(['test'], 'dummy', 'graphql', $serializerContext)->willReturn(new \stdClass());
5454
$provider = new DenormalizeProvider($decorated, $denormalizer, $serializerContextBuilder);
5555
$provider->provide($operation, [], $context);
@@ -65,7 +65,7 @@ public function testProvideNotCalledWithQuery(): void
6565
$decorated->expects($this->once())->method('provide')->willReturn($objectToPopulate);
6666
$denormalizer = $this->createMock(DenormalizerInterface::class);
6767
$serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class);
68-
$serializerContextBuilder->expects($this->never())->method('create')->with($operation->getClass(), $operation, $context, normalization: false)->willReturn($serializerContext);
68+
$serializerContextBuilder->expects($this->never())->method('create')->with($operation->getClass(), $operation, $context, false)->willReturn($serializerContext);
6969
$denormalizer->expects($this->never())->method('denormalize')->with(['test'], 'dummy', 'graphql', $serializerContext)->willReturn(new \stdClass());
7070
$provider = new DenormalizeProvider($decorated, $denormalizer, $serializerContextBuilder);
7171
$provider->provide($operation, [], $context);
@@ -81,7 +81,7 @@ public function testProvideNotCalledWithoutDeserialize(): void
8181
$decorated->expects($this->once())->method('provide')->willReturn($objectToPopulate);
8282
$denormalizer = $this->createMock(DenormalizerInterface::class);
8383
$serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class);
84-
$serializerContextBuilder->expects($this->never())->method('create')->with($operation->getClass(), $operation, $context, normalization: false)->willReturn($serializerContext);
84+
$serializerContextBuilder->expects($this->never())->method('create')->with($operation->getClass(), $operation, $context, false)->willReturn($serializerContext);
8585
$denormalizer->expects($this->never())->method('denormalize')->with(['test'], 'dummy', 'graphql', $serializerContext)->willReturn(new \stdClass());
8686
$provider = new DenormalizeProvider($decorated, $denormalizer, $serializerContextBuilder);
8787
$provider->provide($operation, [], $context);

src/JsonSchema/Tests/Metadata/Property/Factory/SchemaPropertyMetadataFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testEnumLegacy(): void
4343
public function testEnum(): void
4444
{
4545
$resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
46-
$apiProperty = new ApiProperty(nativeType: Type::nullable(Type::enum(IntEnumAsIdentifier::class))); // @phpstan-ignore-line
46+
$apiProperty = new ApiProperty(nativeType: Type::nullable(Type::enum(IntEnumAsIdentifier::class)));
4747
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
4848
$decorated->expects($this->once())->method('create')->with(DummyWithEnum::class, 'intEnumAsIdentifier')->willReturn($apiProperty);
4949
$schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
@@ -71,7 +71,7 @@ public function testWithCustomOpenApiContext(): void
7171
{
7272
$resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
7373
$apiProperty = new ApiProperty(
74-
nativeType: Type::nullable(Type::enum(IntEnumAsIdentifier::class)), // @phpstan-ignore-line
74+
nativeType: Type::nullable(Type::enum(IntEnumAsIdentifier::class)),
7575
openapiContext: ['type' => 'object', 'properties' => ['alpha' => ['type' => 'integer']]],
7676
);
7777
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);

0 commit comments

Comments
 (0)