Skip to content

Commit 82ab5ef

Browse files
chore: more phpstan fixes (#7265)
1 parent ae51d6a commit 82ab5ef

26 files changed

+87
-189
lines changed

phpstan.neon.dist

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ parameters:
5454
- tests/Fixtures/TestBundle/Document/
5555
- tests/Fixtures/TestBundle/Entity/
5656
- src/OpenApi/Factory/OpenApiFactory.php
57+
-
58+
message: '#is never assigned .* so it can be removed from the property type.#'
59+
paths:
60+
- src/Doctrine/Common/Tests/Fixtures/
61+
- src/Doctrine/Orm/Tests/Fixtures/
62+
- src/Doctrine/Odm/Tests/Fixtures/
63+
- src/Elasticsearch/Tests/Fixtures/
64+
- src/GraphQl/Tests/Fixtures/
65+
- src/JsonSchema/Tests/Fixtures/
66+
- src/Metadata/Tests/Fixtures/
67+
- src/Serializer/Tests/Fixtures/
68+
- tests/Fixtures/
5769
-
5870
message: '#is never written, only read.#'
5971
paths:
@@ -97,18 +109,6 @@ parameters:
97109
message: '#^Service "[^"]+" is private.$#'
98110
path: src
99111

112+
100113
# Allow extra assertions in tests: https://github.com/phpstan/phpstan-strict-rules/issues/130
101114
- '#^Call to (static )?method PHPUnit\\Framework\\Assert::.* will always evaluate to true\.$#'
102-
103-
# TODO For PHPStan 2.0
104-
-
105-
path: tests/
106-
identifier: function.alreadyNarrowedType
107-
-
108-
identifier: property.unusedType
109-
-
110-
identifier: varTag.nativeType
111-
-
112-
identifier: trait.unused
113-
-
114-
identifier: catch.neverThrown

src/Doctrine/Odm/PropertyHelperTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ abstract protected function splitPropertyParts(string $property, string $resourc
3939
*/
4040
protected function getClassMetadata(string $resourceClass): ClassMetadata
4141
{
42-
/** @var ?ManagerRegistry $managerRegistry */
42+
/**
43+
* @var ?ManagerRegistry $managerRegistry
44+
*
45+
* @phpstan-ignore varTag.nativeType (https://github.com/phpstan/phpstan/issues/9515)
46+
*/
4347
$managerRegistry = $this->getManagerRegistry();
4448
$manager = $managerRegistry?->getManagerForClass($resourceClass);
4549

src/Doctrine/Orm/Util/QueryBuilderHelper.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,7 @@ public static function getExistingJoin(QueryBuilder $queryBuilder, string $alias
186186
*/
187187
private static function mapRootAliases(array $rootAliases, array $rootEntities): array
188188
{
189-
/** @var false|array $aliasMap */
190-
$aliasMap = array_combine($rootAliases, $rootEntities);
191-
if (false === $aliasMap) {
192-
throw new \LogicException('Number of root aliases and root entities do not match.');
193-
}
194-
195-
return $aliasMap;
189+
return array_combine($rootAliases, $rootEntities);
196190
}
197191

198192
/**

src/GraphQl/Subscription/SubscriptionManager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public function getPushPayloads(object $object): array
8282
$payloads = [];
8383
foreach ($subscriptions as [$subscriptionId, $subscriptionFields, $subscriptionResult]) {
8484
$resolverContext = ['fields' => $subscriptionFields, 'is_collection' => false, 'is_mutation' => false, 'is_subscription' => true];
85-
/** @var Operation */
8685
$operation = (new Subscription())->withName('update_subscription')->withShortName($shortName);
8786
$data = $this->normalizeProcessor->process($object, $operation, [], $resolverContext);
8887

src/GraphQl/Tests/Type/FieldsBuilderTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,6 @@ public function testResolveResourceArgs(array $args, array $expectedResolvedArgs
855855

856856
$this->typeConverterProphecy->resolveType(Argument::type('string'))->willReturn(GraphQLType::string());
857857

858-
/** @var Operation $operation */
859858
$operation = (new Query())->withName('operation')->withShortName('shortName');
860859
$args = $this->fieldsBuilder->resolveResourceArgs($args, $operation);
861860

src/GraphQl/Tests/Type/TypeBuilderTest.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public function testGetResourceObjectType(): void
8686
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
8787
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();
8888

89-
/** @var Operation $operation */
9089
$operation = (new Query())->withShortName('shortName')->withDescription('description')->withClass('resourceClass');
9190
/** @var ObjectType $resourceObjectType */
9291
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadataCollection, $operation, null, ['input' => false]);
@@ -112,7 +111,6 @@ public function testGetResourceObjectTypeOutputClass(): void
112111
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
113112
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();
114113

115-
/** @var Operation $operation */
116114
$operation = (new Query())->withShortName('shortName')->withDescription('description')->withOutput(['class' => 'outputClass']);
117115
/** @var ObjectType $resourceObjectType */
118116
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadataCollection, $operation, null, ['input' => false]);
@@ -177,7 +175,6 @@ public function testGetResourceObjectTypeInput(): void
177175
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
178176
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();
179177

180-
/** @var Operation $operation */
181178
$operation = (new Mutation())->withName('custom')->withShortName('shortName')->withDescription('description')->withClass('resourceClass');
182179
/** @var NonNull $resourceObjectType */
183180
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => true]);
@@ -202,7 +199,6 @@ public function testGetResourceObjectTypeNestedInput(): void
202199
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
203200
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();
204201

205-
/** @var Operation $operation */
206202
$operation = (new Mutation())->withName('custom')->withShortName('shortName')->withDescription('description')->withClass('resourceClass');
207203
/** @var NonNull $resourceObjectType */
208204
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => true, 'wrapped' => false, 'depth' => 1]);
@@ -227,9 +223,7 @@ public function testGetResourceObjectTypeNestedInputNullable(): void
227223
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
228224
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();
229225

230-
/** @var Operation $operation */
231226
$operation = (new Mutation())->withName('custom')->withShortName('shortNameNullable')->withDescription('description nullable')->withClass('resourceClass');
232-
/** @var ApiProperty $propertyMetadata */
233227
$propertyMetadata = (new ApiProperty())->withRequired(false);
234228
/** @var InputObjectType $resourceObjectType */
235229
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, $propertyMetadata, [
@@ -257,7 +251,6 @@ public function testGetResourceObjectTypeCustomMutationInputArgs(): void
257251
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
258252
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();
259253

260-
/** @var Operation $operation */
261254
$operation = (new Mutation())->withArgs([])->withName('custom')->withShortName('shortName')->withDescription('description')->withClass('resourceClass');
262255
/** @var NonNull $resourceObjectType */
263256
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => true]);
@@ -288,7 +281,6 @@ public function testGetResourceObjectTypeMutation(): void
288281
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
289282
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();
290283

291-
/** @var Operation $operation */
292284
$operation = (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withClass('resourceClass');
293285
/** @var ObjectType $resourceObjectType */
294286
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false]);
@@ -320,7 +312,6 @@ public function testGetResourceObjectTypeMutationWrappedType(): void
320312
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
321313
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();
322314

323-
/** @var Operation $operation */
324315
$operation = (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['create']])->withClass('resourceClass');
325316
/** @var ObjectType $resourceObjectType */
326317
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false]);
@@ -362,7 +353,6 @@ public function testGetResourceObjectTypeMutationNested(): void
362353
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
363354
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();
364355

365-
/** @var Operation $operation */
366356
$operation = (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withClass('resourceClass');
367357
/** @var ObjectType $resourceObjectType */
368358
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false, 'wrapped' => false, 'depth' => 1]);
@@ -390,7 +380,6 @@ public function testGetResourceObjectTypeSubscription(): void
390380
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
391381
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();
392382

393-
/** @var Operation $operation */
394383
$operation = (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withMercure(true)->withClass('resourceClass');
395384
/** @var ObjectType $resourceObjectType */
396385
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false]);
@@ -424,7 +413,6 @@ public function testGetResourceObjectTypeSubscriptionWrappedType(): void
424413
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
425414
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();
426415

427-
/** @var Operation $operation */
428416
$operation = (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['update']])->withClass('resourceClass');
429417
/** @var ObjectType $resourceObjectType */
430418
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false]);
@@ -467,7 +455,6 @@ public function testGetResourceObjectTypeSubscriptionNested(): void
467455
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
468456
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();
469457

470-
/** @var Operation $operation */
471458
$operation = (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withMercure(true)->withClass('resourceClass');
472459
/** @var ObjectType $resourceObjectType */
473460
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false, 'wrapped' => false, 'depth' => 1]);
@@ -496,18 +483,17 @@ public function testGetNodeInterface(): void
496483
$this->assertNull($nodeInterface->resolveType([], [], $this->prophesize(ResolveInfo::class)->reveal()));
497484

498485
$this->typesContainerProphecy->has('Dummy')->shouldBeCalled()->willReturn(false);
499-
$this->assertNull($nodeInterface->resolveType([ItemNormalizer::ITEM_RESOURCE_CLASS_KEY => Dummy::class], [], $this->prophesize(ResolveInfo::class)->reveal()));
486+
$resolvedType = $nodeInterface->resolveType([ItemNormalizer::ITEM_RESOURCE_CLASS_KEY => Dummy::class], [], $this->prophesize(ResolveInfo::class)->reveal());
487+
$this->assertNull($resolvedType);
500488

501489
$this->typesContainerProphecy->has('Dummy')->shouldBeCalled()->willReturn(true);
502490
$this->typesContainerProphecy->get('Dummy')->shouldBeCalled()->willReturn(GraphQLType::string());
503-
/** @var GraphQLType $resolvedType */
504491
$resolvedType = $nodeInterface->resolveType([ItemNormalizer::ITEM_RESOURCE_CLASS_KEY => Dummy::class], [], $this->prophesize(ResolveInfo::class)->reveal());
505492
$this->assertSame(GraphQLType::string(), $resolvedType);
506493
}
507494

508495
public function testCursorBasedGetPaginatedCollectionType(): void
509496
{
510-
/** @var Operation $operation */
511497
$operation = (new Query())->withPaginationType('cursor');
512498
$this->typesContainerProphecy->has('StringCursorConnection')->shouldBeCalled()->willReturn(false);
513499
$this->typesContainerProphecy->set('StringCursorConnection', Argument::type(ObjectType::class))->shouldBeCalled();
@@ -563,7 +549,6 @@ public function testCursorBasedGetPaginatedCollectionType(): void
563549

564550
public function testPageBasedGetPaginatedCollectionType(): void
565551
{
566-
/** @var Operation $operation */
567552
$operation = (new Query())->withPaginationType('page');
568553
$this->typesContainerProphecy->has('StringPageConnection')->shouldBeCalled()->willReturn(false);
569554
$this->typesContainerProphecy->set('StringPageConnection', Argument::type(ObjectType::class))->shouldBeCalled();
@@ -601,7 +586,6 @@ public function testGetEnumType(): void
601586
$enumClass = GamePlayMode::class;
602587
$enumName = 'GamePlayMode';
603588
$enumDescription = 'GamePlayMode description';
604-
/** @var Operation $operation */
605589
$operation = (new Operation())
606590
->withClass($enumClass)
607591
->withShortName($enumName)

0 commit comments

Comments
 (0)