1 | <?php |
||
21 | class FencedCode extends AbstractStringContainerBlock |
||
22 | { |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $info; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | protected $length; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $char; |
||
37 | |||
38 | /** |
||
39 | * @var int |
||
40 | */ |
||
41 | protected $offset; |
||
42 | |||
43 | /** |
||
44 | * @param int $length |
||
45 | * @param string $char |
||
46 | * @param int $offset |
||
47 | */ |
||
48 | 111 | public function __construct(int $length, string $char, int $offset) |
|
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | public function getInfo(): string |
||
64 | |||
65 | /** |
||
66 | * @return string[] |
||
67 | */ |
||
68 | 111 | public function getInfoWords(): array |
|
72 | |||
73 | /** |
||
74 | * @return string |
||
75 | */ |
||
76 | 105 | public function getChar(): string |
|
80 | |||
81 | /** |
||
82 | * @param string $char |
||
83 | * |
||
84 | * @return $this |
||
85 | */ |
||
86 | public function setChar(string $char): self |
||
92 | |||
93 | /** |
||
94 | * @return int |
||
95 | */ |
||
96 | 93 | public function getLength(): int |
|
100 | |||
101 | /** |
||
102 | * @param int $length |
||
103 | * |
||
104 | * @return $this |
||
105 | */ |
||
106 | 87 | public function setLength(int $length): self |
|
112 | |||
113 | /** |
||
114 | * @return int |
||
115 | */ |
||
116 | public function getOffset(): int |
||
120 | |||
121 | /** |
||
122 | * @param int $offset |
||
123 | * |
||
124 | * @return $this |
||
125 | */ |
||
126 | public function setOffset(int $offset): self |
||
132 | |||
133 | /** |
||
134 | * Returns true if this block can contain the given block as a child node |
||
135 | * |
||
136 | * @param AbstractBlock $block |
||
137 | * |
||
138 | * @return bool |
||
139 | */ |
||
140 | public function canContain(AbstractBlock $block): bool |
||
144 | |||
145 | /** |
||
146 | * Whether this is a code block |
||
147 | * |
||
148 | * @return bool |
||
149 | */ |
||
150 | 99 | public function isCode(): bool |
|
154 | |||
155 | 99 | public function matchesNextLine(Cursor $cursor): bool |
|
170 | |||
171 | 111 | public function finalize(ContextInterface $context, int $endLineNumber) |
|
184 | |||
185 | /** |
||
186 | * @param ContextInterface $context |
||
187 | * @param Cursor $cursor |
||
188 | */ |
||
189 | 105 | public function handleRemainingContents(ContextInterface $context, Cursor $cursor) |
|
207 | |||
208 | /** |
||
209 | * @param Cursor $cursor |
||
210 | * @param int $currentLineNumber |
||
211 | * |
||
212 | * @return bool |
||
213 | */ |
||
214 | 105 | public function shouldLastLineBeBlank(Cursor $cursor, int $currentLineNumber): bool |
|
218 | } |
||
219 |
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: