1 | <?php |
||
21 | abstract class AbstractStringContainerBlock extends AbstractBlock implements StringContainerInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var ArrayCollection|string[] |
||
25 | */ |
||
26 | protected $strings; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $finalStringContents = ''; |
||
32 | |||
33 | /** |
||
34 | * Constructor |
||
35 | */ |
||
36 | 2040 | public function __construct() |
|
40 | |||
41 | /** |
||
42 | * @param string $line |
||
43 | */ |
||
44 | 2019 | public function addLine(string $line) |
|
48 | |||
49 | /** |
||
50 | * @param ContextInterface $context |
||
51 | * @param Cursor $cursor |
||
52 | */ |
||
53 | public function handleRemainingContents(ContextInterface $context, Cursor $cursor) |
||
61 | |||
62 | 1992 | public function getStringContent(): string |
|
66 | } |
||
67 |
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 sub-classes 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 parent class: