Passed
Push — master ( 419cde...d38a64 )
by stéphane
02:51
created
yaml/Regex.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,8 +40,9 @@
 block discarded – undo
40 40
         $matchCanonical = preg_match($canonical, $v);
41 41
         $matchSpaced    = preg_match($spaced, $v);
42 42
         $matchIso       = preg_match($iso8601, $v);
43
-        if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso))
44
-          throw new \Exception("Regex date error");
43
+        if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso)) {
44
+                  throw new \Exception("Regex date error");
45
+        }
45 46
 
46 47
         return $matchDate || $matchCanonical || $matchSpaced || $matchIso;
47 48
     }
Please login to merge, or discard this patch.
yaml/YamlObject.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,8 +40,12 @@
 block discarded – undo
40 40
     {
41 41
         $prop = get_object_vars($this);
42 42
         unset($prop["__yaml__object__api"]);
43
-        if (count($prop) > 0) return $prop;
44
-        if (count($this) > 0) return iterator_to_array($this);
43
+        if (count($prop) > 0) {
44
+            return $prop;
45
+        }
46
+        if (count($this) > 0) {
47
+            return iterator_to_array($this);
48
+        }
45 49
         return $this->__yaml__object__api->value;
46 50
     }
47 51
 }
Please login to merge, or discard this patch.
yaml/Node.php 1 patch
Braces   +45 added lines, -15 removed lines patch added patch discarded remove patch
@@ -55,7 +55,9 @@  discard block
 block discarded – undo
55 55
      */
56 56
     public function getParent(int $indent = null):Node
