|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace GraphQL\Tests\PhpStan\Type\Definition\Type; |
|
6
|
|
|
|
|
7
|
|
|
use GraphQL\Type\Definition\InputType; |
|
8
|
|
|
use GraphQL\Type\Definition\Type; |
|
9
|
|
|
use PhpParser\Node\Expr\StaticCall; |
|
10
|
|
|
use PHPStan\Analyser\Scope; |
|
11
|
|
|
use PHPStan\Analyser\SpecifiedTypes; |
|
12
|
|
|
use PHPStan\Analyser\TypeSpecifier; |
|
13
|
|
|
use PHPStan\Analyser\TypeSpecifierAwareExtension; |
|
14
|
|
|
use PHPStan\Analyser\TypeSpecifierContext; |
|
15
|
|
|
use PHPStan\Reflection\MethodReflection; |
|
16
|
|
|
use PHPStan\Type\ObjectType; |
|
17
|
|
|
use PHPStan\Type\StaticMethodTypeSpecifyingExtension; |
|
18
|
|
|
|
|
19
|
|
|
final class IsInputTypeStaticMethodTypeSpecifyingExtension implements StaticMethodTypeSpecifyingExtension, TypeSpecifierAwareExtension |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var TypeSpecifier */ |
|
22
|
|
|
private $typeSpecifier; |
|
23
|
|
|
|
|
24
|
|
|
public function getClass() : string |
|
25
|
|
|
{ |
|
26
|
|
|
return Type::class; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function setTypeSpecifier(TypeSpecifier $typeSpecifier) : void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->typeSpecifier = $typeSpecifier; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function isStaticMethodSupported(MethodReflection $staticMethodReflection, StaticCall $node, TypeSpecifierContext $context) : bool |
|
35
|
|
|
{ |
|
36
|
|
|
// The $context argument tells us if we're in an if condition or not (as in this case). |
|
37
|
|
|
return $staticMethodReflection->getName() === 'isInputType' && ! $context->null(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function specifyTypes(MethodReflection $staticMethodReflection, StaticCall $node, Scope $scope, TypeSpecifierContext $context) : SpecifiedTypes |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->typeSpecifier->create($node->args[0]->value, new ObjectType(InputType::class), $context); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|