diff --git a/composer.json b/composer.json index 27a3dac..7ace361 100644 --- a/composer.json +++ b/composer.json @@ -16,9 +16,9 @@ "require-dev": { "doctrine/coding-standard": "^5.0", "phpbench/phpbench": "^0.14.0", - "phpstan/phpstan": "0.10.5", - "phpstan/phpstan-phpunit": "0.10.0", - "phpstan/phpstan-strict-rules": "0.10.1", + "phpstan/phpstan": "^0.11.4", + "phpstan/phpstan-phpunit": "^0.11.0", + "phpstan/phpstan-strict-rules": "^0.11.0", "phpunit/phpcov": "^5.0", "phpunit/phpunit": "^7.2", "psr/http-message": "^1.0", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index af2455b..02a7a9a 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -8,6 +8,8 @@ parameters: ignoreErrors: - "~Construct empty\\(\\) is not allowed\\. Use more strict comparison~" - "~(Method|Property) .+::.+(\\(\\))? (has parameter \\$\\w+ with no|has no return|has no) typehint specified~" + - "~Variable property access on .+~" + - "~Variable method call on static\\(GraphQL\\\\Server\\\\ServerConfig\\)~" # TODO get rid of includes: - vendor/phpstan/phpstan-phpunit/extension.neon diff --git a/src/Error/Warning.php b/src/Error/Warning.php index a652968..9157b05 100644 --- a/src/Error/Warning.php +++ b/src/Error/Warning.php @@ -61,8 +61,6 @@ final class Warning } elseif ($suppress === false) { self::$enableWarnings = self::ALL; } else { - $suppress = (int) $suppress; - self::$enableWarnings &= ~$suppress; } } @@ -86,8 +84,6 @@ final class Warning } elseif ($enable === false) { self::$enableWarnings = 0; } else { - $enable = (int) $enable; - self::$enableWarnings |= $enable; } } diff --git a/src/Executor/ExecutionResult.php b/src/Executor/ExecutionResult.php index e9dbe4e..db16dd3 100644 --- a/src/Executor/ExecutionResult.php +++ b/src/Executor/ExecutionResult.php @@ -154,7 +154,7 @@ class ExecutionResult implements JsonSerializable } if (! empty($this->extensions)) { - $result['extensions'] = (array) $this->extensions; + $result['extensions'] = $this->extensions; } return $result; diff --git a/src/Server/OperationParams.php b/src/Server/OperationParams.php index 6d2cfd1..3ab12de 100644 --- a/src/Server/OperationParams.php +++ b/src/Server/OperationParams.php @@ -62,13 +62,10 @@ class OperationParams * Creates an instance from given array * * @param mixed[] $params - * @param bool $readonly - * - * @return OperationParams * * @api */ - public static function create(array $params, $readonly = false) + public static function create(array $params, bool $readonly = false) : OperationParams { $instance = new static(); @@ -108,7 +105,7 @@ class OperationParams $instance->operation = $params['operationname']; $instance->variables = $params['variables']; $instance->extensions = $params['extensions']; - $instance->readOnly = (bool) $readonly; + $instance->readOnly = $readonly; // Apollo server/client compatibility: look for the queryid in extensions if (isset($instance->extensions['persistedQuery']['sha256Hash']) && empty($instance->query) && empty($instance->queryId)) { diff --git a/src/Server/ServerConfig.php b/src/Server/ServerConfig.php index d121ec5..cb36ceb 100644 --- a/src/Server/ServerConfig.php +++ b/src/Server/ServerConfig.php @@ -225,15 +225,11 @@ class ServerConfig /** * Allow batching queries (disabled by default) * - * @param bool $enableBatching - * - * @return self - * * @api */ - public function setQueryBatching($enableBatching) + public function setQueryBatching(bool $enableBatching) : self { - $this->queryBatching = (bool) $enableBatching; + $this->queryBatching = $enableBatching; return $this; } diff --git a/src/Type/Definition/BooleanType.php b/src/Type/Definition/BooleanType.php index 1c24a53..67b8178 100644 --- a/src/Type/Definition/BooleanType.php +++ b/src/Type/Definition/BooleanType.php @@ -58,11 +58,11 @@ class BooleanType extends ScalarType */ public function parseLiteral($valueNode, ?array $variables = null) { - if ($valueNode instanceof BooleanValueNode) { - return (bool) $valueNode->value; + if (! $valueNode instanceof BooleanValueNode) { + // Intentionally without message, as all information already in wrapped Exception + throw new Exception(); } - // Intentionally without message, as all information already in wrapped Exception - throw new Exception(); + return $valueNode->value; } } diff --git a/src/Type/Definition/Directive.php b/src/Type/Definition/Directive.php index ab7d5d5..9baa7ff 100644 --- a/src/Type/Definition/Directive.php +++ b/src/Type/Definition/Directive.php @@ -40,7 +40,7 @@ class Directive public $locations; /** @var FieldArgument[] */ - public $args; + public $args = []; /** @var DirectiveDefinitionNode|null */ public $astNode; diff --git a/src/Type/Definition/ListOfType.php b/src/Type/Definition/ListOfType.php index 29e3438..e45bc14 100644 --- a/src/Type/Definition/ListOfType.php +++ b/src/Type/Definition/ListOfType.php @@ -20,15 +20,9 @@ class ListOfType extends Type implements WrappingType, OutputType, NullableType, $this->ofType = Type::assertType($type); } - /** - * @return string - */ - public function toString() + public function toString() : string { - $type = $this->ofType; - $str = $type instanceof Type ? $type->toString() : (string) $type; - - return '[' . $str . ']'; + return '[' . $this->ofType->toString() . ']'; } /** diff --git a/src/Utils/BreakingChangesFinder.php b/src/Utils/BreakingChangesFinder.php index 93736b6..533abf6 100644 --- a/src/Utils/BreakingChangesFinder.php +++ b/src/Utils/BreakingChangesFinder.php @@ -531,12 +531,12 @@ class BreakingChangesFinder ]; } // Check if a non-null arg was added to the field - foreach ($newTypeFields[$fieldName]->args as $newArgDef) { + foreach ($newTypeFields[$fieldName]->args as $newTypeFieldArgDef) { $oldArgs = $oldTypeFields[$fieldName]->args; $oldArgDef = Utils::find( $oldArgs, - static function ($arg) use ($newArgDef) { - return $arg->name === $newArgDef->name; + static function ($arg) use ($newTypeFieldArgDef) { + return $arg->name === $newTypeFieldArgDef->name; } ); @@ -545,8 +545,8 @@ class BreakingChangesFinder } $newTypeName = $newType->name; - $newArgName = $newArgDef->name; - if ($newArgDef->getType() instanceof NonNull) { + $newArgName = $newTypeFieldArgDef->name; + if ($newTypeFieldArgDef->getType() instanceof NonNull) { $breakingChanges[] = [ 'type' => self::BREAKING_CHANGE_NON_NULL_ARG_ADDED, 'description' => "A non-null arg ${newArgName} on ${newTypeName}.${fieldName} was added", @@ -668,7 +668,7 @@ class BreakingChangesFinder { $removedArgs = []; $newArgMap = self::getArgumentMapForDirective($newDirective); - foreach ((array) $oldDirective->args as $arg) { + foreach ($oldDirective->args as $arg) { if (isset($newArgMap[$arg->name])) { continue; } @@ -727,7 +727,7 @@ class BreakingChangesFinder { $addedArgs = []; $oldArgMap = self::getArgumentMapForDirective($oldDirective); - foreach ((array) $newDirective->args as $arg) { + foreach ($newDirective->args as $arg) { if (isset($oldArgMap[$arg->name])) { continue; } diff --git a/src/Utils/TypeInfo.php b/src/Utils/TypeInfo.php index b187511..63c3f4a 100644 --- a/src/Utils/TypeInfo.php +++ b/src/Utils/TypeInfo.php @@ -178,7 +178,7 @@ class TypeInfo $nestedTypes = array_merge($nestedTypes, $type->getInterfaces()); } if ($type instanceof ObjectType || $type instanceof InterfaceType) { - foreach ((array) $type->getFields() as $fieldName => $field) { + foreach ($type->getFields() as $fieldName => $field) { if (! empty($field->args)) { $fieldArgTypes = array_map( static function (FieldArgument $arg) { @@ -193,12 +193,12 @@ class TypeInfo } } if ($type instanceof InputObjectType) { - foreach ((array) $type->getFields() as $fieldName => $field) { + foreach ($type->getFields() as $fieldName => $field) { $nestedTypes[] = $field->getType(); } } - foreach ($nestedTypes as $type) { - $typeMap = self::extractTypes($type, $typeMap); + foreach ($nestedTypes as $nestedType) { + $typeMap = self::extractTypes($nestedType, $typeMap); } return $typeMap; diff --git a/src/Utils/Utils.php b/src/Utils/Utils.php index a1a983d..8dddd65 100644 --- a/src/Utils/Utils.php +++ b/src/Utils/Utils.php @@ -264,8 +264,8 @@ class Utils $grouped = []; foreach ($traversable as $key => $value) { $newKeys = (array) $keyFn($value, $key); - foreach ($newKeys as $key) { - $grouped[$key][] = $value; + foreach ($newKeys as $newKey) { + $grouped[$newKey][] = $value; } } diff --git a/src/Validator/Rules/QueryDepth.php b/src/Validator/Rules/QueryDepth.php index 5a35f0c..2f5c9c8 100644 --- a/src/Validator/Rules/QueryDepth.php +++ b/src/Validator/Rules/QueryDepth.php @@ -98,14 +98,12 @@ class QueryDepth extends QuerySecurityRule /** * Set max query depth. If equal to 0 no check is done. Must be greater or equal to 0. - * - * @param int $maxQueryDepth */ - public function setMaxQueryDepth($maxQueryDepth) + public function setMaxQueryDepth(int $maxQueryDepth) { $this->checkIfGreaterOrEqualToZero('maxQueryDepth', $maxQueryDepth); - $this->maxQueryDepth = (int) $maxQueryDepth; + $this->maxQueryDepth = $maxQueryDepth; } public static function maxQueryDepthErrorMessage($max, $count)