@@ -238,7 +238,6 @@  | 
                                                    ||
| 238 | 238 | /**  | 
                                                        
| 239 | 239 | * Builds a litteral (folded or not) or any NodeList that has YAML::RAW type (like a multiline value)  | 
                                                        
| 240 | 240 | *  | 
                                                        
| 241 | - * @param NodeList $children The children  | 
                                                        |
| 242 | 241 | * @param integer $type The type  | 
                                                        
| 243 | 242 | *  | 
                                                        
| 244 | 243 | * @return string The litteral.  | 
                                                        
@@ -37,7 +37,7 @@ discard block  | 
                                                    ||
| 37 | 37 | $q = new NodeList;  | 
                                                        
| 38 | 38 | $q->push($_root->value);  | 
                                                        
| 39 | 39 | self::$_root = new YamlObject;  | 
                                                        
| 40 | - $tmp = self::buildNodeList($q, self::$_root);  | 
                                                        |
| 40 | + $tmp = self::buildNodeList($q, self::$_root);  | 
                                                        |
| 41 | 41 | return $tmp;  | 
                                                        
| 42 | 42 | }  | 
                                                        
| 43 | 43 | $_root->value instanceof NodeList && $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE);  | 
                                                        
@@ -82,13 +82,13 @@ discard block  | 
                                                    ||
| 82 | 82 | *  | 
                                                        
| 83 | 83 | * @return mixed The parent (object|array) or a string representing the NodeList.  | 
                                                        
| 84 | 84 | */  | 
                                                        
| 85 | - private static function buildNodeList(NodeList $node, &$parent=null)  | 
                                                        |
| 85 | + private static function buildNodeList(NodeList $node, &$parent = null)  | 
                                                        |
| 86 | 86 |      { | 
                                                        
| 87 | 87 | $node->forceType();  | 
                                                        
| 88 | -        if ($node->type & (Y::RAW | Y::LITTERALS)) { | 
                                                        |
| 88 | +        if ($node->type & (Y::RAW|Y::LITTERALS)) { | 
                                                        |
| 89 | 89 | return self::buildLitteral($node, (int) $node->type);  | 
                                                        
| 90 | 90 | }  | 
                                                        
| 91 | -        $action = function ($child, &$parent, &$out) { | 
                                                        |
| 91 | +        $action = function($child, &$parent, &$out) { | 
                                                        |
| 92 | 92 | self::build($child, $out);  | 
                                                        
| 93 | 93 | };  | 
                                                        
| 94 | 94 |          if ($node->type & (Y::COMPACT_MAPPING|Y::MAPPING|Y::SET)) { | 
                                                        
@@ -97,7 +97,7 @@ discard block  | 
                                                    ||
| 97 | 97 | $out = $parent ?? [];  | 
                                                        
| 98 | 98 |          } else { | 
                                                        
| 99 | 99 | $out = '';  | 
                                                        
| 100 | -            $action = function ($child, &$parent, &$out) { | 
                                                        |
| 100 | +            $action = function($child, &$parent, &$out) { | 
                                                        |
| 101 | 101 |                  if ($child->type & (Y::SCALAR|Y::QUOTED)) { | 
                                                        
| 102 | 102 |                      if ($parent) { | 
                                                        
| 103 | 103 | $parent->setText(self::build($child));  | 
                                                        
@@ -127,7 +127,7 @@ discard block  | 
                                                    ||
| 127 | 127 | private static function buildNode(Node $node, &$parent)  | 
                                                        
| 128 | 128 |      { | 
                                                        
| 129 | 129 | extract((array) $node, EXTR_REFS);  | 
                                                        
| 130 | -        if ($type & (Y::REF_DEF | Y::REF_CALL)) { | 
                                                        |
| 130 | +        if ($type&(Y::REF_DEF|Y::REF_CALL)) { | 
                                                        |
| 131 | 131 |              if (is_object($value)) { | 
                                                        
| 132 | 132 | $tmp = self::build($value, $parent) ?? $parent;  | 
                                                        
| 133 | 133 |              } else { | 
                                                        
@@ -136,10 +136,10 @@ discard block  | 
                                                    ||
| 136 | 136 | if ($type === Y::REF_DEF) self::$_root->addReference($identifier, $tmp);  | 
                                                        
| 137 | 137 | return self::$_root->getReference($identifier);  | 
                                                        
| 138 | 138 | }  | 
                                                        
| 139 | -        if ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) { | 
                                                        |
| 139 | +        if ($type&(Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) { | 
                                                        |
| 140 | 140 | return self::buildNodeList($node->value, $parent);  | 
                                                        
| 141 | 141 | }  | 
                                                        
| 142 | - if ($type & Y::COMMENT) self::$_root->addComment($node->line, $node->value);  | 
                                                        |
| 142 | + if ($type&Y::COMMENT) self::$_root->addComment($node->line, $node->value);  | 
                                                        |
| 143 | 143 | $typesActions = [Y::DIRECTIVE => 'buildDirective',  | 
                                                        
| 144 | 144 | Y::ITEM => 'buildItem',  | 
                                                        
| 145 | 145 | Y::KEY => 'buildKey',  | 
                                                        
@@ -162,7 +162,7 @@ discard block  | 
                                                    ||
| 162 | 162 | * @throws \ParseError if Key has no name(identifier) Note: empty string is allowed  | 
                                                        
| 163 | 163 | * @return null  | 
                                                        
| 164 | 164 | */  | 
                                                        
| 165 | - private static function buildKey(Node $node, &$parent=null)  | 
                                                        |
| 165 | + private static function buildKey(Node $node, &$parent = null)  | 
                                                        |
| 166 | 166 |      { | 
                                                        
| 167 | 167 | extract((array) $node, EXTR_REFS);  | 
                                                        
| 168 | 168 |          if (is_null($identifier)) { | 
                                                        
@@ -180,7 +180,7 @@ discard block  | 
                                                    ||
| 180 | 180 | }  | 
                                                        
| 181 | 181 |              if ($value instanceof NodeList) { | 
                                                        
| 182 | 182 | $childTypes = $value->getTypes();  | 
                                                        
| 183 | -                if (is_null($value->type) && $childTypes & Y::SCALAR && !($childTypes & Y::COMMENT)) { | 
                                                        |
| 183 | +                if (is_null($value->type) && $childTypes&Y::SCALAR && !($childTypes&Y::COMMENT)) { | 
                                                        |
| 184 | 184 | $result = self::buildLitteral($value, Y::LITT_FOLDED);  | 
                                                        
| 185 | 185 |                  } else { | 
                                                        
| 186 | 186 | $result = self::buildNodeList($value);  | 
                                                        
@@ -209,7 +209,7 @@ discard block  | 
                                                    ||
| 209 | 209 | */  | 
                                                        
| 210 | 210 | private static function buildItem(Node $node, &$parent)  | 
                                                        
| 211 | 211 |      { | 
                                                        
| 212 | - extract((array) $node, EXTR_REFS);//var_dump(__METHOD__);  | 
                                                        |
| 212 | + extract((array) $node, EXTR_REFS); //var_dump(__METHOD__);  | 
                                                        |
| 213 | 213 |          if (!is_array($parent) && !($parent instanceof \ArrayIterator)) { | 
                                                        
| 214 | 214 |              throw new \Exception("parent must be an Iterable not ".(is_object($parent) ? get_class($parent) : gettype($parent)), 1); | 
                                                        
| 215 | 215 | }  | 
                                                        
@@ -217,7 +217,7 @@ discard block  | 
                                                    ||
| 217 | 217 | $numKeys = array_filter(array_keys($ref), 'is_int');  | 
                                                        
| 218 | 218 | $key = count($numKeys) > 0 ? max($numKeys) + 1 : 0;  | 
                                                        
| 219 | 219 |          if ($value instanceof Node) { | 
                                                        
| 220 | -            if($value->type & Y::KEY) { | 
                                                        |
| 220 | +            if ($value->type & Y::KEY) { | 
                                                        |
| 221 | 221 | self::buildKey($node->value, $parent);  | 
                                                        
| 222 | 222 | return;  | 
                                                        
| 223 | 223 |              } elseif ($value->type & Y::ITEM) { | 
                                                        
@@ -254,14 +254,14 @@ discard block  | 
                                                    ||
| 254 | 254 | }  | 
                                                        
| 255 | 255 | $result = '';  | 
                                                        
| 256 | 256 | $separator = '';  | 
                                                        
| 257 | - if ($type & Y::LITT) $separator = "\n";  | 
                                                        |
| 258 | - if ($type & Y::LITT_FOLDED) $separator = ' ';  | 
                                                        |
| 257 | + if ($type&Y::LITT) $separator = "\n";  | 
                                                        |
| 258 | + if ($type&Y::LITT_FOLDED) $separator = ' ';  | 
                                                        |
| 259 | 259 |          foreach ($list as $child) { | 
                                                        
| 260 | 260 |              if ($child->value instanceof NodeList) { | 
                                                        
| 261 | 261 | $result .= self::buildLitteral($child->value, $type).$separator;  | 
                                                        
| 262 | 262 |              } else { | 
                                                        
| 263 | 263 | $val = $child->type & (Y::SCALAR|Y::BLANK) ? $child->value : substr($child->raw, $refIndent);  | 
                                                        
| 264 | -                if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { | 
                                                        |
| 264 | +                if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { | 
                                                        |
| 265 | 265 | if ($result[-1] === $separator)  | 
                                                        
| 266 | 266 | $result[-1] = "\n";  | 
                                                        
| 267 | 267 | if ($result[-1] === "\n")  | 
                                                        
@@ -285,7 +285,7 @@ discard block  | 
                                                    ||
| 285 | 285 | private function buildSetKey(Node $node, &$parent)  | 
                                                        
| 286 | 286 |      { | 
                                                        
| 287 | 287 | $built = is_object($node->value) ? self::build($node->value) : null;  | 
                                                        
| 288 | - $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built;  | 
                                                        |
| 288 | + $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built;  | 
                                                        |
| 289 | 289 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);  | 
                                                        
| 290 | 290 |          // if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); | 
                                                        
| 291 | 291 |          $parent->{trim($key, '\'" ')} = null; | 
                                                        
@@ -42,10 +42,14 @@ discard block  | 
                                                    ||
| 42 | 42 | }  | 
                                                        
| 43 | 43 | $_root->value instanceof NodeList && $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE);  | 
                                                        
| 44 | 44 |          foreach ($_root->value as $child) { | 
                                                        
| 45 | - if ($child->type & Y::DOC_START) $totalDocStart++;  | 
                                                        |
| 45 | +            if ($child->type & Y::DOC_START) { | 
                                                        |
| 46 | + $totalDocStart++;  | 
                                                        |
| 47 | + }  | 
                                                        |
| 46 | 48 | //if 0 or 1 DOC_START = we are still in first document  | 
                                                        
| 47 | 49 | $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;  | 
                                                        
| 48 | - if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList();  | 
                                                        |
| 50 | +            if (!isset($documents[$currentDoc])) { | 
                                                        |
| 51 | + $documents[$currentDoc] = new NodeList();  | 
                                                        |
| 52 | + }  | 
                                                        |
| 49 | 53 | $documents[$currentDoc]->push($child);  | 
                                                        
| 50 | 54 | }  | 
                                                        
| 51 | 55 | $content = [];  | 
                                                        
@@ -70,7 +74,9 @@ discard block  | 
                                                    ||
| 70 | 74 | */  | 
                                                        
| 71 | 75 | private static function build(object $node, &$parent = null)  | 
                                                        
| 72 | 76 |      { | 
                                                        
| 73 | - if ($node instanceof NodeList) return self::buildNodeList($node, $parent);  | 
                                                        |
| 77 | +        if ($node instanceof NodeList) { | 
                                                        |
| 78 | + return self::buildNodeList($node, $parent);  | 
                                                        |
| 79 | + }  | 
                                                        |
| 74 | 80 | return self::buildNode($node, $parent);  | 
                                                        
| 75 | 81 | }  | 
                                                        
| 76 | 82 | |
@@ -133,13 +139,17 @@ discard block  | 
                                                    ||
| 133 | 139 |              } else { | 
                                                        
| 134 | 140 | $tmp = Node2PHP::get($node);  | 
                                                        
| 135 | 141 | }  | 
                                                        
| 136 | - if ($type === Y::REF_DEF) self::$_root->addReference($identifier, $tmp);  | 
                                                        |
| 142 | +            if ($type === Y::REF_DEF) { | 
                                                        |
| 143 | + self::$_root->addReference($identifier, $tmp);  | 
                                                        |
| 144 | + }  | 
                                                        |
| 137 | 145 | return self::$_root->getReference($identifier);  | 
                                                        
| 138 | 146 | }  | 
                                                        
| 139 | 147 |          if ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) { | 
                                                        
| 140 | 148 | return self::buildNodeList($node->value, $parent);  | 
                                                        
| 141 | 149 | }  | 
                                                        
| 142 | - if ($type & Y::COMMENT) self::$_root->addComment($node->line, $node->value);  | 
                                                        |
| 150 | +        if ($type & Y::COMMENT) { | 
                                                        |
| 151 | + self::$_root->addComment($node->line, $node->value);  | 
                                                        |
| 152 | + }  | 
                                                        |
| 143 | 153 | $typesActions = [Y::DIRECTIVE => 'buildDirective',  | 
                                                        
| 144 | 154 | Y::ITEM => 'buildItem',  | 
                                                        
| 145 | 155 | Y::KEY => 'buildKey',  | 
                                                        
@@ -254,18 +264,24 @@ discard block  | 
                                                    ||
| 254 | 264 | }  | 
                                                        
| 255 | 265 | $result = '';  | 
                                                        
| 256 | 266 | $separator = '';  | 
                                                        
| 257 | - if ($type & Y::LITT) $separator = "\n";  | 
                                                        |
| 258 | - if ($type & Y::LITT_FOLDED) $separator = ' ';  | 
                                                        |
| 267 | +        if ($type & Y::LITT) { | 
                                                        |
| 268 | + $separator = "\n";  | 
                                                        |
| 269 | + }  | 
                                                        |
| 270 | +        if ($type & Y::LITT_FOLDED) { | 
                                                        |
| 271 | + $separator = ' ';  | 
                                                        |
| 272 | + }  | 
                                                        |
| 259 | 273 |          foreach ($list as $child) { | 
                                                        
| 260 | 274 |              if ($child->value instanceof NodeList) { | 
                                                        
| 261 | 275 | $result .= self::buildLitteral($child->value, $type).$separator;  | 
                                                        
| 262 | 276 |              } else { | 
                                                        
| 263 | 277 | $val = $child->type & (Y::SCALAR|Y::BLANK) ? $child->value : substr($child->raw, $refIndent);  | 
                                                        
| 264 | 278 |                  if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { | 
                                                        
| 265 | - if ($result[-1] === $separator)  | 
                                                        |
| 266 | - $result[-1] = "\n";  | 
                                                        |
| 267 | - if ($result[-1] === "\n")  | 
                                                        |
| 268 | - $result .= $val;  | 
                                                        |
| 279 | +                    if ($result[-1] === $separator) { | 
                                                        |
| 280 | + $result[-1] = "\n";  | 
                                                        |
| 281 | + }  | 
                                                        |
| 282 | +                    if ($result[-1] === "\n") { | 
                                                        |
| 283 | + $result .= $val;  | 
                                                        |
| 284 | + }  | 
                                                        |
| 269 | 285 | continue;  | 
                                                        
| 270 | 286 | }  | 
                                                        
| 271 | 287 | $result .= $val.$separator;  | 
                                                        
@@ -32,7 +32,7 @@ discard block  | 
                                                    ||
| 32 | 32 | * Create the Node object and parses $nodeString IF not null (else assume a root type Node)  | 
                                                        
| 33 | 33 | *  | 
                                                        
| 34 | 34 | * @param string|null $nodeString The node string  | 
                                                        
| 35 | - * @param int|null $line The line  | 
                                                        |
| 35 | + * @param integer $line The line  | 
                                                        |
| 36 | 36 | */  | 
                                                        
| 37 | 37 | public function __construct($nodeString = null, $line = 0)  | 
                                                        
| 38 | 38 |      { | 
                                                        
@@ -221,7 +221,7 @@ discard block  | 
                                                    ||
| 221 | 221 | * Process when a "key: value" syntax is found in the parsed string  | 
                                                        
| 222 | 222 | * Note : key is match 1, value is match 2 as per regex from R::KEY  | 
                                                        
| 223 | 223 | *  | 
                                                        
| 224 | - * @param array $matches The matches provided by 'preg_match' function in Node::parse  | 
                                                        |
| 224 | + * @param string[] $matches The matches provided by 'preg_match' function in Node::parse  | 
                                                        |
| 225 | 225 | */  | 
                                                        
| 226 | 226 | private function onKey(array $matches)  | 
                                                        
| 227 | 227 |      { | 
                                                        
@@ -40,18 +40,18 @@  | 
                                                    ||
| 40 | 40 | public function forceType()  | 
                                                        
| 41 | 41 |      { | 
                                                        
| 42 | 42 |          if (is_null($this->type)) { | 
                                                        
| 43 | - $childTypes = $this->getTypes();  | 
                                                        |
| 44 | -            if ($childTypes & (Y::KEY|Y::SET_KEY)) { | 
                                                        |
| 45 | -                if ($childTypes & Y::ITEM) { | 
                                                        |
| 43 | + $childTypes = $this->getTypes();  | 
                                                        |
| 44 | +            if ($childTypes&(Y::KEY|Y::SET_KEY)) { | 
                                                        |
| 45 | +                if ($childTypes&Y::ITEM) { | 
                                                        |
| 46 | 46 | // TODO: replace the document index in HERE ----------v  | 
                                                        
| 47 | 47 | throw new \ParseError(self::class.": Error conflicting types found");  | 
                                                        
| 48 | 48 |                  } else { | 
                                                        
| 49 | 49 | $this->type = Y::MAPPING;  | 
                                                        
| 50 | 50 | }  | 
                                                        
| 51 | 51 |              } else { | 
                                                        
| 52 | -                if ($childTypes & Y::ITEM) { | 
                                                        |
| 52 | +                if ($childTypes&Y::ITEM) { | 
                                                        |
| 53 | 53 | $this->type = Y::SEQUENCE;  | 
                                                        
| 54 | -                } elseif (!($childTypes & Y::COMMENT)) { | 
                                                        |
| 54 | +                } elseif (!($childTypes&Y::COMMENT)) { | 
                                                        |
| 55 | 55 | $this->type = Y::LITT_FOLDED;  | 
                                                        
| 56 | 56 | }  | 
                                                        
| 57 | 57 | }  |