1 | <?php |
||
21 | class HtmlBlock extends AbstractStringContainerBlock |
||
22 | { |
||
23 | // Any changes to these constants should be reflected in .phpstorm.meta.php |
||
24 | const TYPE_1_CODE_CONTAINER = 1; |
||
25 | const TYPE_2_COMMENT = 2; |
||
26 | const TYPE_3 = 3; |
||
27 | const TYPE_4 = 4; |
||
28 | const TYPE_5_CDATA = 5; |
||
29 | const TYPE_6_BLOCK_ELEMENT = 6; |
||
30 | const TYPE_7_MISC_ELEMENT = 7; |
||
31 | |||
32 | /** |
||
33 | * @var int |
||
34 | */ |
||
35 | protected $type; |
||
36 | |||
37 | /** |
||
38 | * @param int $type |
||
39 | */ |
||
40 | 177 | public function __construct(int $type) |
|
46 | |||
47 | /** |
||
48 | * @return int |
||
49 | */ |
||
50 | public function getType(): int |
||
54 | |||
55 | /** |
||
56 | * @param int $type |
||
57 | */ |
||
58 | public function setType(int $type) |
||
62 | |||
63 | /** |
||
64 | * Returns true if this block can contain the given block as a child node |
||
65 | * |
||
66 | * @param AbstractBlock $block |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function canContain(AbstractBlock $block): bool |
||
74 | |||
75 | /** |
||
76 | * Whether this is a code block |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | 111 | public function isCode(): bool |
|
84 | |||
85 | 132 | public function matchesNextLine(Cursor $cursor): bool |
|
93 | |||
94 | 162 | public function finalize(ContextInterface $context, int $endLineNumber) |
|
100 | |||
101 | /** |
||
102 | * @param ContextInterface $context |
||
103 | * @param Cursor $cursor |
||
104 | */ |
||
105 | 162 | public function handleRemainingContents(ContextInterface $context, Cursor $cursor) |
|
116 | } |
||
117 |
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: