| Conditions | 2 |
| Paths | 2 |
| Total Lines | 10 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 2 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 34 | 2 | public function simplify(AbstractNode $node) { |
|
| 35 | 2 | if(!$this->isSimplifierFor($node)) { |
|
| 36 | 1 | throw new InvalidArgumentException('RecursiveSortSimplifier can only simplify SortNode'); |
|
| 37 | } |
||
| 38 | |||
| 39 | 1 | return new SortNode( |
|
| 40 | 1 | $this->simplifierFactory->newNodeSimplifier()->simplify($node->getOperand()), |
|
|
|
|||
| 41 | 1 | $node->getPredicate() |
|
| 42 | 1 | ); |
|
| 43 | } |
||
| 44 | } |
||
| 45 |
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: