1 | <?php |
||
14 | class FirstNodeSimplifier implements NodeSimplifier { |
||
15 | |||
16 | /** |
||
17 | * @var NodeSimplifierFactory |
||
18 | */ |
||
19 | private $simplifierFactory; |
||
20 | |||
21 | /** |
||
22 | * @param NodeSimplifierFactory $simplifierFactory |
||
23 | */ |
||
24 | 7 | public function __construct(NodeSimplifierFactory $simplifierFactory) { |
|
27 | |||
28 | /** |
||
29 | * @see NodeSimplifier::isSimplifierFor |
||
30 | */ |
||
31 | 6 | public function isSimplifierFor(AbstractNode $node) { |
|
34 | |||
35 | /** |
||
36 | * @see NodeSimplifier::simplify |
||
37 | * @param FirstNode $node |
||
38 | */ |
||
39 | 4 | public function simplify(AbstractNode $node) { |
|
58 | } |
||
59 |
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: