| 1 | <?php |
||
| 13 | class RecursiveOperatorNodeSimplifier implements NodeSimplifier { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var NodeSimplifierFactory |
||
| 17 | */ |
||
| 18 | private $simplifierFactory; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param NodeSimplifierFactory $simplifierFactory |
||
| 22 | */ |
||
| 23 | 7 | public function __construct(NodeSimplifierFactory $simplifierFactory) { |
|
| 26 | |||
| 27 | /** |
||
| 28 | * @see NodeSimplifier::isSimplifierFor |
||
| 29 | */ |
||
| 30 | 6 | public function isSimplifierFor(AbstractNode $node) { |
|
| 33 | |||
| 34 | /** |
||
| 35 | * @see NodeSimplifier::simplify |
||
| 36 | * @param OperatorNode $node |
||
| 37 | */ |
||
| 38 | 3 | public function simplify(AbstractNode $node) { |
|
| 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: