| 1 | <?php |
||
| 23 | final class RequestListener |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var ThemeRepositoryInterface |
||
| 27 | */ |
||
| 28 | private $themeRepository; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var ThemeContextInterface |
||
| 32 | */ |
||
| 33 | private $themeContext; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param ThemeRepositoryInterface $themeRepository |
||
| 37 | * @param SettableThemeContext $themeContext |
||
| 38 | */ |
||
| 39 | public function __construct(ThemeRepositoryInterface $themeRepository, SettableThemeContext $themeContext) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param GetResponseEvent $event |
||
| 47 | */ |
||
| 48 | public function onKernelRequest(GetResponseEvent $event) |
||
| 57 | } |
||
| 58 |
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 implementation 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 interface: