Merge pull request #458 from simPod/upgrade-phpstan

Upgrade PHPStan
This commit is contained in:
Vladimir Razuvaev 2019-03-23 17:57:09 +07:00 committed by GitHub
commit b088720d40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 32 additions and 49 deletions

View File

@ -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",

View File

@ -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

View File

@ -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;
}
}

View File

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

View File

@ -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)) {

View File

@ -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;
}

View File

@ -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;
}
}

View File

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

View File

@ -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() . ']';
}
/**

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}
}

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.
*
* @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)