Completed
Push — master ( b9ada3...d95e42 )
by stéphane
01:58
created
yaml/Builder.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
      *
76 76
      * @return mixed    The parent (object|array) or a string representing the NodeList.
77 77
      */
78
-    private static function buildNodeList(NodeList $node, &$parent=null)
78
+    private static function buildNodeList(NodeList $node, &$parent = null)
79 79
     {
80 80
         $node->forceType();
81
-        if ($node->type & (Y::RAW | Y::LITTERALS)) {
81
+        if ($node->type & (Y::RAW|Y::LITTERALS)) {
82 82
             return self::buildLitteral($node, (int) $node->type);
83 83
         }
84
-        $action = function ($child, &$parent, &$out) {
84
+        $action = function($child, &$parent, &$out) {
85 85
             self::build($child, $out);
86 86
         };
87 87
         if ($node->type & (Y::COMPACT_MAPPING|Y::MAPPING|Y::SET)) {
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
             $out = $parent ?? [];
91 91
         } else {
92 92
             $out = '';
93
-            $action = function ($child, &$parent, &$out) {
93
+            $action = function($child, &$parent, &$out) {
94 94
                 if ($child->type & (Y::SCALAR|Y::QUOTED)) {
95 95
                     if ($parent) {
96 96
                         $parent->setText(self::build($child));
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
         ];
130 130
         if (isset($actions[$type])) {
131 131
             return self::{$actions[$type]}($node, $parent);
132
-        } elseif ($type & Y::COMMENT) {
132
+        } elseif ($type&Y::COMMENT) {
133 133
             self::$_root->addComment($line, $value);
134
-        } elseif ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) {
134
+        } elseif ($type&(Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) {
135 135
             return self::buildNodeList($value, $parent);
136
-        } elseif ($type & (Y::REF_DEF | Y::REF_CALL)) {
136
+        } elseif ($type&(Y::REF_DEF|Y::REF_CALL)) {
137 137
             return self::handleReference($node, $parent);
138 138
         } elseif ($value instanceof Node) {
139 139
             return self::buildNode($value, $parent);
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      * @throws \ParseError if Key has no name(identifier) Note: empty string is allowed
160 160
      * @return null
161 161
      */
162
-    private static function buildKey(Node $node, &$parent=null)
162
+    private static function buildKey(Node $node, &$parent = null)
163 163
     {
164 164
         extract((array) $node, EXTR_REFS);
165 165
         if (is_null($identifier)) {
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
         $numKeys = array_filter(array_keys($ref), 'is_int');
207 207
         $key = count($numKeys) > 0 ? max($numKeys) + 1 : 0;
208 208
         if ($value instanceof Node) {
209
-            if($value->type & Y::KEY) {
209
+            if ($value->type & Y::KEY) {
210 210
                 self::buildKey($node->value, $parent);
211 211
                 return;
212 212
             } elseif ($value->type & Y::ITEM) {
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
         //remove trailing blank
236 236
         while ($list->top()->type & Y::BLANK) $list->pop();
237 237
         $result = '';
238
-        $separator = [ Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type];
238
+        $separator = [Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type];
239 239
         foreach ($list as $child) {
240 240
             if ($child->value instanceof NodeList) {
241 241
                 $result .= self::buildLitteral($child->value, $type).$separator;
242 242
             } else {
243 243
                 $val = $child->type & (Y::SCALAR|Y::BLANK) ? $child->value : substr($child->raw, $refIndent);
244
-                if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
244
+                if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
245 245
                     if ($result[-1] === $separator)
246 246
                         $result[-1] = "\n";
247 247
                     if ($result[-1] === "\n")
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
     private function buildSetKey(Node $node, &$parent)
266 266
     {
267 267
         $built = is_object($node->value) ? self::build($node->value) : null;
268
-        $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built;
268
+        $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built;
269 269
         $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
270 270
         if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1);
271 271
         $parent->{trim($key, '\'" ')} = null;
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
     {
282 282
         $prop = array_keys(get_object_vars($parent));
283 283
         $key = end($prop);
284
-        if ($node->value->type & (Y::ITEM|Y::KEY )) {
284
+        if ($node->value->type & (Y::ITEM|Y::KEY)) {
285 285
             $node->value = new NodeList($node->value);
286 286
         }
287 287
         $parent->{$key} = self::build($node->value);
Please login to merge, or discard this patch.