Conditions | 6 |
Paths | 3 |
Total Lines | 25 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
29 | 9 | public function parse(string $match, InlineParserContext $inlineContext): bool |
|
30 | { |
||
31 | 9 | $container = $inlineContext->getContainer(); |
|
32 | |||
33 | // Checkbox must come at the beginning of the first paragraph of the list item |
||
34 | 9 | if ($container->hasChildren() || ! ($container instanceof Paragraph && $container->parent() && $container->parent() instanceof ListItem)) { |
|
35 | 3 | return false; |
|
36 | } |
||
37 | |||
38 | 9 | $cursor = $inlineContext->getCursor(); |
|
39 | 9 | $oldState = $cursor->saveState(); |
|
40 | |||
41 | 9 | $cursor->advanceBy(3); |
|
42 | |||
43 | 9 | if ($cursor->getNextNonSpaceCharacter() === null) { |
|
44 | 3 | $cursor->restoreState($oldState); |
|
45 | |||
46 | 3 | return false; |
|
47 | } |
||
48 | |||
49 | 9 | $isChecked = $match !== '[ ]'; |
|
50 | |||
51 | 9 | $container->appendChild(new TaskListItemMarker($isChecked)); |
|
52 | |||
53 | 9 | return true; |
|
54 | } |
||
56 |