| Conditions | 2 |
| Paths | 2 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | public function create(TaxonInterface $taxon, $locale) |
||
| 28 | { |
||
| 29 | $taxonView = new TaxonView(); |
||
| 30 | $taxonView->name = $taxon->getTranslation($locale)->getName(); |
||
|
|
|||
| 31 | $taxonView->code = $taxon->getCode(); |
||
| 32 | $taxonView->slug = $taxon->getTranslation($locale)->getSlug(); |
||
| 33 | $taxonView->description = $taxon->getTranslation($locale)->getDescription(); |
||
| 34 | $taxonView->position = $taxon->getPosition(); |
||
| 35 | |||
| 36 | /** @var ImageInterface $image */ |
||
| 37 | foreach ($taxon->getImages() as $image) { |
||
| 38 | $taxonView->images[] = $this->imageViewFactory->create($image); |
||
| 39 | } |
||
| 40 | |||
| 41 | return $taxonView; |
||
| 42 | } |
||
| 43 | } |
||
| 44 |
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: