Skip to content

Commit 5d89083

Browse files
committed
adapt src
1 parent 8ece38a commit 5d89083

19 files changed

+55
-47
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ parameters:
2020
count: 1
2121
path: src/Language/Visitor.php
2222

23-
-
24-
message: "#^Parameter \\#1 \\$config of class GraphQL\\\\Type\\\\Definition\\\\Argument constructor expects array\\{name\\: string, type\\: \\(callable\\(\\)\\: \\(GraphQL\\\\Type\\\\Definition\\\\InputType&GraphQL\\\\Type\\\\Definition\\\\Type\\)\\)\\|\\(GraphQL\\\\Type\\\\Definition\\\\InputType&GraphQL\\\\Type\\\\Definition\\\\Type\\), defaultValue\\?\\: mixed, description\\?\\: string\\|null, deprecationReason\\?\\: string\\|null, astNode\\?\\: GraphQL\\\\Language\\\\AST\\\\InputValueDefinitionNode\\|null\\}, non\\-empty\\-array given\\.$#"
25-
count: 1
26-
path: src/Type/Definition/Argument.php
27-
2823
-
2924
message: "#^Property GraphQL\\\\Type\\\\Definition\\\\InterfaceType\\:\\:\\$interfaces \\(array\\<int, GraphQL\\\\Type\\\\Definition\\\\InterfaceType\\>\\) does not accept array\\<int, GraphQL\\\\Type\\\\Definition\\\\Type\\>\\.$#"
3025
count: 1
@@ -79,13 +74,3 @@ parameters:
7974
message: "#^Method GraphQL\\\\Validator\\\\Rules\\\\KnownDirectives\\:\\:getDirectiveLocationForASTPath\\(\\) has parameter \\$ancestors with generic class GraphQL\\\\Language\\\\AST\\\\NodeList but does not specify its types\\: T$#"
8075
count: 1
8176
path: src/Validator/Rules/KnownDirectives.php
82-
83-
-
84-
message: "#^Method GraphQL\\\\Validator\\\\Rules\\\\OverlappingFieldsCanBeMerged\\:\\:getFieldsAndFragmentNames\\(\\) should return array\\{array\\<string, array\\<int, array\\{GraphQL\\\\Type\\\\Definition\\\\Type, GraphQL\\\\Language\\\\AST\\\\FieldNode, GraphQL\\\\Type\\\\Definition\\\\FieldDefinition\\|null\\}\\>\\>, array\\<int, string\\>\\} but returns array\\{mixed, array\\<int, int\\|string\\>\\}\\.$#"
85-
count: 1
86-
path: src/Validator/Rules/OverlappingFieldsCanBeMerged.php
87-
88-
-
89-
message: "#^SplObjectStorage\\<GraphQL\\\\Language\\\\AST\\\\SelectionSetNode, array\\{array\\<string, array\\<int, array\\{GraphQL\\\\Type\\\\Definition\\\\Type, GraphQL\\\\Language\\\\AST\\\\FieldNode, GraphQL\\\\Type\\\\Definition\\\\FieldDefinition\\|null\\}\\>\\>, array\\<int, string\\>\\}\\> does not accept array\\<int, mixed\\>\\.$#"
90-
count: 1
91-
path: src/Validator/Rules/OverlappingFieldsCanBeMerged.php

src/Error/Error.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function __construct(
9393

9494
// Compute list of blame nodes.
9595
if ($nodes instanceof \Traversable) {
96-
$this->nodes = array_filter(\iterator_to_array($nodes));
96+
$this->nodes = array_filter(\iterator_to_array($nodes), static fn (?Node $node): bool => $node !== null);
9797
} elseif (\is_array($nodes)) {
9898
$this->nodes = array_filter($nodes);
9999
} elseif ($nodes !== null) {

src/Executor/ExecutionContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ExecutionContext
4949
*/
5050
public $argsMapper;
5151

52-
/** @var array<int, Error> */
52+
/** @var list<Error> */
5353
public array $errors;
5454

5555
public PromiseAdapter $promiseAdapter;
@@ -59,7 +59,7 @@ class ExecutionContext
5959
* @param mixed $rootValue
6060
* @param mixed $contextValue
6161
* @param array<string, mixed> $variableValues
62-
* @param array<int, Error> $errors
62+
* @param list<Error> $errors
6363
*
6464
* @phpstan-param FieldResolver $fieldResolver
6565
*/

src/Executor/ExecutionResult.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,14 @@ public function toArray(int $debug = DebugFlag::NONE): array
158158
$result = [];
159159

160160
if ($this->errors !== []) {
161+
/**
162+
* @phpstan-var ErrorsHandler $defaultErrorsHandler
163+
*
164+
* @phpstan-ignore varTag.nativeType (phpstan cannot type callables yet)
165+
*/
166+
$defaultErrorsHandler = static fn (array $errors, callable $formatter): array => \array_map($formatter, $errors);
161167
$errorsHandler = $this->errorsHandler
162-
?? static fn (array $errors, callable $formatter): array => \array_map($formatter, $errors);
168+
?? $defaultErrorsHandler;
163169

164170
$handledErrors = $errorsHandler(
165171
$this->errors,

src/Executor/Promise/Adapter/AmpPromiseAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function all(iterable $promisesOrValues): Promise
126126

127127
/**
128128
* @template TArgument
129-
* @template TResult
129+
* @template TResult of \Amp\Promise<mixed>
130130
*
131131
* @param Deferred<TResult> $deferred
132132
* @param callable(TArgument): TResult $callback

src/Executor/ReferenceExecutor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function doExecute(): Promise
150150
*
151151
* @throws \Exception
152152
*
153-
* @return ExecutionContext|array<int, Error>
153+
* @return ExecutionContext|list<Error>
154154
*/
155155
protected static function buildExecutionContext(
156156
Schema $schema,
@@ -163,7 +163,7 @@ protected static function buildExecutionContext(
163163
callable $argsMapper,
164164
PromiseAdapter $promiseAdapter
165165
) {
166-
/** @var array<int, Error> $errors */
166+
/** @var list<Error> $errors */
167167
$errors = [];
168168

169169
/** @var array<string, FragmentDefinitionNode> $fragments */

src/Language/AST/Node.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ protected static function cloneValue($value)
7979
}
8080

8181
if ($value instanceof NodeList) {
82+
/**
83+
* @phpstan-var TCloneable
84+
*
85+
* @phpstan-ignore varTag.nativeType (PHPStan is strict about template types and sees NodeList<TNode> as potentially different from TCloneable)
86+
*/
8287
return $value->cloneDeep();
8388
}
8489

src/Language/AST/NodeList.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ public function reindex(): void
145145
*/
146146
public function cloneDeep(): self
147147
{
148-
/** @var static<T> $cloned */
149-
$cloned = new static([]);
148+
/** @var array<T> $empty */
149+
$empty = [];
150+
$cloned = new static($empty);
150151
foreach ($this->getIterator() as $key => $node) {
151152
$cloned[$key] = $node->cloneDeep();
152153
}

src/Language/Printer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,6 @@ protected function indent(string $string): string
531531
/** @param array<string|null> $parts */
532532
protected function join(array $parts, string $separator = ''): string
533533
{
534-
return \implode($separator, \array_filter($parts));
534+
return \implode($separator, \array_filter($parts, static fn (?string $part) => $part !== '' && $part !== null));
535535
}
536536
}

src/Language/Visitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ public static function visitWithTypeInfo(TypeInfo $typeInfo, array $visitor): ar
478478
/**
479479
* @phpstan-param VisitorArray $visitor
480480
*
481-
* @return callable(Node $node, string $key, Node|NodeList $parent, array<int, int|string $path, array<int, Node|NodeList> $ancestors): VisitorOperation|Node|null
481+
* @return (callable(Node $node, string $key, Node|NodeList<Node>|null $parent, array<int, int|string> $path, array<int, Node|NodeList<Node>> $ancestors): (VisitorOperation|Node|null))|(callable(Node): (VisitorOperation|void|false|null))|null
482482
*/
483483
protected static function extractVisitFn(array $visitor, string $kind, bool $isLeaving): ?callable
484484
{

0 commit comments

Comments
 (0)