| 1 | <?php |
||
| 8 | final class PaymentMethodViewFactory implements PaymentMethodViewFactoryInterface |
||
| 9 | { |
||
| 10 | /** @var string */ |
||
| 11 | private $paymentMethodViewClass; |
||
| 12 | |||
| 13 | public function __construct(string $paymentMethodViewClass) |
||
| 17 | |||
| 18 | /** |
||
| 19 | * {@inheritdoc} |
||
| 20 | */ |
||
| 21 | public function create(PaymentMethodInterface $paymentMethod, string $locale): PaymentMethodView |
||
| 32 | } |
||
| 33 |
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: