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