Skip to content

Commit

Permalink
Progress towards PHPStan level 5 (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia authored Nov 21, 2021
1 parent e18d52d commit eca0651
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 114 deletions.
17 changes: 9 additions & 8 deletions docs/class-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ static function isInputType($type): bool

```php
/**
* @return (Type&NamedType)|null
*
* @api
*/
static function getNamedType($type): GraphQL\Type\Definition\Type
static function getNamedType(GraphQL\Type\Definition\Type $type): GraphQL\Type\Definition\Type
```

```php
Expand Down Expand Up @@ -2293,7 +2295,7 @@ static function fromArray(array $node): GraphQL\Language\AST\Node
/**
* Convert AST node to serializable array
*
* @return mixed[]
* @return array<string, mixed>
*
* @api
*/
Expand Down Expand Up @@ -2349,9 +2351,9 @@ static function astFromValue($value, GraphQL\Type\Definition\InputType $type)
* | Null Value | null |
*
* @param VariableNode|NullValueNode|IntValueNode|FloatValueNode|StringValueNode|BooleanValueNode|EnumValueNode|ListValueNode|ObjectValueNode|null $valueNode
* @param mixed[]|null $variables
* @param array<string, mixed>|null $variables
*
* @return mixed[]|stdClass|null
* @return mixed
*
* @throws Exception
*
Expand Down Expand Up @@ -2381,16 +2383,15 @@ static function valueFromAST(
* | Enum | Mixed |
* | Null | null |
*
* @param Node $valueNode
* @param mixed[]|null $variables
* @param array<string, mixed>|null $variables
*
* @return mixed
*
* @throws Exception
*
* @api
*/
static function valueFromASTUntyped($valueNode, array $variables = null)
static function valueFromASTUntyped(GraphQL\Language\AST\Node $valueNode, array $variables = null)
```

```php
Expand All @@ -2403,7 +2404,7 @@ static function valueFromASTUntyped($valueNode, array $variables = null)
*
* @api
*/
static function typeFromAST(GraphQL\Type\Schema $schema, $inputTypeNode): GraphQL\Type\Definition\Type
static function typeFromAST(GraphQL\Type\Schema $schema, GraphQL\Language\AST\Node $inputTypeNode): GraphQL\Type\Definition\Type
```

```php
Expand Down
3 changes: 3 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<file>tests</file>

<rule ref="Doctrine">
<!-- Prevents useful type assertions -->
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable" />

<!-- We will rely on PHPStan instead of these -->
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint" />
Expand Down
5 changes: 4 additions & 1 deletion src/Type/Definition/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,17 @@ public static function isInputType($type): bool
}

/**
* @return (Type&NamedType)|null
*
* @api
*/
public static function getNamedType($type): ?Type
public static function getNamedType(?Type $type): ?Type
{
while ($type instanceof WrappingType) {
$type = $type->getWrappedType();
}

// @phpstan-ignore-next-line non-wrapped types must be named types
return $type;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Utils/TypeInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public function getFieldDef(): ?FieldDefinition
}

/**
* @return mixed|null
* @return mixed any value is possible
*/
public function getDefaultValue()
{
Expand Down
4 changes: 4 additions & 0 deletions src/Validator/Rules/FieldsOnCorrectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use GraphQL\Error\Error;
use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Type\Definition\InterfaceType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\TypeWithFields;
use GraphQL\Type\Definition\UnionType;
use GraphQL\Type\Schema;
use GraphQL\Utils\Utils;
use GraphQL\Validator\ValidationContext;
Expand Down Expand Up @@ -69,6 +71,8 @@ public function getVisitor(ValidationContext $context): array
protected function getSuggestedTypeNames(Schema $schema, Type $type, string $fieldName): array
{
if (Type::isAbstractType($type)) {
/** @var InterfaceType|UnionType $type must be abstract type inside this if */

$suggestedObjectTypes = [];
$interfaceUsageCount = [];

Expand Down
Loading

0 comments on commit eca0651

Please sign in to comment.