Skip to content

chore: more phpstan fixes #7265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ parameters:
- tests/Fixtures/TestBundle/Document/
- tests/Fixtures/TestBundle/Entity/
- src/OpenApi/Factory/OpenApiFactory.php
-
message: '#is never assigned .* so it can be removed from the property type.#'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false positive because private ?int $id is not set with a setter but with doctrine magic.

paths:
- src/Doctrine/Common/Tests/Fixtures/
- src/Doctrine/Orm/Tests/Fixtures/
- src/Doctrine/Odm/Tests/Fixtures/
- src/Elasticsearch/Tests/Fixtures/
- src/GraphQl/Tests/Fixtures/
- src/JsonSchema/Tests/Fixtures/
- src/Metadata/Tests/Fixtures/
- src/Serializer/Tests/Fixtures/
- tests/Fixtures/
-
message: '#is never written, only read.#'
paths:
Expand Down Expand Up @@ -97,18 +109,6 @@ parameters:
message: '#^Service "[^"]+" is private.$#'
path: src


# 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
-
path: tests/
identifier: function.alreadyNarrowedType
-
identifier: property.unusedType
-
identifier: varTag.nativeType
-
identifier: trait.unused
-
identifier: catch.neverThrown
6 changes: 5 additions & 1 deletion src/Doctrine/Odm/PropertyHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ abstract protected function splitPropertyParts(string $property, string $resourc
*/
protected function getClassMetadata(string $resourceClass): ClassMetadata
{
/** @var ?ManagerRegistry $managerRegistry */
/**
* @var ?ManagerRegistry $managerRegistry
*
* @phpstan-ignore varTag.nativeType (https://github.com/phpstan/phpstan/issues/9515)
*/
$managerRegistry = $this->getManagerRegistry();
$manager = $managerRegistry?->getManagerForClass($resourceClass);

Expand Down
8 changes: 1 addition & 7 deletions src/Doctrine/Orm/Util/QueryBuilderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,7 @@ public static function getExistingJoin(QueryBuilder $queryBuilder, string $alias
*/
private static function mapRootAliases(array $rootAliases, array $rootEntities): array
{
/** @var false|array $aliasMap */
$aliasMap = array_combine($rootAliases, $rootEntities);
if (false === $aliasMap) {
throw new \LogicException('Number of root aliases and root entities do not match.');
}

return $aliasMap;
return array_combine($rootAliases, $rootEntities);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_combine never return false since php 8 and you require 8.2

}

/**
Expand Down
1 change: 0 additions & 1 deletion src/GraphQl/Subscription/SubscriptionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public function getPushPayloads(object $object): array
$payloads = [];
foreach ($subscriptions as [$subscriptionId, $subscriptionFields, $subscriptionResult]) {
$resolverContext = ['fields' => $subscriptionFields, 'is_collection' => false, 'is_mutation' => false, 'is_subscription' => true];
/** @var Operation */
$operation = (new Subscription())->withName('update_subscription')->withShortName($shortName);
$data = $this->normalizeProcessor->process($object, $operation, [], $resolverContext);

Expand Down
1 change: 0 additions & 1 deletion src/GraphQl/Tests/Type/FieldsBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,6 @@ public function testResolveResourceArgs(array $args, array $expectedResolvedArgs

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

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

Expand Down
20 changes: 2 additions & 18 deletions src/GraphQl/Tests/Type/TypeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();

/** @var Operation $operation */
$operation = (new Query())->withShortName('shortName')->withDescription('description')->withClass('resourceClass');
/** @var ObjectType $resourceObjectType */
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadataCollection, $operation, null, ['input' => false]);
Expand All @@ -112,7 +111,6 @@
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();

/** @var Operation $operation */
$operation = (new Query())->withShortName('shortName')->withDescription('description')->withOutput(['class' => 'outputClass']);
/** @var ObjectType $resourceObjectType */
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadataCollection, $operation, null, ['input' => false]);
Expand Down Expand Up @@ -177,7 +175,6 @@
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();

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

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

/** @var Operation $operation */
$operation = (new Mutation())->withName('custom')->withShortName('shortNameNullable')->withDescription('description nullable')->withClass('resourceClass');
/** @var ApiProperty $propertyMetadata */
$propertyMetadata = (new ApiProperty())->withRequired(false);
/** @var InputObjectType $resourceObjectType */
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, $propertyMetadata, [
Expand Down Expand Up @@ -257,7 +251,6 @@
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();

/** @var Operation $operation */
$operation = (new Mutation())->withArgs([])->withName('custom')->withShortName('shortName')->withDescription('description')->withClass('resourceClass');
/** @var NonNull $resourceObjectType */
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => true]);
Expand Down Expand Up @@ -288,7 +281,6 @@
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();

/** @var Operation $operation */
$operation = (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withClass('resourceClass');
/** @var ObjectType $resourceObjectType */
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false]);
Expand Down Expand Up @@ -320,7 +312,6 @@
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();

/** @var Operation $operation */
$operation = (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['create']])->withClass('resourceClass');
/** @var ObjectType $resourceObjectType */
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false]);
Expand Down Expand Up @@ -362,7 +353,6 @@
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();

/** @var Operation $operation */
$operation = (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withClass('resourceClass');
/** @var ObjectType $resourceObjectType */
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false, 'wrapped' => false, 'depth' => 1]);
Expand Down Expand Up @@ -390,7 +380,6 @@
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();

/** @var Operation $operation */
$operation = (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withMercure(true)->withClass('resourceClass');
/** @var ObjectType $resourceObjectType */
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false]);
Expand Down Expand Up @@ -424,7 +413,6 @@
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();

/** @var Operation $operation */
$operation = (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['update']])->withClass('resourceClass');
/** @var ObjectType $resourceObjectType */
$resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false]);
Expand Down Expand Up @@ -467,7 +455,6 @@
$this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false);
$this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled();

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

$this->typesContainerProphecy->has('Dummy')->shouldBeCalled()->willReturn(false);
$this->assertNull($nodeInterface->resolveType([ItemNormalizer::ITEM_RESOURCE_CLASS_KEY => Dummy::class], [], $this->prophesize(ResolveInfo::class)->reveal()));
$resolvedType = $nodeInterface->resolveType([ItemNormalizer::ITEM_RESOURCE_CLASS_KEY => Dummy::class], [], $this->prophesize(ResolveInfo::class)->reveal());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setting a variable avoid a phpstan bug

$this->assertNull($resolvedType);

Check warning on line 487 in src/GraphQl/Tests/Type/TypeBuilderTest.php

View check run for this annotation

Codecov / codecov/patch

src/GraphQl/Tests/Type/TypeBuilderTest.php#L486-L487

Added lines #L486 - L487 were not covered by tests

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

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

public function testPageBasedGetPaginatedCollectionType(): void
{
/** @var Operation $operation */
$operation = (new Query())->withPaginationType('page');
$this->typesContainerProphecy->has('StringPageConnection')->shouldBeCalled()->willReturn(false);
$this->typesContainerProphecy->set('StringPageConnection', Argument::type(ObjectType::class))->shouldBeCalled();
Expand Down Expand Up @@ -601,7 +586,6 @@
$enumClass = GamePlayMode::class;
$enumName = 'GamePlayMode';
$enumDescription = 'GamePlayMode description';
/** @var Operation $operation */
$operation = (new Operation())
->withClass($enumClass)
->withShortName($enumName)
Expand Down
Loading
Loading