Skip to content

Commit d92271b

Browse files
authored
Merge pull request #234 from moufmouf/phpstan_wrongly_ignored_errors
Fixing ignoreErrors section of PHPStan file
2 parents e5911d2 + e4bd941 commit d92271b

28 files changed

+184
-56
lines changed

phpstan.neon

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
parameters:
22
ignoreErrors:
33
- "#PHPDoc tag \\@throws with type Psr\\\\Container\\\\ContainerExceptionInterface is not subtype of Throwable#"
4-
- "#Property TheCodingMachine\\\\GraphQLite\\\\Types\\\\ResolvableInputObjectType::$resolve \\(array<int, object|string>&callable\\) does not accept array<int,object|string>#"
4+
#- "#Property TheCodingMachine\\\\GraphQLite\\\\Types\\\\ResolvableInputObjectType::\\$resolve \\(array<int, object\\|string>&callable\\) does not accept array<int,object\\|string>#"
55
- "#Variable \\$prefetchRefMethod might not be defined.#"
6-
- "#Parameter \\#2 $type of class TheCodingMachine\\\\GraphQLite\\\\Parameters\\\\InputTypeParameter constructor expects GraphQL\\\\Type\\\\Definition\\\\InputType&GraphQL\\\\Type\\\\Definition\\\\Type, GraphQL\\\\Type\\\\Definition\\\\InputType|GraphQL\\\\Type\\\\Definition\\\\Type given.#"
7-
- "#Parameter .* of class ReflectionMethod constructor expects string, object|string given.#"
8-
- "#Method TheCodingMachine\\\\GraphQLite\\\\Types\\\\MutableObjectType::getFields() should return array<GraphQL\\\\Type\\\\Definition\\\\FieldDefinition> but returns array|float|int.#"
9-
- "#Parameter \\#2 \\$inputTypeNode of static method GraphQL\\\\Utils\\\\AST::typeFromAST() expects GraphQL\\\\Language\\\\AST\\\\ListTypeNode|GraphQL\\\\Language\\\\AST\\\\NamedTypeNode|GraphQL\\\\Language\\\\AST\\\\NonNullTypeNode, GraphQL\\\\Language\\\\AST\\\\ListTypeNode|GraphQL\\\\Language\\\\AST\\\\NameNode|GraphQL\\\\Language\\\\AST\\\\NonNullTypeNode given.#"
6+
#- "#Parameter \\#2 \\$type of class TheCodingMachine\\\\GraphQLite\\\\Parameters\\\\InputTypeParameter constructor expects GraphQL\\\\Type\\\\Definition\\\\InputType&GraphQL\\\\Type\\\\Definition\\\\Type, GraphQL\\\\Type\\\\Definition\\\\InputType\\|GraphQL\\\\Type\\\\Definition\\\\Type given.#"
7+
- "#Parameter .* of class ReflectionMethod constructor expects string, object\\|string given.#"
8+
-
9+
message: '#Method TheCodingMachine\\GraphQLite\\Types\\Mutable(Interface|Object)Type::getFields\(\) should return array<GraphQL\\Type\\Definition\\FieldDefinition> but returns array\|float\|int#'
10+
path: src/Types/MutableTrait.php
11+
#- "#Parameter \\#2 \\$inputTypeNode of static method GraphQL\\\\Utils\\\\AST::typeFromAST() expects GraphQL\\\\Language\\\\AST\\\\ListTypeNode\\|GraphQL\\\\Language\\\\AST\\\\NamedTypeNode\\|GraphQL\\\\Language\\\\AST\\\\NonNullTypeNode, GraphQL\\\\Language\\\\AST\\\\ListTypeNode\\|GraphQL\\\\Language\\\\AST\\\\NameNode\\|GraphQL\\\\Language\\\\AST\\\\NonNullTypeNode given.#"
1012
- "#PHPDoc tag @throws with type Psr\\\\SimpleCache\\\\InvalidArgumentException is not subtype of Throwable#"
1113
- '#Variable \$context might not be defined.#'
1214
-
@@ -22,9 +24,14 @@ parameters:
2224
message: '#Unreachable statement - code above always terminates.#'
2325
path: src/Http/WebonyxGraphqlMiddleware.php
2426
-
25-
message: '#Property TheCodingMachine\GraphQLite\Annotations\Type::$class \(class-string<object>|null\) does not accept string.#'
27+
message: '#Property TheCodingMachine\GraphQLite\Annotations\Type::\$class \(class-string<object>\\|null\) does not accept string.#'
2628
path: src/Annotations/Type.php
29+
-
30+
message: '#Method TheCodingMachine\\GraphQLite\\AnnotationReader::getMethodAnnotations\(\) should return array<int, T of object> but returns array<object>.#'
31+
path: src/AnnotationReader.php
2732
- '#Call to an undefined method GraphQL\\Error\\ClientAware::getMessage()#'
33+
# Needed because of a bug in PHP-CS
34+
- '#PHPDoc tag @param for parameter \$args with type mixed is not subtype of native type array<int, mixed>.#'
2835
#-
2936
# message: '#If condition is always true#'
3037
# path: src/Middlewares/SecurityFieldMiddleware.php

src/AggregateControllerQueryProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
*/
2525
class AggregateControllerQueryProvider implements QueryProviderInterface
2626
{
27-
/** @var array|string[] */
27+
/** @var iterable<string> */
2828
private $controllers;
2929
/** @var ContainerInterface */
3030
private $controllersContainer;
3131
/** @var FieldsBuilder */
3232
private $fieldsBuilder;
3333

3434
/**
35-
* @param string[] $controllers A list of controllers name in the container.
35+
* @param iterable<string> $controllers A list of controllers name in the container.
3636
* @param ContainerInterface $controllersContainer The container we will fetch controllers from.
3737
*/
3838
public function __construct(iterable $controllers, FieldsBuilder $fieldsBuilder, ContainerInterface $controllersContainer)
@@ -73,7 +73,7 @@ public function getMutations(): array
7373
}
7474

7575
/**
76-
* @param array<int, array<string, FieldDefinition>> $list
76+
* @param array<string, array<string, FieldDefinition>> $list
7777
*
7878
* @return array<string, FieldDefinition>
7979
*/

src/AggregateControllerQueryProviderFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
*/
1212
class AggregateControllerQueryProviderFactory implements QueryProviderFactoryInterface
1313
{
14-
/** @var array|string[] */
14+
/** @var iterable<string> */
1515
private $controllers;
1616
/** @var ContainerInterface */
1717
private $controllersContainer;
1818

1919
/**
20-
* @param string[] $controllers A list of controllers name in the container.
20+
* @param iterable<string> $controllers A list of controllers name in the container.
2121
* @param ContainerInterface $controllersContainer The container we will fetch controllers from.
2222
*/
2323
public function __construct(iterable $controllers, ContainerInterface $controllersContainer)

src/Annotations/Security.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Security implements MiddlewareAnnotationInterface
2525
private $failWith;
2626
/** @var bool */
2727
private $failWithIsSet = false;
28-
/** @var int|null */
28+
/** @var int */
2929
private $statusCode;
3030
/** @var string */
3131
private $message;

src/InputTypeUtils.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ public function __construct(
4040
/**
4141
* Returns an array with 2 elements: [ $inputName, $className ]
4242
*
43-
* @return string[]
43+
* @return array{0: string, 1:class-string<object>}
4444
*/
4545
public function getInputTypeNameAndClassName(ReflectionMethod $method): array
4646
{
47+
/**
48+
* @var class-string<object>
49+
*/
4750
$fqsen = ltrim((string) $this->validateReturnType($method), '\\');
4851
$factory = $this->annotationReader->getFactoryAnnotation($method);
4952
if ($factory === null) {

src/Mappers/AbstractTypeMapper.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ private function buildMapClassToExtendTypeArray(): GlobExtendTypeMapperCache
241241

242242
/**
243243
* Returns true if this type mapper can map the $className FQCN to a GraphQL type.
244+
*
245+
* @param class-string<object> $className
244246
*/
245247
public function canMapClassToType(string $className): bool
246248
{
@@ -250,7 +252,7 @@ public function canMapClassToType(string $className): bool
250252
/**
251253
* Maps a PHP fully qualified class name to a GraphQL type.
252254
*
253-
* @param string $className The exact class name to look for (this function does not look into parent classes).
255+
* @param class-string<object> $className The exact class name to look for (this function does not look into parent classes).
254256
* @param OutputType|null $subType An optional sub-type if the main class is an iterator that needs to be typed.
255257
*
256258
* @throws CannotMapTypeExceptionInterface
@@ -287,9 +289,11 @@ public function canMapClassToInputType(string $className): bool
287289
/**
288290
* Maps a PHP fully qualified class name to a GraphQL input type.
289291
*
292+
* @param class-string<object> $className
293+
*
290294
* @return ResolvableMutableInputInterface&InputObjectType
291295
*
292-
* @throws CannotMapTypeExceptionInterface
296+
* @throws CannotMapTypeException
293297
*/
294298
public function mapClassToInputType(string $className): ResolvableMutableInputInterface
295299
{
@@ -359,6 +363,7 @@ public function canExtendTypeForClass(string $className, MutableInterface $type)
359363
/**
360364
* Extends the existing GraphQL type that is mapped to $className.
361365
*
366+
* @param class-string<object> $className
362367
* @param MutableInterface&(MutableObjectType|MutableInterfaceType) $type
363368
*
364369
* @throws CannotMapTypeExceptionInterface

src/Mappers/CannotMapTypeException.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,17 @@ class CannotMapTypeException extends Exception implements CannotMapTypeException
2626
{
2727
use CannotMapTypeTrait;
2828

29+
/**
30+
* @param class-string<object> $className
31+
*/
2932
public static function createForType(string $className): self
3033
{
3134
return new self('cannot map class "' . $className . '" to a known GraphQL type. Check your TypeMapper configuration.');
3235
}
3336

37+
/**
38+
* @param class-string<object> $className
39+
*/
3440
public static function createForInputType(string $className): self
3541
{
3642
return new self('cannot map class "' . $className . '" to a known GraphQL input type. Check your TypeMapper configuration.');
@@ -46,6 +52,9 @@ public static function createForParseError(Error $error): self
4652
return new self($error->getMessage(), $error->getCode(), $error);
4753
}
4854

55+
/**
56+
* @param class-string<object> $className
57+
*/
4958
public static function createForMissingIteratorValue(string $className, self $e): self
5059
{
5160
$message = sprintf(
@@ -87,6 +96,7 @@ public static function mustBeInputType(string $subTypeName): self
8796
}
8897

8998
/**
99+
* @param class-string<object> $className
90100
* @param NamedType&(ObjectType|InterfaceType) $type
91101
*
92102
* @return CannotMapTypeException
@@ -111,6 +121,9 @@ public static function createForDecorateName(string $name, InputObjectType $type
111121
return new self('cannot decorate GraphQL input type "' . $type->name . '" with type "' . $name . '". Check your TypeMapper configuration.');
112122
}
113123

124+
/**
125+
* @param class-string<object> $className
126+
*/
114127
public static function extendTypeWithBadTargetedClass(string $className, ExtendType $extendType): self
115128
{
116129
return new self('For ' . self::extendTypeToString($extendType) . ' annotation declared in class "' . $className . '", the pointed at GraphQL type cannot be extended. You can only target types extending the MutableObjectType (like types created with the @Type annotation).');

src/Mappers/CompositeTypeMapper.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public function addTypeMapper(TypeMapperInterface $typeMapper): void
3535

3636
/**
3737
* Returns true if this type mapper can map the $className FQCN to a GraphQL type.
38+
*
39+
* @param class-string<object> $className
3840
*/
3941
public function canMapClassToType(string $className): bool
4042
{
@@ -50,6 +52,7 @@ public function canMapClassToType(string $className): bool
5052
/**
5153
* Maps a PHP fully qualified class name to a GraphQL type.
5254
*
55+
* @param class-string<object> $className
5356
* @param (OutputType&Type)|null $subType
5457
*
5558
* @throws CannotMapTypeExceptionInterface
@@ -87,6 +90,8 @@ public function getSupportedClasses(): array
8790

8891
/**
8992
* Returns true if this type mapper can map the $className FQCN to a GraphQL input type.
93+
*
94+
* @param class-string<object> $className
9095
*/
9196
public function canMapClassToInputType(string $className): bool
9297
{
@@ -102,6 +107,8 @@ public function canMapClassToInputType(string $className): bool
102107
/**
103108
* Maps a PHP fully qualified class name to a GraphQL input type.
104109
*
110+
* @param class-string<object> $className
111+
*
105112
* @return ResolvableMutableInputInterface&InputObjectType
106113
*
107114
* @throws CannotMapTypeExceptionInterface
@@ -152,6 +159,7 @@ public function canMapNameToType(string $typeName): bool
152159
/**
153160
* Returns true if this type mapper can extend an existing type for the $className FQCN
154161
*
162+
* @param class-string<object> $className
155163
* @param MutableInterface&(MutableObjectType|MutableInterfaceType) $type
156164
*/
157165
public function canExtendTypeForClass(string $className, MutableInterface $type): bool
@@ -168,6 +176,7 @@ public function canExtendTypeForClass(string $className, MutableInterface $type)
168176
/**
169177
* Extends the existing GraphQL type that is mapped to $className.
170178
*
179+
* @param class-string<object> $className
171180
* @param MutableInterface&(MutableObjectType|MutableInterfaceType) $type
172181
*
173182
* @throws CannotMapTypeExceptionInterface

src/Mappers/DuplicateMappingException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public static function createForType(string $sourceClass, string $type1, string
1515
throw new self(sprintf("The class '%s' should be mapped by only one GraphQL type class. Two classes are pointing via the @Type annotation to this class: '%s' and '%s'", $sourceClass, $type1, $type2));
1616
}
1717

18+
/**
19+
* @param class-string<object> $sourceClass
20+
* @param class-string<object> $className1
21+
* @param class-string<object> $className2
22+
*/
1823
public static function createForFactory(string $sourceClass, string $className1, string $method1, string $className2, string $method2): self
1924
{
2025
throw new self(sprintf("The class '%s' should be mapped to only one GraphQL Input type. Two methods are pointing via the @Factory annotation to this class: '%s::%s' and '%s::%s'", $sourceClass, $className1, $method1, $className2, $method2));

src/Mappers/GlobAnnotationsCache.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
final class GlobAnnotationsCache
1313
{
14-
/** @var string|null */
14+
/** @var class-string<object>|null */
1515
private $typeClassName;
1616

1717
/** @var string|null */
@@ -20,19 +20,25 @@ final class GlobAnnotationsCache
2020
/** @var bool */
2121
private $default;
2222

23-
/** @var array<string, array<int, string|bool>> An array mapping a factory method name to an input name / class name / default flag / declaring class */
23+
/** @var array<string, array{0: string, 1:class-string<object>|null, 2:bool, 3:class-string<object>}> An array mapping a factory method name to an input name / class name / default flag / declaring class */
2424
private $factories = [];
2525

26-
/** @var array<string, array<int, string>> An array mapping a decorator method name to an input name / declaring class */
26+
/** @var array<string, array{0: string, 1:class-string<object>}> An array mapping a decorator method name to an input name / declaring class */
2727
private $decorators = [];
2828

29+
/**
30+
* @param class-string<object> $className
31+
*/
2932
public function setType(string $className, string $typeName, bool $isDefault): void
3033
{
3134
$this->typeClassName = $className;
3235
$this->typeName = $typeName;
3336
$this->default = $isDefault;
3437
}
3538

39+
/**
40+
* @return class-string<object>|null
41+
*/
3642
public function getTypeClassName(): ?string
3743
{
3844
return $this->typeClassName;
@@ -48,26 +54,33 @@ public function isDefault(): bool
4854
return $this->default;
4955
}
5056

57+
/**
58+
* @param class-string<object>|null $className
59+
* @param class-string<object> $declaringClass
60+
*/
5161
public function registerFactory(string $methodName, string $inputName, ?string $className, bool $isDefault, string $declaringClass): void
5262
{
5363
$this->factories[$methodName] = [$inputName, $className, $isDefault, $declaringClass];
5464
}
5565

66+
/**
67+
* @param class-string<object> $declaringClass
68+
*/
5669
public function registerDecorator(string $methodName, string $inputName, string $declaringClass): void
5770
{
5871
$this->decorators[$methodName] = [$inputName, $declaringClass];
5972
}
6073

6174
/**
62-
* @return array<string, array<int, string|bool>>
75+
* @return array<string, array{0: string, 1:class-string<object>|null, 2:bool, 3:class-string<object>}>
6376
*/
6477
public function getFactories(): array
6578
{
6679
return $this->factories;
6780
}
6881

6982
/**
70-
* @return array<string, array<int, string>>
83+
* @return array<string, array{0: string, 1:class-string<object>}>
7184
*/
7285
public function getDecorators(): array
7386
{

0 commit comments

Comments
 (0)