Completed
Pull Request — master (#27)
by David
11:28
created

ParameterDebugContext::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 0
1
<?php
2
3
4
namespace TheCodingMachine\PHPStan\Rules\TypeHints;
5
6
7
use PhpParser\Node\FunctionLike;
8
use PhpParser\Node\Name;
9
use PhpParser\Node\Stmt\ClassMethod;
10
use PhpParser\Node\Stmt\Function_;
11
use PHPStan\Analyser\Scope;
12
use PHPStan\Reflection\Php\PhpParameterReflection;
13
14
class ParameterDebugContext implements DebugContextInterface
15
{
16
    /**
17
     * @var FunctionLike
18
     */
19
    private $function;
20
    /**
21
     * @var PhpParameterReflection
22
     */
23
    private $parameter;
24
    /**
25
     * @var Scope
26
     */
27
    private $scope;
28
29
    public function __construct(Scope $scope, FunctionLike $function, PhpParameterReflection $parameter)
30
    {
31
32
        $this->function = $function;
33
        $this->parameter = $parameter;
34
        $this->scope = $scope;
35
    }
36
37
    public function __toString()
38
    {
39
        if ($this->function instanceof ClassMethod) {
40
            if (!$this->scope->isInClass()) {
41
                return 'Should not happen';
42
            }
43
44
            return sprintf('In method "%s::%s", parameter $%s', $this->scope->getClassReflection()->getDisplayName(), $this->function->name->name, $this->parameter->getName());
45
        }
46
        elseif ($this->function instanceof Function_) {
47
            return sprintf('In function "%s", parameter $%s', $this->function->name->name, $this->parameter->getName());
48
        }
49
        return 'Should not happen';
50
    }
51
52
    public function getName(): string
53
    {
54
        return $this->parameter->getName();
55
    }
56
}