Completed
Push — master ( a5cd41...696772 )
by stéphane
04:51
created
yaml/Builder.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
      */
44 44
     private static function buildNodeList(NodeList $node, &$parent)
45 45
     {
46
-        if ($node->type & (Y::RAW | Y::LITTERALS)) {
46
+        if ($node->type & (Y::RAW|Y::LITTERALS)) {
47 47
             return self::buildLitteral($node, $node->type);
48 48
         }
49 49
         $p = $parent;
50 50
         switch ($node->type) {
51 51
             case Y::MAPPING: //fall through
52 52
             case Y::SET:      $p = new \StdClass; break;
53
-            case Y::SEQUENCE: $p = [];break;
53
+            case Y::SEQUENCE: $p = []; break;
54 54
             // case Y::KEY: $p = $parent;break;
55 55
         }
56 56
         $out = null;
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     private static function buildNode(Node $node, &$parent)
79 79
     {
80 80
         extract((array) $node, EXTR_REFS);
81
-        if ($type & (Y::REF_DEF | Y::REF_CALL)) {
81
+        if ($type&(Y::REF_DEF|Y::REF_CALL)) {
82 82
             if (is_object($value)) {
83 83
                 $tmp = self::build($value, $parent) ?? $parent;
84 84
             } else {
@@ -193,15 +193,15 @@  discard block
 block discarded – undo
193 193
     {
194 194
         self::$_root = new YamlObject();
195 195
         $childTypes = $list->getTypes();
196
-        $isaMapping  = (bool) (Y::KEY | Y::MAPPING) & $childTypes;
196
+        $isaMapping  = (bool) (Y::KEY|Y::MAPPING)&$childTypes;
197 197
         $isaSequence = (bool) Y::ITEM & $childTypes;
198 198
         $isaSet      = (bool) Y::SET_VALUE & $childTypes;
199 199
         if ($isaMapping && $isaSequence) {
200 200
             throw new \ParseError(sprintf(self::INVALID_DOCUMENT, $key));
201 201
         } else {
202 202
             switch (true) {
203
-                case $isaSequence: $list->type = Y::SEQUENCE;break;
204
-                case $isaSet:      $list->type = Y::SET;break;
203
+                case $isaSequence: $list->type = Y::SEQUENCE; break;
204
+                case $isaSet:      $list->type = Y::SET; break;
205 205
                 default:           $list->type = Y::MAPPING;
206 206
             }
207 207
         }
@@ -236,15 +236,15 @@  discard block
 block discarded – undo
236 236
                 $lines[] = self::buildLitteral($child->value, $type);
237 237
             } else {
238 238
                 $prefix = '';
239
-                if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
239
+                if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
240 240
                     $prefix = "\n";
241 241
                 }
242 242
                 $lines[] = $prefix.$child->value;
243 243
             }
244 244
         }
245
-        if ($type & Y::RAW)         return implode('',   $lines);
246
-        if ($type & Y::LITT)        return implode("\n", $lines);
247
-        if ($type & Y::LITT_FOLDED) return implode(' ',  $lines);
245
+        if ($type&Y::RAW)         return implode('', $lines);
246
+        if ($type&Y::LITT)        return implode("\n", $lines);
247
+        if ($type&Y::LITT_FOLDED) return implode(' ', $lines);
248 248
         return '';
249 249
     }
250 250
 
Please login to merge, or discard this patch.
Braces   +29 added lines, -11 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
      */
30 30
     private static function build(object $node, &$parent = null)
31 31
     {
32
-        if ($node instanceof NodeList) return self::buildNodeList($node, $parent);
32
+        if ($node instanceof NodeList) {
33
+            return self::buildNodeList($node, $parent);
34
+        }
33 35
         return self::buildNode($node, $parent);
34 36
     }
35 37
 
@@ -84,7 +86,9 @@  discard block
 block discarded – undo
84 86
             } else {
85 87
                 $tmp = $node->getPhpValue();
86 88
             }
87
-            if ($type === Y::REF_DEF) self::$_root->addReference($identifier, $tmp);
89
+            if ($type === Y::REF_DEF) {
90
+                self::$_root->addReference($identifier, $tmp);
91
+            }
88 92
             return self::$_root->getReference($identifier);
89 93
         }
90 94
         $typesActions = [Y::COMMENT   => 'buildComment',
@@ -169,10 +173,14 @@  discard block
 block discarded – undo
169 173
         }
170 174
         $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE);
171 175
         foreach ($_root->value as $child) {
172
-            if ($child->type & Y::DOC_START) $totalDocStart++;
176
+            if ($child->type & Y::DOC_START) {
177
+                $totalDocStart++;
178
+            }
173 179
             //if 0 or 1 DOC_START = we are still in first document
174 180
             $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;
175
-            if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList();
181
+            if (!isset($documents[$currentDoc])) {
182
+                $documents[$currentDoc] = new NodeList();
183
+            }
176 184
             $documents[$currentDoc]->push($child);
177 185
         }
178 186
         $content = array_map([self::class, 'buildDocument'], $documents, array_keys($documents));
@@ -242,9 +250,15 @@  discard block
 block discarded – undo
242 250
                 $lines[] = $prefix.$child->value;
243 251
             }
244 252
         }
245
-        if ($type & Y::RAW)         return implode('',   $lines);
246
-        if ($type & Y::LITT)        return implode("\n", $lines);
247
-        if ($type & Y::LITT_FOLDED) return implode(' ',  $lines);
253
+        if ($type & Y::RAW) {
254
+            return implode('',   $lines);
255
+        }
256
+        if ($type & Y::LITT) {
257
+            return implode("\n", $lines);
258
+        }
259
+        if ($type & Y::LITT_FOLDED) {
260
+            return implode(' ',  $lines);
261
+        }
248 262
         return '';
249 263
     }
250 264
 
@@ -259,8 +273,9 @@  discard block
 block discarded – undo
259 273
     private function buildSetKey(Node $node, $parent):void
260 274
     {
261 275
         $key = json_encode(self::build($node->value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
262
-        if (empty($key))
263
-        throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1);
276
+        if (empty($key)) {
277
+                throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1);
278
+        }
264 279
         $parent->{$key} = null;
265 280
     }
266 281
 
@@ -299,8 +314,11 @@  discard block
 block discarded – undo
299 314
         }
300 315
         //TODO: have somewhere a list of common tags and their treatment
301 316
         if (in_array($node->identifier, ['!binary', '!str'])) {
302
-            if ($node->value->value instanceof NodeList) $node->value->value->type = Y::RAW;
303
-            else $node->value->type = Y::RAW;
317
+            if ($node->value->value instanceof NodeList) {
318
+                $node->value->value->type = Y::RAW;
319
+            } else {
320
+                $node->value->type = Y::RAW;
321
+            }
304 322
         }
305 323
         $val = is_null($node->value) ? null : self::build(/** @scrutinizer ignore-type */ $node->value, $node);
306 324
         return new Tag($node->identifier, $val);
Please login to merge, or discard this patch.