1 | <?php |
||
14 | abstract class AbstractService |
||
15 | { |
||
16 | use Traits\ClientTrait; |
||
17 | use Traits\AuthorizationTrait; |
||
18 | use Traits\SerializerTrait; |
||
19 | |||
20 | /** |
||
21 | * Device constructor. |
||
22 | * |
||
23 | * @param Model\InStore\Authorization $auth |
||
24 | * @param Client $client |
||
25 | * @param SerializerInterface $serializer |
||
26 | */ |
||
27 | public function __construct(Model\InStore\Authorization $auth, Client $client, SerializerInterface $serializer) |
||
33 | |||
34 | /** |
||
35 | * @param object|array $model |
||
36 | * @param HandlerStack|null $stack |
||
37 | * |
||
38 | * @return array |
||
39 | */ |
||
40 | protected function generateParams($model, HandlerStack $stack = null) |
||
62 | } |
||
63 |
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: