LiteralFolded   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B getFinalString() 0 22 8
1
<?php
2
3
namespace Dallgoot\Yaml\Nodes;
4
5
use Dallgoot\Yaml\NodeList;
6
use Dallgoot\Yaml\Nodes\Generic\Literals;
7
8
/**
9
 *
10
 * @author  Stéphane Rebai <[email protected]>
11
 * @license Apache 2.0
12
 * @link    https://github.com/dallgoot/yaml
13
 */
14
class LiteralFolded extends Literals
15
{
16
    /**
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 Blank) {
36 1
                    $separator = "\n";
37
                }
38 1
                $result .= $separator . $this->getChildValue($child, $indent);
39
            }
40
        }
41 1
        return $result;
42
    }
43
}
44