| 1 | <?php |
||
| 10 | class IndexController extends AbstractActionController |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var InteractiveAuth |
||
| 14 | */ |
||
| 15 | private $auth; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var Redirect |
||
| 19 | */ |
||
| 20 | private $redirect; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | private $redirectToUrl; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * IndexController constructor. |
||
| 29 | * |
||
| 30 | * @param InteractiveAuth $auth |
||
| 31 | * @param Redirect $redirect |
||
| 32 | * @param string $redirectToUrl |
||
| 33 | */ |
||
| 34 | public function __construct( |
||
| 44 | |||
| 45 | public function loginFormAction() |
||
| 70 | |||
| 71 | public function logoutAction() |
||
| 76 | } |
||
| 77 |
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: