Passed
Push — master ( dd077a...e2a7b5 )
by stéphane
05:33
created

NodeLit::getFinalString()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 22
rs 9.1111
c 0
b 0
f 0
cc 6
nc 4
nop 2
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 NodeLit extends NodeLiterals
12
{
13
    /**
14
     * Gets the final string.
15
     *
16
     * @param      NodeList  $list   The list
17
     *
18
     * @return     string    The final string.
19
     */
20
    public function getFinalString(NodeList $value, $refIndent = null):string
21
    {
22
        $result = '';
23
        $list = $value->filterComment();
24
        if ($this->identifier !== '+') {
25
             self::litteralStripTrailing($list);
26
        }
27
        if ($list->count()) {
28
            $list->setIteratorMode(NodeList::IT_MODE_DELETE);
29
            $first  = $list->shift();
30
            $indent = $refIndent ?? $first->indent;
31
            $result = $this->getChildValue($first, $indent);
32
            foreach ($list as $child) {
33
                $value = "\n";
34
                if (!($child instanceof NodeBlank)) {
35
                    $newIndent = $indent > 0 ? $child->indent - $indent : 0;
36
                    $value .= str_repeat(' ', $newIndent).$this->getChildValue($child, $indent);
37
                }
38
                $result .= $value;
39
            }
40
        }
41
        return $result;
42
    }
43
}