Conditions | 5 |
Paths | 5 |
Total Lines | 22 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 5 |
Changes | 5 | ||
Bugs | 1 | Features | 3 |
1 | <?php |
||
20 | 4 | public function apply(AbstractNode $node) |
|
21 | { |
||
22 | 4 | if (false === $this->isTest($node)) { |
|
|
|||
23 | 1 | return; |
|
24 | } |
||
25 | |||
26 | 3 | $regex = $this->getStringProperty('regex'); |
|
27 | 3 | $number = $this->getIntProperty('number'); |
|
28 | |||
29 | 3 | foreach ($node->getMethods() as $method) { |
|
30 | 3 | if ('test' !== substr($method->getImage(), 0, 4)) { |
|
31 | 1 | continue; |
|
32 | } |
||
33 | |||
34 | 2 | $wordsInclusiveTest = count(preg_split($regex, $method->getImage())); |
|
35 | 2 | $words = $wordsInclusiveTest - 1; |
|
36 | |||
37 | 2 | if ($number > $words) { |
|
38 | 1 | $this->addViolation($method, [$words, $number]); |
|
39 | 1 | } |
|
40 | 3 | } |
|
41 | 3 | } |
|
42 | } |
||
43 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.