Passed
Push — master ( f81cc4...5281ab )
by stéphane
04:50
created

LiteralFolded::getFinalString()   B

Complexity

Conditions 8
Paths 4

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 8

Importance

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