Completed
Push — master ( 519791...2b7f2d )
by stéphane
02:16
created
yaml/Node.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
     {
264 264
         $v = &$this->value;
265 265
         if (is_null($v)) return null;
266
-        if ($this->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($v);
267
-        if ($this->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type);
266
+        if ($this->type & (Y::REF_CALL|Y::SCALAR)) return self::getScalar($v);
267
+        if ($this->type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type);
268 268
         switch ($this->type) {
269 269
             case Y::JSON:   return json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR);
270 270
             case Y::QUOTED: return substr($v, 1, -1);
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
     {
321 321
         $out = new Compact();
322 322
         if ($type === Y::COMPACT_SEQUENCE) {
323
-            $f = function ($e) { return self::getScalar(trim($e));};
323
+            $f = function($e) { return self::getScalar(trim($e)); };
324 324
             //TODO : that's not robust enough, improve it
325 325
             foreach (array_map($f, explode(",", $mappingOrSeqString)) as $key => $value) {
326 326
                 $out[$key] = $value;
Please login to merge, or discard this patch.
Braces   +45 added lines, -15 removed lines patch added patch discarded remove patch
@@ -59,7 +59,9 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function getParent(int $indent = null):Node
61 61
     {
62
-        if (!is_int($indent)) return $this->parent ?? $this;
62
+        if (!is_int($indent)) {
63
+            return $this->parent ?? $this;
64
+        }
63 65
         $cursor = $this;
64 66
         while ($cursor instanceof Node && $cursor->indent >= $indent) {
65 67
             $cursor = $cursor->parent;
@@ -150,8 +152,12 @@  discard block
 block discarded – undo
150 152
             $type = R::isProperlyQuoted($nodeValue) ? Y::QUOTED : Y::PARTIAL;
151 153
             return [$type, $nodeValue];
152 154
         }
153
-        if (in_array($first, ['{', '[']))      return $this->onObject($nodeValue);
154
-        if (in_array($first, ['!', '&', '*'])) return $this->onNodeAction($nodeValue);
155
+        if (in_array($first, ['{', '['])) {
156
+            return $this->onObject($nodeValue);
157
+        }
158
+        if (in_array($first, ['!', '&', '*'])) {
159
+            return $this->onNodeAction($nodeValue);
160
+        }
155 161
         switch ($first) {
156 162
             case '#': return [Y::COMMENT, ltrim($v)];
157 163
             case "-": return $this->onHyphen($nodeValue);
@@ -203,9 +209,15 @@  discard block
 block discarded – undo
203 209
     private function onObject($value):array
204 210
     {
205 211
         json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
206
-        if (json_last_error() === JSON_ERROR_NONE)  return [Y::JSON, $value];
207
-        if (preg_match(R::MAPPING, $value))         return [Y::COMPACT_MAPPING, $value];
208
-        if (preg_match(R::SEQUENCE, $value))        return [Y::COMPACT_SEQUENCE, $value];
212
+        if (json_last_error() === JSON_ERROR_NONE) {
213
+            return [Y::JSON, $value];
214
+        }
215
+        if (preg_match(R::MAPPING, $value)) {
216
+            return [Y::COMPACT_MAPPING, $value];
217
+        }
218
+        if (preg_match(R::SEQUENCE, $value)) {
219
+            return [Y::COMPACT_SEQUENCE, $value];
220
+        }
209 221
         return [Y::PARTIAL, $value];
210 222
     }
211 223
 
@@ -220,7 +232,9 @@  discard block
 block discarded – undo
220 232
     {
221 233
         if (substr($nodeValue, 0, 3) === '---') {
222 234
             $rest = trim(substr($nodeValue, 3));
223
-            if (empty($rest)) return [Y::DOC_START, null];
235
+            if (empty($rest)) {
236
+                return [Y::DOC_START, null];
237
+            }
224 238
             $n = new Node($rest, $this->line);
225 239
             $n->indent = $this->indent + 4;
226 240
             return [Y::DOC_START, $n->setParent($this)];
@@ -262,9 +276,15 @@  discard block
 block discarded – undo
262 276
     public function getPhpValue()
263 277
     {
264 278
         $v = &$this->value;
265
-        if (is_null($v)) return null;
266
-        if ($this->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($v);
267
-        if ($this->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type);
279
+        if (is_null($v)) {
280
+            return null;
281
+        }
282
+        if ($this->type & (Y::REF_CALL | Y::SCALAR)) {
283
+            return self::getScalar($v);
284
+        }
285
+        if ($this->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) {
286
+            return self::getCompact(substr($v, 1, -1), $this->type);
287
+        }
268 288
         switch ($this->type) {
269 289
             case Y::JSON:   return json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR);
270 290
             case Y::QUOTED: return substr($v, 1, -1);
@@ -293,9 +313,15 @@  discard block
 block discarded – undo
293 313
                     '-.inf' => -INF,
294 314
                     '.nan'  => NAN
295 315
         ];
296
-        if (isset($types[strtolower($v)])) return $types[strtolower($v)];
297
-        if (R::isDate($v))   return date_create($v);
298
-        if (R::isNumber($v)) return self::getNumber($v);
316
+        if (isset($types[strtolower($v)])) {
317
+            return $types[strtolower($v)];
318
+        }
319
+        if (R::isDate($v)) {
320
+            return date_create($v);
321
+        }
322
+        if (R::isNumber($v)) {
323
+            return self::getNumber($v);
324
+        }
299 325
         return strval($v);
300 326
     }
301 327
 
@@ -308,8 +334,12 @@  discard block
 block discarded – undo
308 334
      */
309 335
     private static function getNumber(string $v)
310 336
     {
311
-        if (preg_match("/^(0o\d+)$/i", $v))      return intval(base_convert($v, 8, 10));
312
-        if (preg_match("/^(0x[\da-f]+)$/i", $v)) return intval(base_convert($v, 16, 10));
337
+        if (preg_match("/^(0o\d+)$/i", $v)) {
338
+            return intval(base_convert($v, 8, 10));
339
+        }
340
+        if (preg_match("/^(0x[\da-f]+)$/i", $v)) {
341
+            return intval(base_convert($v, 16, 10));
342
+        }
313 343
         // TODO: remove these if not needed
314 344
         // if preg_match("/^([\d.]+e[-+]\d{1,2})$/", $v)://fall through
315 345
         // if preg_match("/^([-+]?(?:\d+|\d*.\d+))$/", $v):
Please login to merge, or discard this patch.
yaml/Regex.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
         $matchSpaced    = preg_match($spaced, $v);
38 38
         $matchIso       = preg_match($iso8601, $v);
39 39
         if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso)) {
40
-                  throw new \Exception("Regex date error");
40
+                    throw new \Exception("Regex date error");
41 41
         }
42 42
 
43 43
         return $matchDate || $matchCanonical || $matchSpaced || $matchIso;
Please login to merge, or discard this patch.
yaml/YamlObject.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
     public function __call($funcName, $arguments)
33 33
     {
34 34
         $reflectAPI = new \ReflectionClass(get_class($this->__yaml__object__api));
35
-        $getName = function ($o) { return $o->name; };
35
+        $getName = function($o) { return $o->name; };
36 36
         $publicApi  = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PUBLIC));
37 37
         $privateApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PRIVATE));
38 38
         if (!in_array($funcName, $publicApi) && !in_array($funcName, $privateApi)) {
Please login to merge, or discard this patch.