1 | <?php |
||
22 | final class MongoDBPurgerListener extends AbstractListener implements BeforeSuiteListenerInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var ManagerRegistry |
||
26 | */ |
||
27 | private $managerRegistry; |
||
28 | |||
29 | /** |
||
30 | * @param ManagerRegistry $managerRegistry |
||
31 | */ |
||
32 | public function __construct(ManagerRegistry $managerRegistry) |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | public function beforeSuite(SuiteEvent $suiteEvent, array $options) |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function getName() |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | protected function configureOptionsNode(ArrayNodeDefinition $optionsNode) |
||
71 | } |
||
72 |
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: