1 | <?php |
||
20 | class ListBlock extends AbstractBlock |
||
21 | { |
||
22 | const TYPE_UNORDERED = 'Bullet'; |
||
23 | const TYPE_ORDERED = 'Ordered'; |
||
24 | |||
25 | /** |
||
26 | * @var bool |
||
27 | */ |
||
28 | protected $tight = false; |
||
29 | |||
30 | /** |
||
31 | * @var ListData |
||
32 | */ |
||
33 | protected $listData; |
||
34 | |||
35 | 255 | public function __construct(ListData $listData) |
|
41 | |||
42 | /** |
||
43 | * @return ListData |
||
44 | */ |
||
45 | 255 | public function getListData() |
|
49 | |||
50 | /** |
||
51 | * @return bool |
||
52 | */ |
||
53 | 30 | public function endsWithBlankLine() |
|
65 | |||
66 | /** |
||
67 | * Returns true if this block can contain the given block as a child node |
||
68 | * |
||
69 | * @param AbstractBlock $block |
||
70 | * |
||
71 | * @return bool |
||
72 | */ |
||
73 | 237 | public function canContain(AbstractBlock $block) |
|
77 | |||
78 | /** |
||
79 | * Returns true if block type can accept lines of text |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | 21 | public function acceptsLines() |
|
87 | |||
88 | /** |
||
89 | * Whether this is a code block |
||
90 | * |
||
91 | * @return bool |
||
92 | */ |
||
93 | 123 | public function isCode() |
|
97 | |||
98 | 204 | public function matchesNextLine(Cursor $cursor) |
|
102 | |||
103 | 237 | public function finalize(ContextInterface $context, $endLineNumber) |
|
104 | { |
||
105 | 237 | parent::finalize($context, $endLineNumber); |
|
106 | |||
107 | 237 | $this->tight = true; // tight by default |
|
108 | |||
109 | 237 | foreach ($this->children() as $item) { |
|
110 | // check for non-final list item ending with blank line: |
||
111 | 237 | if ($item->endsWithBlankLine() && $item !== $this->lastChild()) { |
|
112 | 18 | $this->tight = false; |
|
113 | 18 | break; |
|
114 | } |
||
115 | |||
116 | // Recurse into children of list item, to see if there are |
||
117 | // spaces between any of them: |
||
118 | 228 | foreach ($item->children() as $subItem) { |
|
119 | 222 | if ($subItem->endsWithBlankLine() && ($item !== $this->lastChild() || $subItem !== $item->lastChild())) { |
|
120 | 81 | $this->tight = false; |
|
121 | 179 | break; |
|
122 | } |
||
123 | 76 | } |
|
124 | 79 | } |
|
125 | 237 | } |
|
126 | |||
127 | /** |
||
128 | * @return bool |
||
129 | */ |
||
130 | 255 | public function isTight() |
|
134 | } |
||
135 |
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: