1 | <?php |
||
11 | class GetAccountDetails extends AbstractPlugin |
||
12 | { |
||
13 | use VerifyHttpStatusResponseCode; |
||
14 | |||
15 | protected $baseUrl; |
||
16 | |||
17 | const GET_ACCOUNT_DETAILS_ENDPOINT = "/bank/resolve"; |
||
18 | |||
19 | 3 | public function __construct(string $baseUrl) |
|
23 | |||
24 | 3 | public function getPluginAccessor(): string |
|
28 | |||
29 | 3 | public function handle(array $params) |
|
47 | |||
48 | 3 | protected function isValid(array $params): bool |
|
53 | } |
||
54 |
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: