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 string |
||
26 | */ |
||
27 | private $fallback; |
||
28 | |||
29 | /** |
||
30 | * @param ImageViewFactoryInterface $imageViewFactory |
||
31 | * @param ProductAttributeValuesViewFactoryInterface $attributeValuesViewFactory |
||
32 | * @param string $fallback |
||
33 | */ |
||
34 | public function __construct( |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | public function create(ProductInterface $product, ChannelInterface $channel, $locale) |
||
69 | } |
||
70 |
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: