1 | <?php |
||
12 | final class ProductViewFactory implements ProductViewFactoryInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var ImageViewFactoryInterface |
||
16 | */ |
||
17 | private $imageViewFactory; |
||
18 | |||
19 | /** |
||
20 | * @var ProductAttributeValuesViewFactoryInterface |
||
21 | */ |
||
22 | private $attributeValuesViewFactory; |
||
23 | |||
24 | /** |
||
25 | * @var TaxonViewFactoryInterface |
||
26 | */ |
||
27 | private $taxonViewFactory; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | private $fallback; |
||
33 | |||
34 | /** |
||
35 | * @param ImageViewFactoryInterface $imageViewFactory |
||
36 | * @param ProductAttributeValuesViewFactoryInterface $attributeValuesViewFactory |
||
37 | * @param TaxonViewFactoryInterface $taxonViewFactory |
||
38 | * @param string $fallback |
||
39 | */ |
||
40 | public function __construct( |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function create(ProductInterface $product, ChannelInterface $channel, $locale) |
||
77 | |||
78 | /** |
||
79 | * @param TaxonInterface $taxon |
||
80 | * @param string $locale |
||
81 | * |
||
82 | * @return TaxonView |
||
83 | */ |
||
84 | private function getTaxonWithAncestors(TaxonInterface $taxon, $locale) |
||
97 | } |
||
98 |
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: