1 | <?php |
||
20 | class ListCategoryUseCase implements ResponderAwareInterface |
||
21 | { |
||
22 | use ResponderAwareTrait; |
||
23 | |||
24 | /** @var CategoryRepositoryInterface */ |
||
25 | private $categoryRepository; |
||
26 | |||
27 | /** |
||
28 | * ListCategoryUseCase constructor. |
||
29 | * |
||
30 | * @param CategoryRepositoryInterface $categoryRepository |
||
31 | */ |
||
32 | public function __construct(CategoryRepositoryInterface $categoryRepository) |
||
36 | |||
37 | /** |
||
38 | * |
||
39 | */ |
||
40 | public function execute() |
||
46 | |||
47 | /** |
||
48 | * @param $categories |
||
49 | * @return CategoryListItem[] |
||
50 | */ |
||
51 | private function fetchCategoriesItems($categories) |
||
61 | |||
62 | /** |
||
63 | * @param $items |
||
64 | */ |
||
65 | private function listFetched($items) |
||
72 | } |
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: