Skip to content

Commit

Permalink
phpstan: prefer using list<> syntax whenever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
mfn committed Mar 4, 2024
1 parent b82745f commit 1f779a3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 21 deletions.
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ parameters:
count: 1
path: src/GraphQL.php

-
message: "#^Method Rebing\\\\GraphQL\\\\GraphQL\\:\\:getGlobalResolverMiddlewares\\(\\) should return list\\<class\\-string\\|object\\> but returns array\\.$#"
count: 1
path: src/GraphQL.php

-
message: "#^Parameter \\#1 \\$config of class GraphQL\\\\Type\\\\Definition\\\\ObjectType constructor expects array\\{name\\?\\: string\\|null, description\\?\\: string\\|null, resolveField\\?\\: \\(callable\\(mixed, array\\<string, mixed\\>, mixed, GraphQL\\\\Type\\\\Definition\\\\ResolveInfo\\)\\: mixed\\)\\|null, fields\\: \\(callable\\(\\)\\: iterable\\)\\|iterable, interfaces\\?\\: \\(callable\\(\\)\\: iterable\\<callable\\(\\)\\: GraphQL\\\\Type\\\\Definition\\\\InterfaceType\\|GraphQL\\\\Type\\\\Definition\\\\InterfaceType\\>\\)\\|iterable\\<\\(callable\\(\\)\\: GraphQL\\\\Type\\\\Definition\\\\InterfaceType\\)\\|GraphQL\\\\Type\\\\Definition\\\\InterfaceType\\>, isTypeOf\\?\\: \\(callable\\(mixed, mixed, GraphQL\\\\Type\\\\Definition\\\\ResolveInfo\\)\\: \\(bool\\|GraphQL\\\\Deferred\\|null\\)\\)\\|null, astNode\\?\\: GraphQL\\\\Language\\\\AST\\\\ObjectTypeDefinitionNode\\|null, extensionASTNodes\\?\\: array\\<int, GraphQL\\\\Language\\\\AST\\\\ObjectTypeExtensionNode\\>\\|null\\}, non\\-empty\\-array\\<string, array\\<int\\|string, non\\-empty\\-array\\<string, mixed\\>\\|\\(ArrayAccess&Rebing\\\\GraphQL\\\\Support\\\\Field\\)\\>\\|string\\> given\\.$#"
count: 1
Expand Down Expand Up @@ -125,6 +130,11 @@ parameters:
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:appendGlobalMiddlewares\\(\\) should return list\\<class\\-string\\|object\\> but returns array\\.$#"
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:attributes\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
16 changes: 8 additions & 8 deletions src/GraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GraphQL
/** @var Container */
protected $app;

/** @var array<Schema> */
/** @var array<string,Schema> */
protected $schemas = [];

/**
Expand All @@ -54,7 +54,7 @@ class GraphQL
/**
* These middleware are executed before all resolve methods
*
* @var array<object|class-string>
* @var list<object|class-string>
*/
protected $globalResolverMiddlewares = [];

Expand Down Expand Up @@ -153,7 +153,7 @@ protected function executeAndReturnResult(string $schemaName, Schema $schema, Op
}

/**
* @param array<string> $middleware
* @param list<string> $middleware
* @param mixed $rootValue
* @param mixed $contextValue
*/
Expand All @@ -167,7 +167,7 @@ protected function executeViaMiddleware(array $middleware, string $schemaName, S
}

/**
* @return array<string>
* @return list<class-string>
*/
protected function executionMiddleware(string $schemaName): array
{
Expand All @@ -183,8 +183,8 @@ protected function executionMiddleware(string $schemaName): array
}

/**
* @phpstan-param array<class-string> $middlewares
* @phpstan-return array<class-string>
* @phpstan-param list<class-string> $middlewares
* @phpstan-return list<class-string>
*/
protected function appendGraphqlExecutionMiddleware(array $middlewares): array
{
Expand All @@ -202,7 +202,7 @@ public function appendGlobalResolverMiddleware(object|string $class): void
}

/**
* @phpstan-return array<object|class-string>
* @phpstan-return list<object|class-string>
*/
public function getGlobalResolverMiddlewares(): array
{
Expand Down Expand Up @@ -471,7 +471,7 @@ public function getTypes(): array
}

/**
* @return array<Schema>
* @return array<string,Schema>
*/
public function getSchemas(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Helpers
*
* Apply a callback to a value or each value in an array.
*
* @param mixed|array<mixed> $valueOrValues
* @return mixed|array<mixed>
* @param mixed|list<mixed> $valueOrValues
* @return mixed|list<mixed>
*/
public static function applyEach(Closure $callback, $valueOrValues)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Support/Contracts/ConfigConvertible.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ interface ConfigConvertible
{
/**
* @return array{
* execution_middleware?:array<class-string<AbstractExecutionMiddleware>>,
* execution_middleware?:list<class-string<AbstractExecutionMiddleware>>,
* method?:string|string[],
* middleware?:array<string|class-string>,
* mutation?:array<string,class-string>|array<class-string>,
* query:array<string,class-string>|array<class-string>,
* types?:array<string,class-string>|array<class-string>
* mutation?:array<string,class-string>|list<class-string>,
* query:array<string,class-string>|list<class-string>,
* types?:array<string,class-string>|list<class-string>
* }
*/
public function toConfig(): array;
Expand Down
8 changes: 4 additions & 4 deletions src/Support/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class Field
/** @var array<string,mixed> */
protected $attributes = [];

/** @var string[] */
/** @var list<class-string> */
protected $middleware = [];

/**
Expand Down Expand Up @@ -139,16 +139,16 @@ public function getValidator(array $args, array $rules): ValidatorContract
}

/**
* @return array<string>
* @return list<class-string>
*/
protected function getMiddleware(): array
{
return $this->middleware;
}

/**
* @return array<class-string|object>
* @phpstan-param array<string> $middleware
* @return list<class-string|object>
* @phpstan-param list<string> $middleware
*/
protected function appendGlobalMiddlewares(array $middleware): array
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/EmptyQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EmptyQueryTest extends TestCaseDatabase
{
/**
* @dataProvider dataForEmptyQuery
* @param array<mixed> $parameters
* @param list<mixed> $parameters
*/
public function testEmptyQuery(array $parameters, string $expectedError): void
{
Expand Down Expand Up @@ -132,7 +132,7 @@ static function (array $result): array {
}

/**
* @return array<mixed>
* @return list<mixed>
*/
public static function dataForEmptyQuery(): array
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/Objects/ExampleRuleTestingInputObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function fields(): array
/**
* @param mixed $root
* @param array<string,mixed> $args
* @return array<string>
* @return list<string>
*/
public function resolve($root, array $args): array
{
Expand Down

0 comments on commit 1f779a3

Please sign in to comment.