Skip to content

Commit d1ca5cb

Browse files
vincentchalamonalanpoulain
authored andcommitted
fix: PHPStan
1 parent 1bd5c20 commit d1ca5cb

File tree

66 files changed

+82
-248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+82
-248
lines changed

phpstan.neon.dist

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ parameters:
3939
- handleNotFound
4040
ignoreErrors:
4141
# False positives
42+
-
43+
message: '#but database expects#'
44+
paths:
45+
- tests/Fixtures/TestBundle/Entity/
4246
-
4347
message: '#is never read, only written.#'
4448
paths:
@@ -49,14 +53,12 @@ parameters:
4953
message: '#is never written, only read.#'
5054
paths:
5155
- tests/Fixtures/TestBundle/Document/
52-
- tests/Fixtures/TestBundle/Entity/
5356
- '#Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy<(\\?[a-zA-Z0-9_]+)+>::\$[a-zA-Z0-9_]+#'
5457
# https://github.com/willdurand/Negotiation/issues/89#issuecomment-513283286
5558
-
5659
message: '#Call to an undefined method Negotiation\\AcceptHeader::getType\(\)\.#'
5760
path: src/Symfony/EventListener/AddFormatListener.php
5861
- '#Parameter \#1 \$vars of class GraphQL\\Language\\AST\\(IntValue|ObjectField|ObjectValue|BooleanValue|ListValue|StringValue)Node constructor expects array<bool\|float\|GraphQL\\Language\\AST\\Location\|GraphQL\\Language\\AST\\NameNode\|GraphQL\\Language\\AST\\NodeList\|GraphQL\\Language\\AST\\SelectionSetNode\|int\|string\|null>, array<string, .+> given\.#'
59-
- '#Parameter \#1 \$defaultContext of class Symfony\\Component\\Serializer\\Encoder\\Json(De|En)code constructor expects array, (int|true) given\.#'
6062
-
6163
message: '#Parameter \#1 \$objectValue of method GraphQL\\Type\\Definition\\InterfaceType::resolveType\(\) expects object, array(<string, string>)? given.#'
6264
path: tests/GraphQl/Type/TypeBuilderTest.php
@@ -74,23 +76,10 @@ parameters:
7476
-
7577
message: "#Call to function method_exists\\(\\) with ApiPlatform\\\\JsonApi\\\\Serializer\\\\ItemNormalizer and 'setCircularReferenc…' will always evaluate to false\\.#"
7678
path: tests/JsonApi/Serializer/ItemNormalizerTest.php
77-
-
78-
message: "#Dead catch - JsonException is never thrown in the try block.#"
79-
path: src/Symfony/Bundle/Test/Response.php
8079
# See https://github.com/phpstan/phpstan-symfony/issues/27
8180
-
8281
message: '#^Service "[^"]+" is private.$#'
8382
path: src
8483
-
8584
message: '#^Property .+ is unused.$#'
8685
path: tests/Doctrine/Odm/PropertyInfo/Fixtures/DoctrineDummy.php
87-
-
88-
message: '#Call to an undefined method Symfony\\Component\\PropertyInfo\\Type::getCollectionValueType\(\)#'
89-
path: src
90-
-
91-
message: '#Call to an undefined method Symfony\\Component\\PropertyInfo\\Type::getCollectionKeyType\(\)#'
92-
path: src
93-
# Skipped tests, we do this on purpose
94-
-
95-
message: "#Access to an undefined static property static\\([^)]+\\)::\\$container.$#"
96-
path: tests

rector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
]);
3131
$rectorConfig->phpstanConfig(__DIR__.'/phpstan.neon.dist');
3232
$rectorConfig->importNames();
33-
$rectorConfig->disableImportShortClasses();
33+
$rectorConfig->importShortClasses(false);
3434

3535
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
3636

src/Api/IdentifiersExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
final class IdentifiersExtractor implements IdentifiersExtractorInterface
3434
{
3535
use ResourceClassInfoTrait;
36-
private readonly PropertyAccessorInterface|PropertyAccessor $propertyAccessor;
36+
private readonly PropertyAccessorInterface $propertyAccessor;
3737

3838
public function __construct(ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory, ResourceClassResolverInterface $resourceClassResolver, private readonly PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, private readonly PropertyMetadataFactoryInterface $propertyMetadataFactory, PropertyAccessorInterface $propertyAccessor = null)
3939
{

src/Doctrine/Common/PropertyHelperTrait.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ protected function isPropertyEmbedded(string $property, string $resourceClass):
7171
* Returns an array with the following keys:
7272
* - associations: array of associations according to nesting order
7373
* - field: string holding the actual field (leaf node)
74-
*
75-
* @return array{associations: string[], field: string}
7674
*/
7775
protected function splitPropertyParts(string $property, string $resourceClass): array
7876
{

src/Doctrine/Odm/Filter/SearchFilter.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ protected function filterProperty(string $property, $value, Builder $aggregation
142142

143143
/**
144144
* Add equality match stage according to the strategy.
145-
*
146-
* @param mixed $values
147145
*/
148146
private function addEqualityMatchStrategy(string $strategy, Builder $aggregationBuilder, string $field, string $matchField, array $values, bool $caseSensitive, ClassMetadata $metadata): void
149147
{

src/GraphQl/Resolver/Stage/SerializeStage.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ public function __invoke($itemOrCollection, string $resourceClass, Operation $op
109109
/**
110110
* @throws \LogicException
111111
* @throws \UnexpectedValueException
112-
*
113-
* @return array{totalCount: float|int, edges: array<mixed, array{node: mixed[]|bool|float|int|string|null, cursor: string}>, pageInfo: array{startCursor: string|null, endCursor: string|null, hasNextPage: bool, hasPreviousPage: bool}}
114112
*/
115113
private function serializeCursorBasedPaginatedCollection(iterable $collection, array $normalizationContext, array $context): array
116114
{
@@ -175,8 +173,6 @@ private function serializeCursorBasedPaginatedCollection(iterable $collection, a
175173

176174
/**
177175
* @throws \LogicException
178-
*
179-
* @return array{collection: bool[]|float[]|int[]|string[]|mixed[][]|null[], paginationInfo: array{itemsPerPage: float, totalCount: float, lastPage: float}}
180176
*/
181177
private function serializePageBasedPaginatedCollection(iterable $collection, array $normalizationContext): array
182178
{
@@ -196,33 +192,21 @@ private function serializePageBasedPaginatedCollection(iterable $collection, arr
196192
return $data;
197193
}
198194

199-
/**
200-
* @return array{totalCount: float, edges: never[], pageInfo: array{startCursor: null, endCursor: null, hasNextPage: false, hasPreviousPage: false}}
201-
*/
202195
private function getDefaultCursorBasedPaginatedData(): array
203196
{
204197
return ['totalCount' => 0., 'edges' => [], 'pageInfo' => ['startCursor' => null, 'endCursor' => null, 'hasNextPage' => false, 'hasPreviousPage' => false]];
205198
}
206199

207-
/**
208-
* @return array{collection: never[], paginationInfo: array{itemsPerPage: float, totalCount: float, lastPage: float}}
209-
*/
210200
private function getDefaultPageBasedPaginatedData(): array
211201
{
212202
return ['collection' => [], 'paginationInfo' => ['itemsPerPage' => 0., 'totalCount' => 0., 'lastPage' => 0.]];
213203
}
214204

215-
/**
216-
* @return array{clientMutationId: mixed}
217-
*/
218205
private function getDefaultMutationData(array $context): array
219206
{
220207
return ['clientMutationId' => $context['args']['input']['clientMutationId'] ?? null];
221208
}
222209

223-
/**
224-
* @return array{clientSubscriptionId: mixed}
225-
*/
226210
private function getDefaultSubscriptionData(array $context): array
227211
{
228212
return ['clientSubscriptionId' => $context['args']['input']['clientSubscriptionId'] ?? null];

src/GraphQl/Type/FieldsBuilder.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
use ApiPlatform\State\Pagination\Pagination;
3030
use ApiPlatform\Util\Inflector;
3131
use GraphQL\Type\Definition\InputObjectType;
32-
use GraphQL\Type\Definition\InterfaceType;
33-
use GraphQL\Type\Definition\NonNull;
3432
use GraphQL\Type\Definition\NullableType;
3533
use GraphQL\Type\Definition\Type as GraphQLType;
3634
use GraphQL\Type\Definition\WrappingType;
@@ -53,8 +51,6 @@ public function __construct(private readonly PropertyNameCollectionFactoryInterf
5351

5452
/**
5553
* {@inheritdoc}
56-
*
57-
* @return array{type: InterfaceType, args: array{id: array{type: NonNull}}, resolve: callable}
5854
*/
5955
public function getNodeQueryFields(): array
6056
{
@@ -379,7 +375,7 @@ private function getFilterArgs(array $args, ?string $resourceClass, string $root
379375
}
380376

381377
foreach ($operation->getFilters() ?? [] as $filterId) {
382-
if (null === $this->filterLocator || !$this->filterLocator->has($filterId)) {
378+
if (!$this->filterLocator->has($filterId)) {
383379
continue;
384380
}
385381

@@ -410,11 +406,7 @@ private function getFilterArgs(array $args, ?string $resourceClass, string $root
410406
return $this->convertFilterArgsToTypes($args);
411407
}
412408

413-
/**
414-
* @param AbstractOperation|null $operation
415-
* @param mixed $original
416-
*/
417-
private function mergeFilterArgs(array $args, array $parsed, $operation = null, string $original = ''): array
409+
private function mergeFilterArgs(array $args, array $parsed, ?AbstractOperation $operation = null, string $original = ''): array
418410
{
419411
foreach ($parsed as $key => $value) {
420412
// Never override keys that cannot be merged

src/GraphQl/Type/TypeBuilder.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use ApiPlatform\State\Pagination\Pagination;
2626
use GraphQL\Type\Definition\InputObjectType;
2727
use GraphQL\Type\Definition\InterfaceType;
28-
use GraphQL\Type\Definition\ListOfType;
2928
use GraphQL\Type\Definition\NonNull;
3029
use GraphQL\Type\Definition\ObjectType;
3130
use GraphQL\Type\Definition\Type as GraphQLType;
@@ -245,9 +244,6 @@ public function isCollection(Type $type): bool
245244
return $type->isCollection() && ($collectionValueType = $type->getCollectionValueTypes()[0] ?? null) && null !== $collectionValueType->getClassName();
246245
}
247246

248-
/**
249-
* @return array{edges: ListOfType, pageInfo: NonNull, totalCount: NonNull}
250-
*/
251247
private function getCursorBasedPaginationFields(GraphQLType $resourceType): array
252248
{
253249
$shortName = $resourceType->name;
@@ -283,9 +279,6 @@ private function getCursorBasedPaginationFields(GraphQLType $resourceType): arra
283279
];
284280
}
285281

286-
/**
287-
* @return array{collection: ListOfType, paginationInfo: NonNull}
288-
*/
289282
private function getPageBasedPaginationFields(GraphQLType $resourceType): array
290283
{
291284
$shortName = $resourceType->name;

src/Hal/Serializer/CollectionNormalizer.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public function __construct(ResourceClassResolverInterface $resourceClassResolve
3535

3636
/**
3737
* {@inheritdoc}
38-
*
39-
* @return array{_links: array{self: array{href: string}, first?: array{href: string}, last?: array{href: string}, prev?: array{href: string}, next?: array{href: string}}, totalItems?: mixed, itemsPerPage?: int}
4038
*/
4139
protected function getPaginationData($object, array $context = []): array
4240
{

src/Hal/Serializer/EntrypointNormalizer.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ public function __construct(private readonly ResourceMetadataCollectionFactoryIn
3838

3939
/**
4040
* {@inheritdoc}
41-
*
42-
* @return array{_links: array<string, array{href: string|null}>&mixed[]}
4341
*/
4442
public function normalize(mixed $object, string $format = null, array $context = []): array
4543
{

0 commit comments

Comments
 (0)