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

FunctionDebugContext   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __toString() 0 14 4
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 FunctionDebugContext implements DebugContextInterface
15
{
16
    /**
17
     * @var FunctionLike
18
     */
19
    private $function;
20
    /**
21
     * @var Scope
22
     */
23
    private $scope;
24
25
    public function __construct(Scope $scope, FunctionLike $function)
26
    {
27
28
        $this->function = $function;
29
        $this->scope = $scope;
30
    }
31
32
    public function __toString()
33
    {
34
        if ($this->function instanceof ClassMethod) {
35
            if (!$this->scope->isInClass()) {
36
                return 'Should not happen';
37
            }
38
39
            return sprintf('In method "%s::%s",', $this->scope->getClassReflection()->getDisplayName(), $this->function->name->name);
40
        }
41
        elseif ($this->function instanceof Function_) {
42
            return sprintf('In function "%s",', $this->function->name->name);
43
        }
44
        return 'Should not happen';
45
    }
46
}