From 63c13d981cb2ae74d2e9e1ff6089087951542068 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Thu, 3 Nov 2022 23:45:28 +0100 Subject: [PATCH 1/3] chore: remove psalm --- .gitattributes | 2 - .github/workflows/static-analysis.yml | 26 ------------- .gitignore | 1 - README.md | 1 - composer.json | 7 +--- psalm-baseline.xml | 54 --------------------------- psalm.xml.dist | 20 ---------- src/Error/Warning.php | 4 -- src/Executor/ExecutionResult.php | 4 -- src/Executor/Executor.php | 9 ----- 10 files changed, 2 insertions(+), 126 deletions(-) delete mode 100644 psalm-baseline.xml delete mode 100644 psalm.xml.dist diff --git a/.gitattributes b/.gitattributes index 0548dcc7d..487b6436d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16,6 +16,4 @@ phpbench.json export-ignore phpstan.neon.dist export-ignore phpstan-baseline.neon export-ignore phpunit.xml.dist export-ignore -psalm.xml.dist export-ignore -psalm-baseline.xml export-ignore renovate.json export-ignore diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 516313797..76addd05d 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -34,29 +34,3 @@ jobs: - name: Run a static analysis with phpstan/phpstan run: vendor/bin/phpstan --error-format=checkstyle | cs2pr - - static-analysis-psalm: - name: Static Analysis with Psalm - runs-on: ubuntu-20.04 - - strategy: - matrix: - php-version: - - 8.1 - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - coverage: none - php-version: ${{ matrix.php-version }} - tools: cs2pr - - - name: Install dependencies with Composer - uses: ramsey/composer-install@v2 - - - name: Run a static analysis with vimeo/psalm - run: vendor/bin/psalm --output-format=github --shepherd diff --git a/.gitignore b/.gitignore index 2fd04c601..c40e29c47 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,5 @@ composer.lock composer.phar phpstan.neon -psalm.xml vendor .idea diff --git a/README.md b/README.md index f0f33155e..2a8485121 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ [![CI](https://github.com/webonyx/graphql-php/workflows/CI/badge.svg)](https://github.com/webonyx/graphql-php/actions?query=workflow:CI+branch:master) [![Coverage Status](https://codecov.io/gh/webonyx/graphql-php/branch/master/graph/badge.svg)](https://codecov.io/gh/webonyx/graphql-php/branch/master) [![Latest Stable Version](https://poser.pugx.org/webonyx/graphql-php/version)](https://packagist.org/packages/webonyx/graphql-php) -[![Shepherd Type](https://shepherd.dev/github/webonyx/graphql-php/coverage.svg)](ttps://shepherd.dev/github/webonyx/graphql-php) This is a PHP implementation of the GraphQL [specification](https://github.com/graphql/graphql-spec) based on the [reference implementation in JavaScript](https://github.com/graphql/graphql-js). diff --git a/composer.json b/composer.json index 05090ccc4..5d4e0748c 100644 --- a/composer.json +++ b/composer.json @@ -25,13 +25,11 @@ "phpstan/phpstan-phpunit": "1.2.2", "phpstan/phpstan-strict-rules": "1.4.4", "phpunit/phpunit": "^9.5", - "psalm/plugin-phpunit": "^0.17", "psr/http-message": "^1", "react/promise": "^2", "symfony/polyfill-php81": "^1.23", "symfony/var-exporter": "^5 || ^6", - "thecodingmachine/safe": "^1.3", - "vimeo/psalm": "^4.19" + "thecodingmachine/safe": "^1.3" }, "suggest": { "psr/http-message": "To use standard GraphQL server", @@ -59,12 +57,11 @@ "sort-packages": true }, "scripts": { - "baseline": "phpstan --generate-baseline && psalm --set-baseline", "bench": "phpbench run", "check": "composer fix && composer stan && composer test", "docs": "php generate-class-reference.php", "fix": "php-cs-fixer fix", - "stan": "phpstan && psalm", + "stan": "phpstan", "test": "phpunit" } } diff --git a/psalm-baseline.xml b/psalm-baseline.xml deleted file mode 100644 index ececdb61f..000000000 --- a/psalm-baseline.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - ParserOptions - - - ParserOptions from Parser - - - - - ParserOptions - ParserOptions - ParserOptions - ParserOptions - array{string, ParserOptions} - - - - - $path[count($path) - 1] - - - - - $this->config - ComplexityFn|null - FieldDefinitionConfig - FieldsConfig - array - - - - - FieldsConfig from FieldDefinition - - - - - UnnamedFieldDefinitionConfig from FieldDefinition - - - - - UnnamedFieldDefinitionConfig from FieldDefinition - - - - - UnnamedFieldDefinitionConfig from FieldDefinition - - - diff --git a/psalm.xml.dist b/psalm.xml.dist deleted file mode 100644 index 5c628e865..000000000 --- a/psalm.xml.dist +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/Error/Warning.php b/src/Error/Warning.php index 87681cbc9..14902fde8 100644 --- a/src/Error/Warning.php +++ b/src/Error/Warning.php @@ -11,10 +11,6 @@ * Also, it is possible to override warning handler (which is **trigger_error()** by default). * * @phpstan-type WarningHandler callable(string $errorMessage, int $warningId, ?int $messageLevel): void - * - * @see https://github.com/vimeo/psalm/issues/7527 - * - * @psalm-type WarningHandler callable(string, int, int|null): void */ final class Warning { diff --git a/src/Executor/ExecutionResult.php b/src/Executor/ExecutionResult.php index 7c26ea531..387a686d0 100644 --- a/src/Executor/ExecutionResult.php +++ b/src/Executor/ExecutionResult.php @@ -34,10 +34,6 @@ * } * @phpstan-type ErrorFormatter callable(Throwable): SerializableError * @phpstan-type ErrorsHandler callable(array $errors, ErrorFormatter $formatter): SerializableErrors - * - * @see https://github.com/vimeo/psalm/issues/6928 - * - * @psalm-type ErrorsHandler callable(Error[], ErrorFormatter): SerializableErrors */ class ExecutionResult implements \JsonSerializable { diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 664e9b05b..88c132d2a 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -14,16 +14,7 @@ * Implements the "Evaluating requests" section of the GraphQL specification. * * @phpstan-type FieldResolver callable(mixed, array, mixed, ResolveInfo): mixed - * - * @see https://github.com/vimeo/psalm/issues/6928 - * - * @psalm-type FieldResolver callable(mixed, array, mixed, ResolveInfo): mixed - * * @phpstan-type ImplementationFactory callable(PromiseAdapter, Schema, DocumentNode, mixed, mixed, array, ?string, callable): ExecutorImplementation - * - * @see https://github.com/vimeo/psalm/issues/6928, https://github.com/vimeo/psalm/issues/7527 - * - * @psalm-type ImplementationFactory callable(PromiseAdapter, Schema, DocumentNode, mixed, mixed, array, ?string, callable): ExecutorImplementation */ class Executor { From b1fa874471b03ab3f4d2d55a37eef5b94dd80fb4 Mon Sep 17 00:00:00 2001 From: simPod Date: Fri, 4 Nov 2022 09:09:00 +0000 Subject: [PATCH 2/3] Update class reference --- docs/class-reference.md | 174 ++++++++++++++++++---------------------- 1 file changed, 79 insertions(+), 95 deletions(-) diff --git a/docs/class-reference.md b/docs/class-reference.md index 6f1b9c6e5..78c588a5a 100644 --- a/docs/class-reference.md +++ b/docs/class-reference.md @@ -512,15 +512,15 @@ Usage example: @phpstan-type TypeLoader callable(string $typeName): ((Type&NamedType)|null) @phpstan-type Types iterable|(callable(): iterable) @phpstan-type SchemaConfigOptions array{ -query?: ObjectType|null, -mutation?: ObjectType|null, -subscription?: ObjectType|null, -types?: Types|null, -directives?: array|null, -typeLoader?: TypeLoader|null, -assumeValid?: bool|null, -astNode?: SchemaDefinitionNode|null, -extensionASTNodes?: array|null, + query?: ObjectType|null, + mutation?: ObjectType|null, + subscription?: ObjectType|null, + types?: Types|null, + directives?: array|null, + typeLoader?: TypeLoader|null, + assumeValid?: bool|null, + astNode?: SchemaDefinitionNode|null, + extensionASTNodes?: array|null, } ### GraphQL\Type\SchemaConfig Methods @@ -827,46 +827,46 @@ function validate(): array Parses string containing GraphQL query language or [schema definition language](schema-definition-language.md) to Abstract Syntax Tree. @phpstan-type ParserOptions array{ -noLocation?: bool, -allowLegacySDLEmptyFields?: bool, -allowLegacySDLImplementsInterfaces?: bool, -experimentalFragmentVariables?: bool + noLocation?: bool, + allowLegacySDLEmptyFields?: bool, + allowLegacySDLImplementsInterfaces?: bool, + experimentalFragmentVariables?: bool } noLocation: -(By default, the parser creates AST nodes that know the location -in the source that they correspond to. This configuration flag -disables that behavior for performance or testing.) + (By default, the parser creates AST nodes that know the location + in the source that they correspond to. This configuration flag + disables that behavior for performance or testing.) allowLegacySDLEmptyFields: -If enabled, the parser will parse empty fields sets in the Schema -Definition Language. Otherwise, the parser will follow the current -specification. + If enabled, the parser will parse empty fields sets in the Schema + Definition Language. Otherwise, the parser will follow the current + specification. -This option is provided to ease adoption of the final SDL specification -and will be removed in a future major release. + This option is provided to ease adoption of the final SDL specification + and will be removed in a future major release. allowLegacySDLImplementsInterfaces: -If enabled, the parser will parse implemented interfaces with no `&` -character between each interface. Otherwise, the parser will follow the -current specification. + If enabled, the parser will parse implemented interfaces with no `&` + character between each interface. Otherwise, the parser will follow the + current specification. -This option is provided to ease adoption of the final SDL specification -and will be removed in a future major release. + This option is provided to ease adoption of the final SDL specification + and will be removed in a future major release. experimentalFragmentVariables: -(If enabled, the parser will understand and parse variable definitions -contained in a fragment definition. They'll be represented in the -`variableDefinitions` field of the FragmentDefinitionNode. + (If enabled, the parser will understand and parse variable definitions + contained in a fragment definition. They'll be represented in the + `variableDefinitions` field of the FragmentDefinitionNode. -The syntax is identical to normal, query-defined variables. For example: + The syntax is identical to normal, query-defined variables. For example: fragment A($var: Boolean = false) on T { ... } -Note: this feature is experimental and may change or be removed in the -future.) + Note: this feature is experimental and may change or be removed in the + future.) Those magic functions allow partial parsing: @method static NameNode name(Source|string $source, bool[] $options = []) @@ -1067,51 +1067,51 @@ visitor API: 1. Named visitors triggered when entering a node a specific kind. - Visitor::visit($ast, [ + Visitor::visit($ast, [ 'Kind' => function ($node) { - // enter the "Kind" node - } - ]); + // enter the "Kind" node + } + ]); 2. Named visitors that trigger upon entering and leaving a node of a specific kind. - Visitor::visit($ast, [ + Visitor::visit($ast, [ 'Kind' => [ 'enter' => function ($node) { - // enter the "Kind" node - } - 'leave' => function ($node) { - // leave the "Kind" node - } - ] - ]); + // enter the "Kind" node + } + 'leave' => function ($node) { + // leave the "Kind" node + } + ] + ]); 3. Generic visitors that trigger upon entering and leaving any node. - Visitor::visit($ast, [ + Visitor::visit($ast, [ 'enter' => function ($node) { - // enter any node - }, - 'leave' => function ($node) { - // leave any node - } - ]); + // enter any node + }, + 'leave' => function ($node) { + // leave any node + } + ]); 4. Parallel visitors for entering and leaving nodes of a specific kind. - Visitor::visit($ast, [ + Visitor::visit($ast, [ 'enter' => [ 'Kind' => function($node) { - // enter the "Kind" node - } - }, - 'leave' => [ - 'Kind' => function ($node) { - // leave the "Kind" node - } - ] - ]); + // enter the "Kind" node + } + }, + 'leave' => [ + 'Kind' => function ($node) { + // leave the "Kind" node + } + ] + ]); @phpstan-type VisitorArray array|array> @@ -1264,17 +1264,8 @@ const CLASS_MAP = [ Implements the "Evaluating requests" section of the GraphQL specification. @phpstan-type FieldResolver callable(mixed, array, mixed, ResolveInfo): mixed - -@see https://github.com/vimeo/psalm/issues/6928 - -@psalm-type FieldResolver callable(mixed, array, mixed, ResolveInfo): mixed - @phpstan-type ImplementationFactory callable(PromiseAdapter, Schema, DocumentNode, mixed, mixed, array, ?string, callable): ExecutorImplementation -@see https://github.com/vimeo/psalm/issues/6928, https://github.com/vimeo/psalm/issues/7527 - -@psalm-type ImplementationFactory callable(PromiseAdapter, Schema, DocumentNode, mixed, mixed, array, ?string, callable): ExecutorImplementation - ### GraphQL\Executor\Executor Methods ```php @@ -1342,24 +1333,20 @@ serializable array using `toArray()`. @see Throwable @phpstan-type SerializableError array{ -message: string, -locations?: array, -path?: array, -extensions?: array + message: string, + locations?: array, + path?: array, + extensions?: array } @phpstan-type SerializableErrors array @phpstan-type SerializableResult array{ -data?: array, -errors?: SerializableErrors, -extensions?: array + data?: array, + errors?: SerializableErrors, + extensions?: array } @phpstan-type ErrorFormatter callable(Throwable): SerializableError @phpstan-type ErrorsHandler callable(array $errors, ErrorFormatter $formatter): SerializableErrors -@see https://github.com/vimeo/psalm/issues/6928 - -@psalm-type ErrorsHandler callable(Error[], ErrorFormatter): SerializableErrors - ### GraphQL\Executor\ExecutionResult Props ```php @@ -1676,10 +1663,6 @@ Also, it is possible to override warning handler (which is **trigger_error()** b @phpstan-type WarningHandler callable(string $errorMessage, int $warningId, ?int $messageLevel): void -@see https://github.com/vimeo/psalm/issues/7527 - -@psalm-type WarningHandler callable(string, int, int|null): void - ### GraphQL\Error\Warning Constants ```php @@ -2297,21 +2280,21 @@ See [schema definition language docs](schema-definition-language.md) for details @phpstan-import-type TypeConfigDecorator from ASTDefinitionBuilder @phpstan-type BuildSchemaOptions array{ -assumeValid?: bool, -assumeValidSDL?: bool + assumeValid?: bool, + assumeValidSDL?: bool } - assumeValid: - When building a schema from a GraphQL service's introspection result, it - might be safe to assume the schema is valid. Set to true to assume the - produced schema is valid. + When building a schema from a GraphQL service's introspection result, it + might be safe to assume the schema is valid. Set to true to assume the + produced schema is valid. - Default: false + Default: false - assumeValidSDL: - Set to true to assume the SDL is valid. + Set to true to assume the SDL is valid. - Default: false + Default: false ### GraphQL\Utils\BuildSchema Methods @@ -2365,7 +2348,7 @@ Various utilities dealing with AST. ### GraphQL\Utils\AST Methods -````php +```php /** * Convert representation of AST as an associative array to instance of GraphQL\Language\AST\Node. * @@ -2392,7 +2375,7 @@ Various utilities dealing with AST. * @api */ static function fromArray(array $node): GraphQL\Language\AST\Node -```` +``` ```php /** @@ -2565,3 +2548,4 @@ static function doPrint(GraphQL\Type\Schema $schema, array $options = []): strin */ static function printIntrospectionSchema(GraphQL\Type\Schema $schema, array $options = []): string ``` + From 2839640ecbeec296ad06932abad0bf6b21ce2bed Mon Sep 17 00:00:00 2001 From: simPod Date: Fri, 4 Nov 2022 09:09:21 +0000 Subject: [PATCH 3/3] Prettify docs --- docs/class-reference.md | 157 ++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 79 deletions(-) diff --git a/docs/class-reference.md b/docs/class-reference.md index 78c588a5a..8e9232b55 100644 --- a/docs/class-reference.md +++ b/docs/class-reference.md @@ -512,15 +512,15 @@ Usage example: @phpstan-type TypeLoader callable(string $typeName): ((Type&NamedType)|null) @phpstan-type Types iterable|(callable(): iterable) @phpstan-type SchemaConfigOptions array{ - query?: ObjectType|null, - mutation?: ObjectType|null, - subscription?: ObjectType|null, - types?: Types|null, - directives?: array|null, - typeLoader?: TypeLoader|null, - assumeValid?: bool|null, - astNode?: SchemaDefinitionNode|null, - extensionASTNodes?: array|null, +query?: ObjectType|null, +mutation?: ObjectType|null, +subscription?: ObjectType|null, +types?: Types|null, +directives?: array|null, +typeLoader?: TypeLoader|null, +assumeValid?: bool|null, +astNode?: SchemaDefinitionNode|null, +extensionASTNodes?: array|null, } ### GraphQL\Type\SchemaConfig Methods @@ -827,46 +827,46 @@ function validate(): array Parses string containing GraphQL query language or [schema definition language](schema-definition-language.md) to Abstract Syntax Tree. @phpstan-type ParserOptions array{ - noLocation?: bool, - allowLegacySDLEmptyFields?: bool, - allowLegacySDLImplementsInterfaces?: bool, - experimentalFragmentVariables?: bool +noLocation?: bool, +allowLegacySDLEmptyFields?: bool, +allowLegacySDLImplementsInterfaces?: bool, +experimentalFragmentVariables?: bool } noLocation: - (By default, the parser creates AST nodes that know the location - in the source that they correspond to. This configuration flag - disables that behavior for performance or testing.) +(By default, the parser creates AST nodes that know the location +in the source that they correspond to. This configuration flag +disables that behavior for performance or testing.) allowLegacySDLEmptyFields: - If enabled, the parser will parse empty fields sets in the Schema - Definition Language. Otherwise, the parser will follow the current - specification. +If enabled, the parser will parse empty fields sets in the Schema +Definition Language. Otherwise, the parser will follow the current +specification. - This option is provided to ease adoption of the final SDL specification - and will be removed in a future major release. +This option is provided to ease adoption of the final SDL specification +and will be removed in a future major release. allowLegacySDLImplementsInterfaces: - If enabled, the parser will parse implemented interfaces with no `&` - character between each interface. Otherwise, the parser will follow the - current specification. +If enabled, the parser will parse implemented interfaces with no `&` +character between each interface. Otherwise, the parser will follow the +current specification. - This option is provided to ease adoption of the final SDL specification - and will be removed in a future major release. +This option is provided to ease adoption of the final SDL specification +and will be removed in a future major release. experimentalFragmentVariables: - (If enabled, the parser will understand and parse variable definitions - contained in a fragment definition. They'll be represented in the - `variableDefinitions` field of the FragmentDefinitionNode. +(If enabled, the parser will understand and parse variable definitions +contained in a fragment definition. They'll be represented in the +`variableDefinitions` field of the FragmentDefinitionNode. - The syntax is identical to normal, query-defined variables. For example: +The syntax is identical to normal, query-defined variables. For example: fragment A($var: Boolean = false) on T { ... } - Note: this feature is experimental and may change or be removed in the - future.) +Note: this feature is experimental and may change or be removed in the +future.) Those magic functions allow partial parsing: @method static NameNode name(Source|string $source, bool[] $options = []) @@ -1067,51 +1067,51 @@ visitor API: 1. Named visitors triggered when entering a node a specific kind. - Visitor::visit($ast, [ + Visitor::visit($ast, [ 'Kind' => function ($node) { - // enter the "Kind" node - } - ]); + // enter the "Kind" node + } + ]); 2. Named visitors that trigger upon entering and leaving a node of a specific kind. - Visitor::visit($ast, [ + Visitor::visit($ast, [ 'Kind' => [ 'enter' => function ($node) { - // enter the "Kind" node - } - 'leave' => function ($node) { - // leave the "Kind" node - } - ] - ]); + // enter the "Kind" node + } + 'leave' => function ($node) { + // leave the "Kind" node + } + ] + ]); 3. Generic visitors that trigger upon entering and leaving any node. - Visitor::visit($ast, [ + Visitor::visit($ast, [ 'enter' => function ($node) { - // enter any node - }, - 'leave' => function ($node) { - // leave any node - } - ]); + // enter any node + }, + 'leave' => function ($node) { + // leave any node + } + ]); 4. Parallel visitors for entering and leaving nodes of a specific kind. - Visitor::visit($ast, [ + Visitor::visit($ast, [ 'enter' => [ 'Kind' => function($node) { - // enter the "Kind" node - } - }, - 'leave' => [ - 'Kind' => function ($node) { - // leave the "Kind" node - } - ] - ]); + // enter the "Kind" node + } + }, + 'leave' => [ + 'Kind' => function ($node) { + // leave the "Kind" node + } + ] + ]); @phpstan-type VisitorArray array|array> @@ -1333,16 +1333,16 @@ serializable array using `toArray()`. @see Throwable @phpstan-type SerializableError array{ - message: string, - locations?: array, - path?: array, - extensions?: array +message: string, +locations?: array, +path?: array, +extensions?: array } @phpstan-type SerializableErrors array @phpstan-type SerializableResult array{ - data?: array, - errors?: SerializableErrors, - extensions?: array +data?: array, +errors?: SerializableErrors, +extensions?: array } @phpstan-type ErrorFormatter callable(Throwable): SerializableError @phpstan-type ErrorsHandler callable(array $errors, ErrorFormatter $formatter): SerializableErrors @@ -2280,21 +2280,21 @@ See [schema definition language docs](schema-definition-language.md) for details @phpstan-import-type TypeConfigDecorator from ASTDefinitionBuilder @phpstan-type BuildSchemaOptions array{ - assumeValid?: bool, - assumeValidSDL?: bool +assumeValid?: bool, +assumeValidSDL?: bool } - assumeValid: - When building a schema from a GraphQL service's introspection result, it - might be safe to assume the schema is valid. Set to true to assume the - produced schema is valid. + When building a schema from a GraphQL service's introspection result, it + might be safe to assume the schema is valid. Set to true to assume the + produced schema is valid. - Default: false + Default: false - assumeValidSDL: - Set to true to assume the SDL is valid. + Set to true to assume the SDL is valid. - Default: false + Default: false ### GraphQL\Utils\BuildSchema Methods @@ -2348,7 +2348,7 @@ Various utilities dealing with AST. ### GraphQL\Utils\AST Methods -```php +````php /** * Convert representation of AST as an associative array to instance of GraphQL\Language\AST\Node. * @@ -2375,7 +2375,7 @@ Various utilities dealing with AST. * @api */ static function fromArray(array $node): GraphQL\Language\AST\Node -``` +```` ```php /** @@ -2548,4 +2548,3 @@ static function doPrint(GraphQL\Type\Schema $schema, array $options = []): strin */ static function printIntrospectionSchema(GraphQL\Type\Schema $schema, array $options = []): string ``` -