1 | <?php |
||
9 | class RecursiveTripleNodeSimplifier implements NodeSimplifier { |
||
10 | |||
11 | /** |
||
12 | * @var NodeSimplifierFactory |
||
13 | */ |
||
14 | private $simplifierFactory; |
||
15 | |||
16 | /** |
||
17 | * @param NodeSimplifierFactory $simplifierFactory |
||
18 | */ |
||
19 | 5 | public function __construct(NodeSimplifierFactory $simplifierFactory) { |
|
22 | |||
23 | /** |
||
24 | * @see NodeSimplifier::isSimplifierFor |
||
25 | */ |
||
26 | 4 | public function isSimplifierFor(AbstractNode $node) { |
|
29 | |||
30 | /** |
||
31 | * @see NodeSimplifier::simplify |
||
32 | * @param TripleNode $node |
||
33 | */ |
||
34 | 2 | public function simplify(AbstractNode $node) { |
|
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: