Skip to content

Commit

Permalink
Merge pull request #1129 from rebing/mfn-misc-changes
Browse files Browse the repository at this point in the history
phpstan: misc smaller improvements
  • Loading branch information
mfn authored Mar 4, 2024
2 parents 91735a9 + 4334aee commit 66078d3
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

- run: composer update --prefer-dist --no-progress

- run: composer phpstan -- --no-progress
- run: composer phpstan -- --no-progress --error-format=table

code-style-checker:
name: Code Style checker
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
}
},
"scripts": {
"phpstan": "phpstan analyse --memory-limit=512M",
"phpstan": "phpstan analyse --memory-limit=512M --error-format=raw",
"phpstan-baseline": "phpstan analyse --memory-limit=512M --generate-baseline",
"lint": "php-cs-fixer fix --diff --dry-run",
"fix-style": "php-cs-fixer fix",
Expand Down
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
20 changes: 12 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 All @@ -72,6 +72,7 @@ public function __construct(Container $app, Repository $config)

public function schema(?string $schemaName = null): Schema
{
/** @var string $schemaName */
$schemaName = $schemaName ?? $this->config->get('graphql.default_schema', 'default');

if (isset($this->schemas[$schemaName])) {
Expand Down Expand Up @@ -108,6 +109,7 @@ public function query(string $query, ?array $variables = null, array $opts = [])
public function queryAndReturnResult(string $query, ?array $variables = null, array $opts = []): ExecutionResult
{
$context = $opts['context'] ?? null;
/** @var string $schemaName */
$schemaName = $opts['schema'] ?? $this->config->get('graphql.default_schema', 'default');
$operationName = $opts['operationName'] ?? null;
$rootValue = $opts['rootValue'] ?? null;
Expand Down Expand Up @@ -153,12 +155,13 @@ protected function executeAndReturnResult(string $schemaName, Schema $schema, Op
}

/**
* @param array<string> $middleware
* @param list<string> $middleware
* @param mixed $rootValue
* @param mixed $contextValue
*/
protected function executeViaMiddleware(array $middleware, string $schemaName, Schema $schema, OperationParams $params, $rootValue = null, $contextValue = null): ExecutionResult
{
/** @var ExecutionResult */
return $this->app->make(Pipeline::class)
->send([$schemaName, $schema, $params, $rootValue, $contextValue])
->through($middleware)
Expand All @@ -167,7 +170,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 +186,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 +205,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 @@ -385,6 +388,7 @@ public function buildSchemaFromConfig(array $schemaConfig): Schema
$schemaQuery = $schemaConfig['query'] ?? [];
$schemaMutation = $schemaConfig['mutation'] ?? [];
$schemaSubscription = $schemaConfig['subscription'] ?? [];
/** @var array<int|string,string> $schemaTypes */
$schemaTypes = $schemaConfig['types'] ?? [];
$schemaDirectives = $schemaConfig['directives'] ?? [];

Expand Down Expand Up @@ -471,7 +475,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 66078d3

Please sign in to comment.