1 | <?php |
||
10 | class TwigFormatter extends HtmlFormatter |
||
11 | { |
||
12 | /** |
||
13 | * @var \Twig_Environment |
||
14 | */ |
||
15 | protected $environment; |
||
16 | |||
17 | /** |
||
18 | * @param \Twig_Environment $environment |
||
19 | * @param Httpstatus $httpStatus |
||
20 | */ |
||
21 | 3 | public function __construct(\Twig_Environment $environment, Httpstatus $httpStatus) |
|
26 | |||
27 | /** |
||
28 | * @param TemplatePayload $payload |
||
29 | * @return string |
||
30 | */ |
||
31 | 1 | public function body(PayloadInterface $payload) |
|
38 | } |
||
39 |
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: