Conditions | 4 |
Paths | 8 |
Total Lines | 22 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 4 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | 3 | public function convert(ElementInterface $element) |
|
23 | { |
||
24 | // If parent is an ol, use numbers, otherwise, use dashes |
||
25 | 3 | $tagname = $element->getParent()->getTagName(); |
|
26 | |||
27 | // Add spaces to start for nested list items |
||
28 | 3 | $level = $element->getListItemLevel($element); |
|
29 | |||
30 | 3 | $items = explode("\n", trim($element->getValue())); |
|
31 | |||
32 | 3 | $paragraphPrefix = str_repeat(' ', $level + 1); |
|
33 | |||
34 | 3 | $value = implode("\n" . $paragraphPrefix, $items); |
|
35 | |||
36 | 3 | $number = (integer) $element->getSiblingPosition(); |
|
37 | |||
38 | // If list item is the first in a nested list, add a newline before it |
||
39 | 3 | $prefix = $level > 0 && $number === 1 ? "\n" : ''; |
|
40 | |||
41 | 3 | $position = $tagname === 'ol' ? $number . '. ' : '* '; |
|
42 | |||
43 | 3 | return $prefix . $position . trim($value) . "\n"; |
|
44 | } |
||
56 |