Upgrade PHPStan

This commit is contained in:
Simon Podlipsky 2019-03-18 12:59:34 +01:00
parent d15a9405cd
commit 23ece09407
13 changed files with 32 additions and 49 deletions

View File

@ -16,9 +16,9 @@
"require-dev": { "require-dev": {
"doctrine/coding-standard": "^5.0", "doctrine/coding-standard": "^5.0",
"phpbench/phpbench": "^0.14.0", "phpbench/phpbench": "^0.14.0",
"phpstan/phpstan": "0.10.5", "phpstan/phpstan": "^0.11.4",
"phpstan/phpstan-phpunit": "0.10.0", "phpstan/phpstan-phpunit": "^0.11.0",
"phpstan/phpstan-strict-rules": "0.10.1", "phpstan/phpstan-strict-rules": "^0.11.0",
"phpunit/phpcov": "^5.0", "phpunit/phpcov": "^5.0",
"phpunit/phpunit": "^7.2", "phpunit/phpunit": "^7.2",
"psr/http-message": "^1.0", "psr/http-message": "^1.0",

View File

@ -8,6 +8,8 @@ parameters:
ignoreErrors: ignoreErrors:
- "~Construct empty\\(\\) is not allowed\\. Use more strict comparison~" - "~Construct empty\\(\\) is not allowed\\. Use more strict comparison~"
- "~(Method|Property) .+::.+(\\(\\))? (has parameter \\$\\w+ with no|has no return|has no) typehint specified~" - "~(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: includes:
- vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-phpunit/extension.neon

View File

@ -61,8 +61,6 @@ final class Warning
} elseif ($suppress === false) { } elseif ($suppress === false) {
self::$enableWarnings = self::ALL; self::$enableWarnings = self::ALL;
} else { } else {
$suppress = (int) $suppress;
self::$enableWarnings &= ~$suppress; self::$enableWarnings &= ~$suppress;
} }
} }
@ -86,8 +84,6 @@ final class Warning
} elseif ($enable === false) { } elseif ($enable === false) {
self::$enableWarnings = 0; self::$enableWarnings = 0;
} else { } else {
$enable = (int) $enable;
self::$enableWarnings |= $enable; self::$enableWarnings |= $enable;
} }
} }

View File

@ -154,7 +154,7 @@ class ExecutionResult implements JsonSerializable
} }
if (! empty($this->extensions)) { if (! empty($this->extensions)) {
$result['extensions'] = (array) $this->extensions; $result['extensions'] = $this->extensions;
} }
return $result; return $result;

View File

