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

Literal   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getFinalString() 0 22 6
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 Literal extends Literals
14
{
15 1
    public function getFinalString(NodeList $list, int $refIndent = null):string
16
    {
17 1
        $result = '';
18 1
        $list = $list->filterComment();
19 1
        if ($this->identifier !== '+') {
20 1
             self::litteralStripTrailing($list);
21
        }
22 1
        if ($list->count()) {
23 1
            $list->setIteratorMode(NodeList::IT_MODE_DELETE);
24 1
            $first  = $list->shift();
25 1
            $indent = $refIndent ?? $first->indent;
26 1
            $result = $this->getChildValue($first, $indent);
27 1
            foreach ($list as $child) {
28 1
                $value = "\n";
29 1
                if (!($child instanceof Blank)) {
30 1
                    $newIndent = $indent > 0 ? $child->indent - $indent : 0;
31 1
                    $value .= str_repeat(' ', $newIndent).$this->getChildValue($child, $indent);
32
                }
33 1
                $result .= $value;
34
            }
35
        }
36 1
        return $result;
37
    }
38
}