mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-23 13:26:04 +03:00
Upgrade PHPStan
This commit is contained in:
parent
d15a9405cd
commit
23ece09407
@ -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",
|
||||||
|
@ -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
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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)) {
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
// Intentionally without message, as all information already in wrapped Exception
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $valueNode->value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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 . ']';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user