Passed
Push — master ( 7cc72b...baad32 )
by Vladimir
10:39
created

setTypeSpecifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Tests\PhpStan\Type\Definition\Type;
6
7
use GraphQL\Type\Definition\CompositeType;
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 IsCompositeTypeStaticMethodTypeSpecifyingExtension 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() === 'isCompositeType' && ! $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(CompositeType::class), $context);
43
    }
44
}
45