@ -62,13 +62,10 @@ class OperationParams
* Creates an instance from given array * Creates an instance from given array
* *
* @param mixed[] $params * @param mixed[] $params
* @param bool $readonly
*
* @return OperationParams
* *
* @api * @api
*/ */
public static function create(array $params, $readonly = false) public static function create(array $params, bool $readonly = false) : OperationParams
{ {
$instance = new static(); $instance = new static();
@ -108,7 +105,7 @@ class OperationParams
$instance->operation = $params['operationname']; $instance->operation = $params['operationname'];
$instance->variables = $params['variables']; $instance->variables = $params['variables'];
$instance->extensions = $params['extensions']; $instance->extensions = $params['extensions'];
$instance->readOnly = (bool) $readonly; $instance->readOnly = $readonly;
// Apollo server/client compatibility: look for the queryid in extensions // Apollo server/client compatibility: look for the queryid in extensions
if (isset($instance->extensions['persistedQuery']['sha256Hash']) && empty($instance->query) && empty($instance->queryId)) { if (isset($instance->extensions['persistedQuery']['sha256Hash']) && empty($instance->query) && empty($instance->queryId)) {

View File

@ -225,15 +225,11 @@ class ServerConfig
/** /**
* Allow batching queries (disabled by default) * Allow batching queries (disabled by default)
* *
* @param bool $enableBatching
*
* @return self
*
* @api * @api
*/ */
public function setQueryBatching($enableBatching) public function setQueryBatching(bool $enableBatching) : self
{ {
$this->queryBatching = (bool) $enableBatching; $this->queryBatching = $enableBatching;
return $this; return $this;
} }

View File

@ -58,11 +58,11 @@ class BooleanType extends ScalarType
*/ */
public function parseLiteral($valueNode, ?array $variables = null) public function parseLiteral($valueNode, ?array $variables = null)
{ {
if ($valueNode instanceof BooleanValueNode) { if (! $valueNode instanceof BooleanValueNode) {
return (bool) $valueNode->value; // Intentionally without message, as all information already in wrapped Exception
throw new Exception();
} }
// Intentionally without message, as all information already in wrapped Exception return $valueNode->value;
throw new Exception();
} }
} }

View File

@ -40,7 +40,7 @@ class Directive
public $locations; public $locations;
/** @var FieldArgument[] */ /** @var FieldArgument[] */
public $args; public $args = [];
/** @var DirectiveDefinitionNode|null */ /** @var DirectiveDefinitionNode|null */
public $astNode; public $astNode;

View File

@ -20,15 +20,9 @@ class ListOfType extends Type implements WrappingType, OutputType, NullableType,
$this->ofType = Type::assertType($type); $this->ofType = Type::assertType($type);
} }
/** public function toString() : string
* @return string
*/
public function toString()
{ {
$type = $this->ofType; return '[' . $this->ofType->toString() . ']';
$str = $type instanceof Type ? $type->toString() : (string) $type;
return '[' . $str . ']';
} }
/** /**

View File

@ -531,12 +531,12 @@ class BreakingChangesFinder
]; ];
} }
// Check if a non-null arg was added to the field // 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; $oldArgs = $oldTypeFields[$fieldName]->args;
$oldArgDef = Utils::find( $oldArgDef = Utils::find(
$oldArgs, $oldArgs,
static function ($arg) use ($newArgDef) { static function ($arg) use ($newTypeFieldArgDef) {
return $arg->name === $newArgDef->name; return $arg->name === $newTypeFieldArgDef->name;
} }
); );
@ -545,8 +545,8 @@ class BreakingChangesFinder
} }
$newTypeName = $newType->name; $newTypeName = $newType->name;
$newArgName = $newArgDef->name; $newArgName = $newTypeFieldArgDef->name;
if ($newArgDef->getType() instanceof NonNull) { if ($newTypeFieldArgDef->getType() instanceof NonNull) {
$breakingChanges[] = [ $breakingChanges[] = [
'type' => self::BREAKING_CHANGE_NON_NULL_ARG_ADDED, 'type' => self::BREAKING_CHANGE_NON_NULL_ARG_ADDED,
'description' => "A non-null arg ${newArgName} on ${newTypeName}.${fieldName} was added", 'description' => "A non-null arg ${newArgName} on ${newTypeName}.${fieldName} was added",
@ -668,7 +668,7 @@ class BreakingChangesFinder
{ {
$removedArgs = []; $removedArgs = [];
$newArgMap = self::getArgumentMapForDirective($newDirective); $newArgMap = self::getArgumentMapForDirective($newDirective);
foreach ((array) $oldDirective->args as $arg) { foreach ($oldDirective->args as $arg) {
if (isset($newArgMap[$arg->name])) { if (isset($newArgMap[$arg->name])) {
continue; continue;
} }
@ -727,7 +727,7 @@ class BreakingChangesFinder
{ {
$addedArgs = []; $addedArgs = [];
$oldArgMap = self::getArgumentMapForDirective($oldDirective); $oldArgMap = self::getArgumentMapForDirective($oldDirective);
foreach ((array) $newDirective->args as $arg) { foreach ($newDirective->args as $arg) {
if (isset($oldArgMap[$arg->name])) { if (isset($oldArgMap[$arg->name])) {
continue; continue;
} }

View File

@ -178,7 +178,7 @@ class TypeInfo
$nestedTypes = array_merge($nestedTypes, $type->getInterfaces()); $nestedTypes = array_merge($nestedTypes, $type->getInterfaces());
} }
if ($type instanceof ObjectType || $type instanceof InterfaceType) { if ($type instanceof ObjectType || $type instanceof InterfaceType) {
foreach ((array) $type->getFields() as $fieldName => $field) { foreach ($type->getFields() as $fieldName => $field) {
if (! empty($field->args)) { if (! empty($field->args)) {
$fieldArgTypes = array_map( $fieldArgTypes = array_map(
static function (FieldArgument $arg) { static function (FieldArgument $arg) {
@ -193,12 +193,12 @@ class TypeInfo
} }
} }
if ($type instanceof InputObjectType) { if ($type instanceof InputObjectType) {
foreach ((array) $type->getFields() as $fieldName => $field) { foreach ($type->getFields() as $fieldName => $field) {
$nestedTypes[] = $field->getType(); $nestedTypes[] = $field->getType();
} }
} }
foreach ($nestedTypes as $type) { foreach ($nestedTypes as $nestedType) {
$typeMap = self::extractTypes($type, $typeMap); $typeMap = self::extractTypes($nestedType, $typeMap);
} }
return $typeMap; return $typeMap;

View File

@ -264,8 +264,8 @@ class Utils
$grouped = []; $grouped = [];
foreach ($traversable as $key => $value) { foreach ($traversable as $key => $value) {
$newKeys = (array) $keyFn($value, $key); $newKeys = (array) $keyFn($value, $key);
foreach ($newKeys as $key) { foreach ($newKeys as $newKey) {
$grouped[$key][] = $value; $grouped[$newKey][] = $value;
} }
} }

View File

@ -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. * 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->checkIfGreaterOrEqualToZero('maxQueryDepth', $maxQueryDepth);
$this->maxQueryDepth = (int) $maxQueryDepth; $this->maxQueryDepth = $maxQueryDepth;
} }
public static function maxQueryDepthErrorMessage($max, $count) public static function maxQueryDepthErrorMessage($max, $count)