Conditions | 7 |
Paths | 6 |
Total Lines | 26 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 7 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
31 | 1674 | public function parse(ContextInterface $context, Cursor $cursor) |
|
32 | { |
||
33 | 1674 | if ($cursor->isIndented()) { |
|
34 | 177 | return false; |
|
35 | } |
||
36 | |||
37 | 1620 | if (!($context->getContainer() instanceof Paragraph)) { |
|
38 | 1620 | return false; |
|
39 | } |
||
40 | |||
41 | 288 | if (count($context->getContainer()->getStrings()) !== 1) { |
|
42 | 45 | return false; |
|
43 | } |
||
44 | |||
45 | 285 | $match = RegexHelper::matchAll('/^(?:=+|-+) *$/', $cursor->getLine(), $cursor->getFirstNonSpacePosition()); |
|
46 | 285 | if ($match === null) { |
|
47 | 246 | return false; |
|
48 | } |
||
49 | |||
50 | 39 | $level = $match[0][0] === '=' ? 1 : 2; |
|
51 | 39 | $strings = $context->getContainer()->getStrings(); |
|
52 | |||
53 | 39 | $context->replaceContainerBlock(new Heading($level, reset($strings) ?: '')); |
|
54 | |||
55 | 39 | return true; |
|
56 | } |
||
57 | } |
||
58 |