| Conditions | 5 |
| Paths | 5 |
| Total Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 5.0073 |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | 3 | public function apply(AbstractNode $node) |
|
| 17 | { |
||
| 18 | 3 | if (false === $this->isTest($node)) { |
|
|
|
|||
| 19 | 1 | return; |
|
| 20 | } |
||
| 21 | |||
| 22 | 2 | $regex = $this->getStringProperty('regex'); |
|
| 23 | 2 | $number = $this->getIntProperty('number'); |
|
| 24 | |||
| 25 | 2 | foreach ($node->getMethods() as $method) { |
|
| 26 | 2 | if ('test' !== substr($method->getImage(), 0, 4)) { |
|
| 27 | continue; |
||
| 28 | } |
||
| 29 | |||
| 30 | 2 | $wordsInclusiveTest = count(preg_split($regex, $method->getImage())); |
|
| 31 | 2 | $words = $wordsInclusiveTest - 1; |
|
| 32 | |||
| 33 | 2 | if ($number > $words) { |
|
| 34 | 2 | $this->addViolation($method, [$words, $number]); |
|
| 35 | 2 | } |
|
| 36 | 2 | } |
|
| 37 | 2 | } |
|
| 38 | } |
||
| 39 |
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.