Passed
Branch master (f496ba)
by stéphane
02:11
created

Builder   F

Complexity

Total Complexity 68

Size/Duplication

Total Lines 209
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 133
dl 0
loc 209
rs 2.96
c 0
b 0
f 0
wmc 68

9 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 4 2
B buildDLL() 0 25 10
A buildItem() 0 7 3
A litteral() 0 18 6
B buildDocument() 0 29 10
B buildContent() 0 21 8
D buildNode() 0 43 21
A getChildrenTypes() 0 7 2
A buildKey() 0 13 6

How to fix   Complexity   

Complex Class

Complex classes like Builder often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Builder, and based on these observations, apply Extract Interface, too.

1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Dallgoot\Yaml;
4
5
use Dallgoot\Yaml\{Node as Node, Types as T, YamlObject, Tag, Builder};
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Dallgoot\Yaml\Tag. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
Bug introduced by
This use statement conflicts with another class in this namespace, Dallgoot\Yaml\Builder. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
Bug introduced by
This use statement conflicts with another class in this namespace, Dallgoot\Yaml\YamlObject. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
Bug introduced by
This use statement conflicts with another class in this namespace, Dallgoot\Yaml\Node. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use \SplDoublyLinkedList as DLL;
7
8
/**
0 ignored issues
show
Coding Style introduced by
Doc comment is empty
Loading history...
9
 *
10
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
11
class Builder
12
{
13
    private static $root;
0 ignored issues
show
Coding Style introduced by
Private member variable "root" must be prefixed with an underscore
Loading history...
14
    private static $debug;
0 ignored issues
show
Coding Style introduced by
Private member variable "debug" must be prefixed with an underscore
Loading history...
15
16
    const ERROR_NO_KEYNAME = self::class.": key has NO IDENTIFIER on line %d";
17
    const INVALID_DOCUMENT = self::class.": DOCUMENT %d can NOT be a mapping AND a sequence";
18
19
20
    private static function build(object $node, &$parent = null)
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Private method name "Builder::build" must be prefixed with an underscore
Loading history...
21
    {
22
        if ($node instanceof DLL) return self::buildDLL($node, $parent);
1 ignored issue
show
Coding Style introduced by
Inline control structures are discouraged
Loading history...
23
        return self::buildNode($node, $parent);
24
    }
25
26
    private static function buildDLL(DLL $node, &$parent)
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Private method name "Builder::buildDLL" must be prefixed with an underscore
Loading history...
27
    {
28
        $type = property_exists($node, "type") ? $node->type : null;
29
        if (in_array($type, [T::RAW, T::LITTERAL, T::LITTERAL_FOLDED])) {
30
            return self::litteral($node, $type);
31
        }
32
        $p = $parent;
33
        switch ($type) {
34
            case T::MAPPING: //fall through
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
35
            case T::SET:      $p = new \StdClass;break;
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
36
            case T::SEQUENCE: $p = [];break;
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
37
            // case T::KEY: $p = $parent;break;
38
        }
39
        $out = null;
40
        foreach ($node as $child) {
41
            $result = self::build($child, $p);
42
            if (!is_null($result)) {
43
                if (is_string($result)) {
44
                    $out .= $result.' ';
45
                } else {
46
                    return $result;
47
                }
48
            }
49
        }
50
        return is_null($out) ? $p : rtrim($out);
51
    }
52
53
    private static function buildNode(Node $node, &$parent)
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Private method name "Builder::buildNode" must be prefixed with an underscore
Loading history...
54
    {
55
        list($line, $type, $value, $identifier) = [$node->line, $node->type, $node->value, $node->identifier];
56
        switch ($type) {
57
            case T::COMMENT: self::$root->addComment($line, $value);return;
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
58
            case T::DIRECTIVE: return;//TODO
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
59
            case T::ITEM: self::buildItem($value, $parent);return;
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
60
            case T::KEY:  self::buildKey($node, $parent);return;
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
61
            case T::REF_DEF: //fall through
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
62
            case T::REF_CALL://TODO: self::build returns what ?
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
63
                $tmp = is_object($value) ? self::build($value, $parent) : $node->getPhpValue();
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::build($value, $parent) targeting Dallgoot\Yaml\Builder::build() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
64
                if ($type === T::REF_DEF) self::$root->addReference($identifier, $tmp);
1 ignored issue
show
Coding Style introduced by
Inline control structures are discouraged
Loading history...
65
                return self::$root->getReference($identifier);
66
            case T::SET_KEY:
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
67
                $key = json_encode(self::build($value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::build($value, $parent) targeting Dallgoot\Yaml\Builder::build() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
It seems like $value can also be of type null and string; however, parameter $node of Dallgoot\Yaml\Builder::build() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
                $key = json_encode(self::build(/** @scrutinizer ignore-type */ $value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
Loading history...
68
                if (empty($key))
1 ignored issue
show
Coding Style introduced by
Inline control structures are discouraged
Loading history...
69
                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
70
                $parent->{$key} = null;
71
                return;
72
            case T::SET_VALUE:
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
73
                $prop = array_keys(get_object_vars($parent));
74
                $key = end($prop);
75
                if (property_exists($value, "type") && in_array($value->type, [T::ITEM, T::MAPPING])) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
76
                    $p = $value->type === T::ITEM  ? [] : new \StdClass;
77
                    self::build($value, $p);
78
                } else {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
79
                    $p = self::build($value, $parent->{$key});
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $p is correct as self::build($value, $parent->$key) targeting Dallgoot\Yaml\Builder::build() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
80
                }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
81
                $parent->{$key} = $p;
82
                return;
83
            case T::TAG:
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
84
                if ($parent === self::$root) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
85
                    $parent->addTag($identifier);return;
86
                } else {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
87
                    if (in_array($identifier, ['!binary', '!str'])) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
88
                        if ($value->value instanceof DLL) $value->value->type = T::RAW;
1 ignored issue
show
Bug introduced by
The property type does not seem to exist on SplDoublyLinkedList.
Loading history...
Bug introduced by
The property value does not seem to exist on SplDoublyLinkedList.
Loading history...
Coding Style introduced by
Inline control structures are discouraged
Loading history...
89
                        else $value->type = T::RAW;
2 ignored issues
show
Coding Style introduced by
Inline control structures are discouraged
Loading history...
Coding Style introduced by
Line indented incorrectly; expected 20 spaces, found 24
Loading history...
90
                    }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
91
                    $val = is_null($value) ? null : self::build($value, $node);
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type string; however, parameter $node of Dallgoot\Yaml\Builder::build() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

91
                    $val = is_null($value) ? null : self::build(/** @scrutinizer ignore-type */ $value, $node);
Loading history...
92
                    return new Tag($identifier, $val);
93
                }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
94
            default:
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
95
                return is_object($value) ? self::build($value, $parent) : $node->getPhpValue();
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::build($value, $parent) targeting Dallgoot\Yaml\Builder::build() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
96
        }
97
    }
98
99
    /**
100
     * Builds a key and set the property + value to the parent given
101
     *
102
     * @param      Node   $node    The node
3 ignored issues
show
Coding Style introduced by
Expected 9 spaces after parameter type; 3 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 6
Loading history...
103
     * @param      object|array  $parent  The parent
3 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 6
Loading history...
104
     * @throws \ParseError if Key has no name(identifier)
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
105
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
106
    private static function buildKey($node, &$parent):void
0 ignored issues
show
Coding Style introduced by
Private method name "Builder::buildKey" must be prefixed with an underscore
Loading history...
107
    {
108
        list($identifier, $value) = [$node->identifier, $node->value];
109
        if (is_null($identifier)) {
110
            throw new \ParseError(sprintf(self::ERROR_NO_KEYNAME, $node->line));
111
        } else {
112
            if ($value instanceof Node && in_array($value->type, [T::KEY, T::ITEM])) {
113
                $parent->{$identifier} = $value->type === T::KEY ? new \StdClass : [];
114
                self::build($value, $parent->{$identifier});
115
            } elseif (is_object($value)) {
116
                $parent->{$identifier} = self::build($value, $parent->{$identifier});
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $parent->$identifier is correct as self::build($value, $parent->$identifier) targeting Dallgoot\Yaml\Builder::build() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
117
            } else {
118
                $parent->{$identifier} = $node->getPhpValue();
119
            }
120
        }
121
    }
122
123
    private static function buildItem($value, &$parent):void
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Private method name "Builder::buildItem" must be prefixed with an underscore
Loading history...
124
    {
125
        if ($value instanceof Node && $value->type === T::KEY) {
126
            $parent[$value->identifier] = self::build($value->value, $parent[$value->identifier]);
0 ignored issues
show
Bug introduced by
It seems like $value->value can also be of type null and string; however, parameter $node of Dallgoot\Yaml\Builder::build() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

126
            $parent[$value->identifier] = self::build(/** @scrutinizer ignore-type */ $value->value, $parent[$value->identifier]);
Loading history...
Bug introduced by
Are you sure the assignment to $parent[$value->identifier] is correct as self::build($value->valu...nt[$value->identifier]) targeting Dallgoot\Yaml\Builder::build() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
127
        } else {
128
            $index = count($parent);
129
            $parent[$index] = self::build($value, $parent[$index]);
130
        }
131
    }
132
133
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $debug should have a doc-comment as per coding-style.
Loading history...
134
     * Builds a file.  check multiple documents & split if more than one documents
135
     *
136
     * @param      Node   $root   The root node
3 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 3 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 3 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 6
Loading history...
137
     * @return     array|YamlObject  list of documents or juste one.
1 ignored issue
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 5
Loading history...
138
     */
139
    public static function buildContent(Node $root, int $debug)
140
    {
141
        self::$debug = $debug;
142
        $totalDocStart = 0;
143
        $documents = [];
144
        if ($root->value instanceof Node) {
145
            $q = new DLL;
146
            $q->push($root->value);
147
            return [self::buildDocument($q, 0)];
148
        }
149
        $root->value->setIteratorMode(DLL::IT_MODE_DELETE);
0 ignored issues
show
Bug introduced by
The method setIteratorMode() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

149
        $root->value->/** @scrutinizer ignore-call */ 
150
                      setIteratorMode(DLL::IT_MODE_DELETE);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
150
        foreach ($root->value as $child) {
151
            if ($child->type === T::DOC_START) $totalDocStart++;
1 ignored issue
show
Coding Style introduced by
Inline control structures are discouraged
Loading history...
152
            //if 0 or 1 DOC_START = we are still in first document
153
            $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;
154
            if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new DLL();
1 ignored issue
show
Coding Style introduced by
Inline control structures are discouraged
Loading history...
155
            $documents[$currentDoc]->push($child);
156
        }
157
        $debug >= 2 && var_dump($documents);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($documents) looks like debug code. Are you sure you do not want to remove it?
Loading history...
158
        $content = array_map([self::class, 'buildDocument'], $documents, array_keys($documents));
159
        return count($content) === 1 ? $content[0] : $content;
160
    }
161
162
    private static function buildDocument(DLL $list, int $key):YamlObject
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Private method name "Builder::buildDocument" must be prefixed with an underscore
Loading history...
163
    {
164
        self::$root = new YamlObject();
165
        $childTypes = self::getChildrenTypes($list);
166
        $isMapping  = count(array_intersect($childTypes, [T::KEY, T::MAPPING])) > 0;
167
        $isSequence = in_array(T::ITEM, $childTypes);
168
        $isSet      = in_array(T::SET_VALUE, $childTypes);
169
        if ($isMapping && $isSequence) {
170
            throw new \ParseError(sprintf(self::INVALID_DOCUMENT, $key));
171
        } else {
172
            switch (true) {
173
                case $isSequence: $list->type = T::SEQUENCE;break;
1 ignored issue
show
Bug introduced by
The property type does not seem to exist on SplDoublyLinkedList.
Loading history...
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
174
                case $isSet: $list->type = T::SET;break;
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
175
                case $isMapping://fall through
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
176
                default:$list->type = T::MAPPING;
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
177
            }
178
        }
179
        self::$debug >= 3 && var_dump(self::$root, $list);
0 ignored issues
show
Security Debugging Code introduced by
var_dump(self::root, $list) looks like debug code. Are you sure you do not want to remove it?
Loading history...
180
        $string = '';
181
        foreach ($list as $child) {
182
            $result = self::build($child, self::$root);
183
            if (is_string($result)) {
184
                $string .= $result.' ';
185
            }
186
        }
187
        if (!empty($string)) {
188
            self::$root->setText(rtrim($string));
189
        }
190
        return self::$root;
191
    }
192
193
    private static function litteral(DLL $children, $type):string
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Private method name "Builder::litteral" must be prefixed with an underscore
Loading history...
194
    {
195
        $children->rewind();
196
        $refIndent = $children->current()->indent;
197
        $separator = $type === T::RAW ? '' : "\n";
198
        $action = function ($c) { return $c->value; };
0 ignored issues
show
Coding Style introduced by
Opening brace must be the last content on the line
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
199
        if ($type === T::LITTERAL_FOLDED) {
200
            $separator = ' ';
201
            $action = function ($c) use ($refIndent) {
202
                return $c->indent > $refIndent || $c->type === T::EMPTY ? "\n".$c->value : $c->value;
203
            };
204
        }
205
        $tmp = [];
206
        $children->rewind();
207
        foreach ($children as $child) {
208
            $tmp[] = $action($child);
209
        }
210
        return implode($separator, $tmp);
211
    }
212
213
    private static function getChildrenTypes(DLL $children):array
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Private method name "Builder::getChildrenTypes" must be prefixed with an underscore
Loading history...
214
    {
215
        $types = [];
216
        foreach ($children as $child) {
217
            $types[] = $child->type;
218
        }
219
        return array_unique($types);
220
    }
221
}
222