Conditions | 7 |
Paths | 4 |
Total Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 7 |
Changes | 0 |
1 | <?php |
||
34 | 9 | public function parse(InlineParserContext $inlineContext): bool |
|
35 | { |
||
36 | 9 | $container = $inlineContext->getContainer(); |
|
37 | |||
38 | // Checkbox must come at the beginning of the first paragraph of the list item |
||
39 | 9 | if ($container->hasChildren() || !($container instanceof Paragraph && $container->parent() && $container->parent() instanceof ListItem)) { |
|
40 | 3 | return false; |
|
41 | } |
||
42 | |||
43 | 9 | $cursor = $inlineContext->getCursor(); |
|
44 | 9 | $oldState = $cursor->saveState(); |
|
45 | |||
46 | 9 | $m = $cursor->match('/\[[ xX]\]/'); |
|
47 | 9 | if ($m === null) { |
|
48 | 3 | return false; |
|
49 | } |
||
50 | |||
51 | 9 | if ($cursor->getNextNonSpaceCharacter() === null) { |
|
52 | 3 | $cursor->restoreState($oldState); |
|
53 | |||
54 | 3 | return false; |
|
55 | } |
||
56 | |||
57 | 9 | $isChecked = $m !== '[ ]'; |
|
58 | |||
59 | 9 | $container->appendChild(new TaskListItemMarker($isChecked)); |
|
60 | |||
61 | 9 | return true; |
|
62 | } |
||
63 | } |
||
64 |