Passed
Push — master ( 3b6a73...d590ba )
by stéphane
02:55
created

NodeLitFolded   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 17
dl 0
loc 31
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getFinalString() 0 22 8
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
                $result .= $separator .$this->getChildValue($child, $indent);
39
            }
40
        }
41 1
        return $result;
42
    }
43
}