1 | <?php |
||
12 | class XmlRpcService |
||
13 | { |
||
14 | /** |
||
15 | * @var RequestService |
||
16 | */ |
||
17 | private $requestService; |
||
18 | |||
19 | /** |
||
20 | * @param RequestService $requestService |
||
21 | */ |
||
22 | public function __construct(RequestService $requestService) |
||
26 | |||
27 | public function call(string $method, array $arguments = []) |
||
42 | |||
43 | public function callRaw(string $method, array $arguments = []) |
||
75 | } |
||
76 |
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: