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