Completed
Push — master ( 985ca9...e0892e )
by David
18s
created

FunctionDebugContext   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
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) {
0 ignored issues
show
Bug introduced by
The class PhpParser\Node\Stmt\ClassMethod does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
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_) {
0 ignored issues
show
Bug introduced by
The class PhpParser\Node\Stmt\Function_ does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
42
            return sprintf('In function "%s",', $this->function->name->name);
43
        }
44
        return 'Should not happen';
45
    }
46
}