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