1 | <?php |
||
11 | final class ResolveNextUrlAction implements ActionInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $thankYouUrl; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $cancelUrl; |
||
22 | |||
23 | /** |
||
24 | * ResolveNextUrlAction constructor. |
||
25 | * |
||
26 | * @param string $thankYouUrl |
||
27 | * @param string $cancelUrl |
||
28 | */ |
||
29 | public function __construct(string $thankYouUrl, string $cancelUrl) |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | * |
||
38 | * @param ResolveNextUrl $request |
||
39 | */ |
||
40 | public function execute($request): void |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public function supports($request): bool |
||
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: