CreateStubExtension::getTypeFromMethodCall()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 12
ccs 0
cts 10
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cdn77\TestUtils\PHPStan;
6
7
use PhpParser\Node\Expr\ClassConstFetch;
8
use PhpParser\Node\Expr\MethodCall;
9
use PhpParser\Node\Name\FullyQualified;
10
use PHPStan\Analyser\Scope;
11
use PHPStan\Reflection\MethodReflection;
12
use PHPStan\Type\DynamicMethodReturnTypeExtension;
13
use PHPStan\Type\ObjectType;
14
use PHPStan\Type\Type;
15
use function assert;
16
17
abstract class CreateStubExtension implements DynamicMethodReturnTypeExtension
18
{
19
    abstract public function getClass() : string;
20
21
    public function isMethodSupported(MethodReflection $methodReflection) : bool
22
    {
23
        return $methodReflection->getName() === 'createStub';
24
    }
25
26
    public function getTypeFromMethodCall(
27
        MethodReflection $methodReflection,
28
        MethodCall $methodCall,
29
        Scope $scope
30
    ) : Type {
31
        $classConstFetch = $methodCall->args[0]->value;
32
        assert($classConstFetch instanceof ClassConstFetch);
33
34
        $fullyQualified = $classConstFetch->class;
35
        assert($fullyQualified instanceof FullyQualified);
36
37
        return new ObjectType($fullyQualified->toCodeString());
38
    }
39
}
40