57 57
     {
58
-        if (!is_int($indent)) return $this->parent ?? $this;
58
+        if (!is_int($indent)) {
59
+            return $this->parent ?? $this;
60
+        }
59 61
         $cursor = $this;
60 62
         while ($cursor instanceof Node && $cursor->indent >= $indent) {
61 63
             $cursor = $cursor->parent;
@@ -146,8 +148,12 @@  discard block
 block discarded – undo
146 148
             $type = R::isProperlyQuoted($nodeValue) ? Y\QUOTED : Y\PARTIAL;
147 149
             return [$type, $nodeValue];
148 150
         }
149
-        if (in_array($first, ['{', '[']))      return $this->onObject($nodeValue);
150
-        if (in_array($first, ['!', '&', '*'])) return $this->onNodeAction($nodeValue);
151
+        if (in_array($first, ['{', '['])) {
152
+            return $this->onObject($nodeValue);
153
+        }
154
+        if (in_array($first, ['!', '&', '*'])) {
155
+            return $this->onNodeAction($nodeValue);
156
+        }
151 157
         switch ($first) {
152 158
             case '#': return [Y\COMMENT, ltrim($v)];
153 159
             case "-": return $this->onHyphen($nodeValue);
@@ -199,9 +205,15 @@  discard block
 block discarded – undo
199 205
     private function onObject($value):array
200 206
     {
201 207
         json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
202
-        if (json_last_error() === JSON_ERROR_NONE)  return [Y\JSON, $value];
203
-        if (preg_match(R::MAPPING, $value))         return [Y\COMPACT_MAPPING, $value];
204
-        if (preg_match(R::SEQUENCE, $value))        return [Y\COMPACT_SEQUENCE, $value];
208
+        if (json_last_error() === JSON_ERROR_NONE) {
209
+            return [Y\JSON, $value];
210
+        }
211
+        if (preg_match(R::MAPPING, $value)) {
212
+            return [Y\COMPACT_MAPPING, $value];
213
+        }
214
+        if (preg_match(R::SEQUENCE, $value)) {
215
+            return [Y\COMPACT_SEQUENCE, $value];
216
+        }
205 217
         return [Y\PARTIAL, $value];
206 218
     }
207 219
 
@@ -216,7 +228,9 @@  discard block
 block discarded – undo
216 228
     {
217 229
         if (substr($nodeValue, 0, 3) === '---') {
218 230
             $rest = trim(substr($nodeValue, 3));
219
-            if (empty($rest)) return [Y\DOC_START, null];
231
+            if (empty($rest)) {
232
+                return [Y\DOC_START, null];
233
+            }
220 234
             $n = new Node($rest, $this->line);
221 235
             $n->indent = $this->indent + 4;
222 236
             return [Y\DOC_START, $n->setParent($this)];
@@ -259,9 +273,15 @@  discard block
 block discarded – undo
259 273
     public function getPhpValue()
260 274
     {
261 275
         $v = $this->value;
262
-        if (is_null($v)) return null;
263
-        if ($this->type & (Y\REF_CALL | Y\SCALAR)) return self::getScalar($v);
264
-        if ($this->type & (Y\COMPACT_MAPPING | Y\COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type);
276
+        if (is_null($v)) {
277
+            return null;
278
+        }
279
+        if ($this->type & (Y\REF_CALL | Y\SCALAR)) {
280
+            return self::getScalar($v);
281
+        }
282
+        if ($this->type & (Y\COMPACT_MAPPING | Y\COMPACT_SEQUENCE)) {
283
+            return self::getCompact(substr($v, 1, -1), $this->type);
284
+        }
265 285
         switch ($this->type) {
266 286
             case Y\JSON:   return json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR);
267 287
             case Y\QUOTED: return substr($v, 1, -1);
@@ -290,9 +310,15 @@  discard block
 block discarded – undo
290 310
                   '-.inf' => -INF,
291 311
                   '.nan'  => NAN
292 312
         ];
293
-        if (isset($types[strtolower($v)])) return $types[strtolower($v)];
294
-        if (R::isDate($v))   return date_create($v);
295
-        if (R::isNumber($v)) return self::getNumber($v);
313
+        if (isset($types[strtolower($v)])) {
314
+            return $types[strtolower($v)];
315
+        }
316
+        if (R::isDate($v)) {
317
+            return date_create($v);
318
+        }
319
+        if (R::isNumber($v)) {
320
+            return self::getNumber($v);
321
+        }
296 322
         return strval($v);
297 323
     }
298 324
 
@@ -305,8 +331,12 @@  discard block
 block discarded – undo
305 331
      */
306 332
     private static function getNumber(string $v)
307 333
     {
308
-        if (preg_match("/^(0o\d+)$/i", $v))      return intval(base_convert($v, 8, 10));
309
-        if (preg_match("/^(0x[\da-f]+)$/i", $v)) return intval(base_convert($v, 16, 10));
334
+        if (preg_match("/^(0o\d+)$/i", $v)) {
335
+            return intval(base_convert($v, 8, 10));
336
+        }
337
+        if (preg_match("/^(0x[\da-f]+)$/i", $v)) {
338
+            return intval(base_convert($v, 16, 10));
339
+        }
310 340
         // TODO: remove these if not needed
311 341
         // if preg_match("/^([\d.]+e[-+]\d{1,2})$/", $v)://fall through
312 342
         // if preg_match("/^([-+]?(?:\d+|\d*.\d+))$/", $v):
Please login to merge, or discard this patch.
yaml/Compact.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,8 +27,12 @@
 block discarded – undo
27 27
     public function jsonSerialize()
28 28
     {
29 29
         $prop = get_object_vars($this);
30
-        if (count($prop) > 0) return $prop;
31
-        if (count($this) > 0) return iterator_to_array($this);
30
+        if (count($prop) > 0) {
31
+            return $prop;
32
+        }
33
+        if (count($this) > 0) {
34
+            return iterator_to_array($this);
35
+        }
32 36
     }
33 37
 
34 38
     public static function wrap($arrayOrObject)
Please login to merge, or discard this patch.
yaml/Dumper.php 1 patch
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,7 +21,9 @@  discard block
 block discarded – undo
21 21
 
22 22
     public function __construct(int $options = null)
23 23
     {
24
-        if (is_int($options)) self::$options = $options;
24
+        if (is_int($options)) {
25
+            self::$options = $options;
26
+        }
25 27
     }
26 28
 
27 29
     /**
@@ -36,7 +38,9 @@  discard block
 block discarded – undo
36 38
      */
37 39
     public static function toString($dataType, int $options = null):string
38 40
     {
39
-        if (is_null($dataType)) throw new \Exception(self::class.": No content to convert to Yaml", 1);
41
+        if (is_null($dataType)) {
42
+            throw new \Exception(self::class.": No content to convert to Yaml", 1);
43
+        }
40 44
         self::$options = is_int($options) ? $options : self::OPTIONS;
41 45
         self::$result = new DLL;
42 46
         self::$result->setIteratorMode(DLL::IT_MODE_FIFO|DLL::IT_MODE_DELETE);
@@ -74,8 +78,12 @@  discard block
 block discarded – undo
74 78
         if (is_scalar($dataType)) {
75 79
             switch (gettype($dataType)) {
76 80
                 case 'boolean': return $dataType ? 'true' : 'false';
77
-                case 'float': if (is_infinite((float) $dataType)) return $dataType > 0 ? '.inf' : '-.inf';
78
-                case 'double': if (is_nan((float) $dataType)) return '.nan';
81
+                case 'float': if (is_infinite((float) $dataType)) {
82
+                    return $dataType > 0 ? '.inf' : '-.inf';
83
+                }
84
+                case 'double': if (is_nan((float) $dataType)) {
85
+                    return '.nan';
86
+                }
79 87
                 default:
80 88
                     return $dataType;
81 89
             }
Please login to merge, or discard this patch.
yaml/Loader.php 1 patch
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -84,9 +84,13 @@  discard block
 block discarded – undo
84 84
     public function parse($strContent = null)
85 85
     {
86 86
         $source = $this->content;
87
-        if (is_null($source)) $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE);
87
+        if (is_null($source)) {
88
+            $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE);
89
+        }
88 90
         //TODO : be more permissive on $strContent values
89
-        if (!is_array($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT);
91
+        if (!is_array($source)) {
92
+            throw new \Exception(self::EXCEPTION_LINE_SPLIT);
93
+        }
90 94
         $previous = $root = new Node();
91 95
         $emptyLines = [];
92 96
         $specialTypes = Y\LITTERALS|Y\BLANK;
@@ -115,7 +119,9 @@  discard block
 block discarded – undo
115 119
                         case -1: $previous->getParent($n->indent)->add($n);break;
116 120
                         case 0:  $previous->getParent()->add($n);break;
117 121
                         default:
118
-                            if ($this->onDeepestType($n, $previous, $lineString)) continue 2;
122
+                            if ($this->onDeepestType($n, $previous, $lineString)) {
123
+                                continue 2;
124
+                            }
119 125
                             $previous->add($n);
120 126
                     }
121 127
                     $previous = $n;
@@ -155,8 +161,12 @@  discard block
 block discarded – undo
155 161
             }
156 162
         }
157 163
         if ($n->type & Y\BLANK) {
158
-            if ($previous->type & Y\SCALAR) $emptyLines[] = $n->setParent($previous->getParent());
159
-            if ($deepest->type & Y\LITTERALS) $emptyLines[] = $n->setParent($deepest);
164
+            if ($previous->type & Y\SCALAR) {
165
+                $emptyLines[] = $n->setParent($previous->getParent());
166
+            }
167
+            if ($deepest->type & Y\LITTERALS) {
168
+                $emptyLines[] = $n->setParent($deepest);
169
+            }
160 170
             return true;
161 171
         }
162 172
         return false;
Please login to merge, or discard this patch.
yaml/Builder.php 1 patch
Braces   +20 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
 
23 23
     private static function build(object $node, &$parent = null)
24 24
     {
25
-        if ($node instanceof NodeList) return self::buildNodeList($node, $parent);
25
+        if ($node instanceof NodeList) {
26
+            return self::buildNodeList($node, $parent);
27
+        }
26 28
         return self::buildNode($node, $parent);
27 29
     }
28 30
 
@@ -74,12 +76,15 @@  discard block
 block discarded – undo
74 76
                     $tmp = $node->getPhpValue();
75 77
                 }
76 78
                 // $tmp = is_object($value) ? self::build($value, $parent) : $node->getPhpValue();
77
-                if ($type === Y\REF_DEF) self::$_root->addReference($identifier, $tmp);
79
+                if ($type === Y\REF_DEF) {
80
+                    self::$_root->addReference($identifier, $tmp);
81
+                }
78 82
                 return self::$_root->getReference($identifier);
79 83
             case Y\SET_KEY:
80 84
                 $key = json_encode(self::build($value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
81
-                if (empty($key))
82
-                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
85
+                if (empty($key)) {
86
+                                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
87
+                }
83 88
                 $parent->{$key} = null;
84 89
                 return;
85 90
             case Y\SET_VALUE:
@@ -98,8 +103,11 @@  discard block
 block discarded – undo
98 103
                     $parent->addTag($identifier); return;
99 104
                 } else {//TODO: have somewhere a list of common tags and their treatment
100 105
                     if (in_array($identifier, ['!binary', '!str'])) {
101
-                        if ($value->value instanceof NodeList) $value->value->type = Y\RAW;
102
-                        else $value->type = Y\RAW;
106
+                        if ($value->value instanceof NodeList) {
107
+                            $value->value->type = Y\RAW;
108
+                        } else {
109
+                            $value->type = Y\RAW;
110
+                        }
103 111
                     }
104 112
                     $val = is_null($value) ? null : self::build(/** @scrutinizer ignore-type */ $value, $node);
105 113
                     return new Tag($identifier, $val);
@@ -168,10 +176,14 @@  discard block
 block discarded – undo
168 176
         }
169 177
         $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE);
170 178
         foreach ($_root->value as $child) {
171
-            if ($child->type & Y\DOC_START) $totalDocStart++;
179
+            if ($child->type & Y\DOC_START) {
180
+                $totalDocStart++;
181
+            }
172 182
             //if 0 or 1 DOC_START = we are still in first document
173 183
             $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;
174
-            if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList();
184
+            if (!isset($documents[$currentDoc])) {
185
+                $documents[$currentDoc] = new NodeList();
186
+            }
175 187
             $documents[$currentDoc]->push($child);
176 188
         }
177 189
         $content = array_map([self::class, 'buildDocument'], $documents, array_keys($documents));
Please login to merge, or discard this patch.