Completed
Pull Request — master (#1)
by David
01:42
created

MissingTypeHintInMethodRule::getContext()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
4
namespace TheCodingMachine\PHPStan\Rules\TypeHints;
5
6
use BetterReflection\Reflection\ReflectionFunction;
7
use BetterReflection\Reflection\ReflectionFunctionAbstract;
8
use BetterReflection\Reflection\ReflectionMethod;
9
use BetterReflection\Reflection\ReflectionParameter;
10
use PhpParser\Node;
11
12
class MissingTypeHintInMethodRule extends AbstractMissingTypeHintRule
13
{
14
    public function getNodeType(): string
15
    {
16
        return Node\Stmt\ClassMethod::class;
17
    }
18
19
    /**
20
     * @param ReflectionFunctionAbstract|ReflectionParameter $reflection
21
     * @return string
22
     */
23
    public function getContext($reflection): string
24
    {
25
        if ($reflection instanceof ReflectionParameter) {
0 ignored issues
show
Bug introduced by
The class BetterReflection\Reflection\ReflectionParameter 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...
26
            $reflection = $reflection->getDeclaringFunction();
27
        }
28
        return 'In method "'.$reflection->getDeclaringClass()->getName().'::'.$reflection->getName().'"';
29
    }
30
}
31