From 0d63d74cbba125410402659c54da294aff86301f Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 23 Aug 2018 08:34:49 +0200 Subject: [PATCH 01/12] Add phpstan PHP Static Analysis Tool --- .gitignore | 1 + .travis.yml | 8 +++++++- composer.json | 12 +++++++++--- phpstan.neon | 0 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 phpstan.neon diff --git a/.gitignore b/.gitignore index 4e3728b..321655a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.phar composer.lock vendor/ bin/ +phpstan.phar diff --git a/.travis.yml b/.travis.yml index d8ec128..c9bb7fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,13 @@ php: - 7.2 - nightly -matrix: +jobs: + include: + - stage: Code Quality + php: 7.2 + env: STATIC_ANALYSIS + install: travis_retry composer install --prefer-dist + script: composer static-analysis allow_failures: - php: nightly diff --git a/composer.json b/composer.json index d48b76a..54d19a6 100644 --- a/composer.json +++ b/composer.json @@ -18,9 +18,6 @@ }, "config": { "bin-dir": "bin", - "platform": { - "php": "5.6.0" - }, "preferred-install": "dist", "sort-packages": true }, @@ -36,6 +33,15 @@ "GraphQL\\Examples\\Blog\\": "examples/01-blog/Blog/" } }, + "scripts": { + "static-analysis": [ + "rm phpstan.phar || true", + "@composer req --ansi --no-interaction --dev phpstan/phpstan-shim", + "cp -f vendor/phpstan/phpstan-shim/phpstan.phar .", + "@composer rem --ansi --dev phpstan/phpstan-shim", + "@php phpstan.phar analyse --ansi -l 1 -c phpstan.neon src" + ] + }, "suggest": { "react/promise": "To leverage async resolving on React PHP platform", "psr/http-message": "To use standard GraphQL server" diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..e69de29 From fce0e4dd223b0cf746f2b16cca8c86831daa851f Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 23 Aug 2018 08:43:25 +0200 Subject: [PATCH 02/12] Use continue 2 instead of continue --- src/Executor/Executor.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 4460e20..e63a42a 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -560,7 +560,7 @@ class Executor switch ($selection->kind) { case NodeKind::FIELD: if (!$this->shouldIncludeNode($selection)) { - continue; + continue 2; } $name = self::getFieldEntryKey($selection); if (!isset($fields[$name])) { @@ -572,7 +572,7 @@ class Executor if (!$this->shouldIncludeNode($selection) || !$this->doesFragmentConditionMatch($selection, $runtimeType) ) { - continue; + continue 2; } $this->collectFields( $runtimeType, @@ -584,14 +584,14 @@ class Executor case NodeKind::FRAGMENT_SPREAD: $fragName = $selection->name->value; if (!empty($visitedFragmentNames[$fragName]) || !$this->shouldIncludeNode($selection)) { - continue; + continue 2; } $visitedFragmentNames[$fragName] = true; /** @var FragmentDefinitionNode|null $fragment */ $fragment = isset($exeContext->fragments[$fragName]) ? $exeContext->fragments[$fragName] : null; if (!$fragment || !$this->doesFragmentConditionMatch($fragment, $runtimeType)) { - continue; + continue 2; } $this->collectFields( $runtimeType, From 3da424dacf60d5fd14171499c4b111a0f1fe8c5c Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 23 Aug 2018 09:07:05 +0200 Subject: [PATCH 03/12] Fix dev deps --- .travis.yml | 5 +---- composer.json | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9bb7fc..299fe07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,10 +28,7 @@ before_install: - phpenv config-rm xdebug.ini || true - composer selfupdate -install: - - composer install --dev --prefer-dist - - composer require react/promise:2.* - - composer require psr/http-message:1.* +install: composer install --dev --prefer-dist script: if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then bin/phpunit --coverage-clover build/logs/clover.xml --group default,ReactPromise; else bin/phpunit --group default,ReactPromise; fi diff --git a/composer.json b/composer.json index 54d19a6..4178927 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ }, "require-dev": { "phpunit/phpunit": "^4.8", - "psr/http-message": "^1.0" + "psr/http-message": "^1.0", + "react/promise": "2.*" }, "config": { "bin-dir": "bin", From f7132eb34f43e124b6dd45a20bac6f96f531ccd8 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 23 Aug 2018 09:10:10 +0200 Subject: [PATCH 04/12] Add undefined property `$promises` --- src/Executor/ExecutionContext.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Executor/ExecutionContext.php b/src/Executor/ExecutionContext.php index f31a444..0a73b1b 100644 --- a/src/Executor/ExecutionContext.php +++ b/src/Executor/ExecutionContext.php @@ -2,6 +2,7 @@ namespace GraphQL\Executor; use GraphQL\Error\Error; +use GraphQL\Executor\Promise\PromiseAdapter; use GraphQL\Language\AST\FragmentDefinitionNode; use GraphQL\Language\AST\OperationDefinitionNode; use GraphQL\Type\Schema; @@ -56,6 +57,11 @@ class ExecutionContext */ public $errors; + /** + * @var PromiseAdapter + */ + public $promises; + public function __construct( $schema, $fragments, From 788581ad2458d445f57a5bb6c8c61e951e3f50b3 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 23 Aug 2018 09:11:17 +0200 Subject: [PATCH 05/12] Fix typehint --- src/Executor/Promise/Adapter/ReactPromiseAdapter.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Executor/Promise/Adapter/ReactPromiseAdapter.php b/src/Executor/Promise/Adapter/ReactPromiseAdapter.php index 747ed42..7f29ecc 100644 --- a/src/Executor/Promise/Adapter/ReactPromiseAdapter.php +++ b/src/Executor/Promise/Adapter/ReactPromiseAdapter.php @@ -5,7 +5,6 @@ use GraphQL\Executor\Promise\Promise; use GraphQL\Executor\Promise\PromiseAdapter; use GraphQL\Utils\Utils; use React\Promise\Promise as ReactPromise; -use React\Promise\PromiseInterface as ReactPromiseInterface; class ReactPromiseAdapter implements PromiseAdapter { @@ -14,7 +13,7 @@ class ReactPromiseAdapter implements PromiseAdapter */ public function isThenable($value) { - return $value instanceof ReactPromiseInterface; + return $value instanceof PromiseAdapter; } /** From 68f0be08cb5240121d470f87eabd2d494ed29dc1 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 23 Aug 2018 09:12:19 +0200 Subject: [PATCH 06/12] Fix variable $editValue might not be defined. --- src/Language/Visitor.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Language/Visitor.php b/src/Language/Visitor.php index ab20d1e..fda7540 100644 --- a/src/Language/Visitor.php +++ b/src/Language/Visitor.php @@ -6,15 +6,6 @@ use GraphQL\Language\AST\NodeKind; use GraphQL\Language\AST\NodeList; use GraphQL\Utils\TypeInfo; -class VisitorOperation -{ - public $doBreak; - - public $doContinue; - - public $removeNode; -} - /** * Utility for efficient AST traversal and modification. * @@ -258,6 +249,7 @@ class Visitor if ($visitFn) { $result = call_user_func($visitFn, $node, $key, $parent, $path, $ancestors); + $editValue = null; if ($result !== null) { if ($result instanceof VisitorOperation) { From 297bac0deaafa172104e15b7410389ce73ccc48c Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 23 Aug 2018 09:13:20 +0200 Subject: [PATCH 07/12] Extract VisitorOperation to be more psr-4 compliant --- src/Language/VisitorOperation.php | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/Language/VisitorOperation.php diff --git a/src/Language/VisitorOperation.php b/src/Language/VisitorOperation.php new file mode 100644 index 0000000..493073d --- /dev/null +++ b/src/Language/VisitorOperation.php @@ -0,0 +1,11 @@ + Date: Thu, 23 Aug 2018 09:14:23 +0200 Subject: [PATCH 08/12] Fix Utils fqcn --- src/Server/StandardServer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server/StandardServer.php b/src/Server/StandardServer.php index 9684205..2ea4480 100644 --- a/src/Server/StandardServer.php +++ b/src/Server/StandardServer.php @@ -5,7 +5,7 @@ use GraphQL\Error\FormattedError; use GraphQL\Error\InvariantViolation; use GraphQL\Executor\ExecutionResult; use GraphQL\Executor\Promise\Promise; -use GraphQL\Utils; +use GraphQL\Utils\Utils; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamInterface; From 19235f5a2d3796fd89a2e6d0952bcedb0373f9f5 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 23 Aug 2018 09:15:08 +0200 Subject: [PATCH 09/12] Add undefined variable complexityFn and fix typehint --- src/Type/Definition/FieldDefinition.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Type/Definition/FieldDefinition.php b/src/Type/Definition/FieldDefinition.php index 19199c3..a98dcd5 100644 --- a/src/Type/Definition/FieldDefinition.php +++ b/src/Type/Definition/FieldDefinition.php @@ -62,6 +62,11 @@ class FieldDefinition */ public $config; + /** + * @var null|callable + */ + public $complexityFn; + /** * @var OutputType */ @@ -108,7 +113,7 @@ class FieldDefinition } /** - * @param array|Config $field + * @param array $field * @param string $typeName * @return FieldDefinition */ From 4209a2f60e67332641f5f97eeae5d15d2d3697d1 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 23 Aug 2018 09:15:56 +0200 Subject: [PATCH 10/12] Fix typehint --- src/Type/Definition/InputObjectField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Type/Definition/InputObjectField.php b/src/Type/Definition/InputObjectField.php index 1744e51..68f2a32 100644 --- a/src/Type/Definition/InputObjectField.php +++ b/src/Type/Definition/InputObjectField.php @@ -24,7 +24,7 @@ class InputObjectField public $description; /** - * @var callback|InputType + * @var callable|InputType */ public $type; From 6996e2da2b381a5fc1339df236dfa208295c97a7 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 23 Aug 2018 09:16:08 +0200 Subject: [PATCH 11/12] Remove unused variables --- src/Validator/Rules/VariablesDefaultValueAllowed.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Validator/Rules/VariablesDefaultValueAllowed.php b/src/Validator/Rules/VariablesDefaultValueAllowed.php index fcbbef4..92e84d1 100644 --- a/src/Validator/Rules/VariablesDefaultValueAllowed.php +++ b/src/Validator/Rules/VariablesDefaultValueAllowed.php @@ -49,10 +49,10 @@ class VariablesDefaultValueAllowed extends AbstractValidationRule return Visitor::skipNode(); }, - NodeKind::SELECTION_SET => function(SelectionSetNode $node) use ($context) { + NodeKind::SELECTION_SET => function(SelectionSetNode $node) { return Visitor::skipNode(); }, - NodeKind::FRAGMENT_DEFINITION => function(FragmentDefinitionNode $node) use ($context) { + NodeKind::FRAGMENT_DEFINITION => function(FragmentDefinitionNode $node) { return Visitor::skipNode(); }, ]; From 761bcfb6f7e6c0a61a1a1a90d7771ac594c03c1d Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 23 Aug 2018 09:21:44 +0200 Subject: [PATCH 12/12] Fix ReactPromiseInterface --- src/Executor/Promise/Adapter/ReactPromiseAdapter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Executor/Promise/Adapter/ReactPromiseAdapter.php b/src/Executor/Promise/Adapter/ReactPromiseAdapter.php index 7f29ecc..747ed42 100644 --- a/src/Executor/Promise/Adapter/ReactPromiseAdapter.php +++ b/src/Executor/Promise/Adapter/ReactPromiseAdapter.php @@ -5,6 +5,7 @@ use GraphQL\Executor\Promise\Promise; use GraphQL\Executor\Promise\PromiseAdapter; use GraphQL\Utils\Utils; use React\Promise\Promise as ReactPromise; +use React\Promise\PromiseInterface as ReactPromiseInterface; class ReactPromiseAdapter implements PromiseAdapter { @@ -13,7 +14,7 @@ class ReactPromiseAdapter implements PromiseAdapter */ public function isThenable($value) { - return $value instanceof PromiseAdapter; + return $value instanceof ReactPromiseInterface; } /**