| 1 | <?php |
||
| 17 | class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface |
||
| 18 | { |
||
| 19 | protected $redirectUrl; |
||
| 20 | |||
| 21 | 2 | public function __construct(RequestInterface $request, $data, $redirectUrl) |
|
| 27 | |||
| 28 | 1 | public function isSuccessful() |
|
| 32 | |||
| 33 | 1 | public function isRedirect() |
|
| 37 | |||
| 38 | public function getRedirectUrl() |
||
| 42 | |||
| 43 | 1 | public function getRedirectMethod() |
|
| 47 | |||
| 48 | 1 | public function getRedirectData() |
|
| 52 | } |
||
| 53 |
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: