1 | <?php |
||
11 | class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface |
||
12 | 3 | { |
|
13 | public function isSuccessful() |
||
17 | 3 | ||
18 | public function isRedirect() |
||
22 | 3 | ||
23 | public function getRedirectUrl() |
||
27 | 1 | ||
28 | public function getRedirectMethod() |
||
32 | 1 | ||
33 | public function getRedirectData() |
||
37 | |||
38 | /** |
||
39 | * Description of the response; mostly only relevant in the error case when not redirecting |
||
40 | 3 | */ |
|
41 | public function getMessage() |
||
45 | } |
||
46 |
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: