| Conditions | 3 |
| Paths | 3 |
| Total Lines | 15 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 38 | 3 | public function simplify(AbstractNode $node) { |
|
| 39 | 3 | if(!$this->isSimplifierFor($node)) { |
|
| 40 | 1 | throw new InvalidArgumentException('RecursiveOperatorNodeSimplifier can only simplify OperatorNode'); |
|
| 41 | } |
||
| 42 | |||
| 43 | 2 | $nodeSimplifier = $this->simplifierFactory->newNodeSimplifier(); |
|
| 44 | |||
| 45 | 2 | $operands = array(); |
|
| 46 | 2 | foreach($node->getOperands() as $operand) { |
|
|
|
|||
| 47 | 2 | $operands[] = $nodeSimplifier->simplify($operand); |
|
| 48 | 2 | } |
|
| 49 | |||
| 50 | 2 | $class = get_class($node); |
|
| 51 | 2 | return new $class($operands); |
|
| 52 | } |
||
| 53 | } |
||
| 54 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: