Completed
Push — master ( c6ecf3...3eacba )
by stéphane
02:27
created

NodeLitFolded::getFinalString()   B

Complexity

Conditions 9
Paths 4

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 9.0101

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 26
ccs 19
cts 20
cp 0.95
rs 8.0555
c 0
b 0
f 0
cc 9
nc 4
nop 2
crap 9.0101
1
<?php
2
3
namespace Dallgoot\Yaml;
4
5
/**
6
 *
7
 * @author  Stéphane Rebai <[email protected]>
8
 * @license Apache 2.0
9
 * @link    TODO : url to specific online doc
10
 */
11
class NodeLitFolded extends NodeLiterals
12
{
13
    /**
14
     * @param NodeList $list The children
15
     *
16
     * @return string    The litteral.
17
     * @todo   Example 6.1. Indentation Spaces  spaces must be considered as content,
18
     *          Whend indent is reduced : do we insert a line break too ?
19
     */
20 1
    public function getFinalString(NodeList $value, int $refIndent = null):string
21
    {
22 1
        $result = '';
23 1
        $list = $value->filterComment();
24 1
        if ($this->identifier !== '+') {
25 1
             self::litteralStripLeading($list);
26 1
             self::litteralStripTrailing($list);
27
        }
28 1
        if ($list->count()) {
29 1
            $refSeparator = ' ';
30 1
            $first = $list->shift();
31 1
            $indent = $refIndent ?? $first->indent;
32 1
            $result = $this->getChildValue($first, $indent);
33 1
            foreach ($list as $child) {
34 1
                $separator = ($result && $result[-1] === "\n") ? '' : $refSeparator;
35 1
                if($child->indent > $indent || $child instanceof NodeBlank) {
36 1
                    $separator = "\n";
37
                }
38 1
                $val = $this->getChildValue($child, $indent);
39 1
                if ($child->value instanceof NodeList) {
40
                    $val = "\n".$this->getFinalString($child->value, $indent);
41
                }
42 1
                $result .= $separator .$val;
43
            }
44
        }
45 1
        return $result;
46
    }
47
}