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

IsCompositeTypeStaticMethodTypeSpecifyingExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 6
dl 0
loc 24
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getClass() 0 3 1
A setTypeSpecifier() 0 3 1
A specifyTypes() 0 3 1
A isStaticMethodSupported() 0 4 2
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