Completed
Push — master ( 519791...2b7f2d )
by stéphane
02:16
created
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/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/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
 
@@ -62,7 +64,9 @@  discard block
 block discarded – undo
62 64
             } else {
63 65
                 $tmp = $node->getPhpValue();
64 66
             }
65
-            if ($type === Y::REF_DEF) self::$_root->addReference($identifier, $tmp);
67
+            if ($type === Y::REF_DEF) {
68
+                self::$_root->addReference($identifier, $tmp);
69
+            }
66 70
             return self::$_root->getReference($identifier);
67 71
         }
68 72
         switch ($type) {
@@ -72,8 +76,9 @@  discard block
 block discarded – undo
72 76
             case Y::KEY:  self::buildKey($node, $parent); return;
73 77
             case Y::SET_KEY:
74 78
                 $key = json_encode(self::build($value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
75
-                if (empty($key))
76
-                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
79
+                if (empty($key)) {
80
+                                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
81
+                }
77 82
                 $parent->{$key} = null;
78 83
                 return;
79 84
             case Y::SET_VALUE:
@@ -92,8 +97,11 @@  discard block
 block discarded – undo
92 97
                     $parent->addTag($identifier); return;
93 98
                 } else {//TODO: have somewhere a list of common tags and their treatment
94 99
                     if (in_array($identifier, ['!binary', '!str'])) {
95
-                        if ($value->value instanceof NodeList) $value->value->type = Y::RAW;
96
-                        else $value->type = Y::RAW;
100
+                        if ($value->value instanceof NodeList) {
101
+                            $value->value->type = Y::RAW;
102
+                        } else {
103
+                            $value->type = Y::RAW;
104
+                        }
97 105
                     }
98 106
                     $val = is_null($value) ? null : self::build(/** @scrutinizer ignore-type */ $value, $node);
99 107
                     return new Tag($identifier, $val);
@@ -162,10 +170,14 @@  discard block
 block discarded – undo
162 170
         }
163 171
         $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE);
164 172
         foreach ($_root->value as $child) {
165
-            if ($child->type & Y::DOC_START) $totalDocStart++;
173
+            if ($child->type & Y::DOC_START) {
174
+                $totalDocStart++;
175
+            }
166 176
             //if 0 or 1 DOC_START = we are still in first document
167 177
             $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;
168
-            if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList();
178
+            if (!isset($documents[$currentDoc])) {
179
+                $documents[$currentDoc] = new NodeList();
180
+            }
169 181
             $documents[$currentDoc]->push($child);
170 182
         }
171 183
         $content = array_map([self::class, 'buildDocument'], $documents, array_keys($documents));
Please login to merge, or discard this patch.
yaml/Loader.php 1 patch
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -87,7 +87,9 @@  discard block
 block discarded – undo
87 87
     {
88 88
         $source = $this->content ?? preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE);
89 89
         //TODO : be more permissive on $strContent values
90
-        if (!is_array($source) || !count($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT);
90
+        if (!is_array($source) || !count($source)) {
91
+            throw new \Exception(self::EXCEPTION_LINE_SPLIT);
92
+        }
91 93
         $previous = $root = new Node();
92 94
         $emptyLines = [];
93 95
         try {
@@ -99,7 +101,9 @@  discard block
 block discarded – undo
99 101
             foreach ($gen() as $lineNb => $lineString) {
100 102
                 $n = new Node($lineString, $lineNb);
101 103
                 if ($n->type & (Y::LITTERALS|Y::BLANK)) {
102
-                    if ($this->onSpecialType($n, $previous, $emptyLines)) continue;
104
+                    if ($this->onSpecialType($n, $previous, $emptyLines)) {
105
+                        continue;
106
+                    }
103 107
                 } else {
104 108
                     foreach ($emptyLines as $blankNode) {
105 109
                         $blankNode->getParent()->add($blankNode);
@@ -113,11 +117,15 @@  discard block
 block discarded – undo
113 117
                         break;
114 118
                     default: $target = $previous;
115 119
                 }
116
-                if ($this->onContextType($n, $target, $lineString)) continue;
120
+                if ($this->onContextType($n, $target, $lineString)) {
121
+                    continue;
122
+                }
117 123
                 $target->add($n);
118 124
                 $previous = $n;
119 125
             }
120
-            if ($this->debug === 2) echo "\033[33mParsed Structure\033[0m\n",var_export($root, true);
126
+            if ($this->debug === 2) {
127
+                echo "\033[33mParsed Structure\033[0m\n",var_export($root, true);
128
+            }
121 129
             $out = Builder::buildContent($root, $this->debug);
122 130
             return $out;
123 131
         } catch (\Error|\Exception|\ParseError $e) {
@@ -137,8 +145,12 @@  discard block
 block discarded – undo
137 145
     {
138 146
         $deepest = $previous->getDeepestNode();
139 147
         if ($n->type & Y::BLANK) {
140
-            if ($previous->type & Y::SCALAR) $emptyLines[] = $n->setParent($previous->getParent());
141
-            if ($deepest->type & Y::LITTERALS) $emptyLines[] = $n->setParent($deepest);
148
+            if ($previous->type & Y::SCALAR) {
149
+                $emptyLines[] = $n->setParent($previous->getParent());
150
+            }
151
+            if ($deepest->type & Y::LITTERALS) {
152
+                $emptyLines[] = $n->setParent($deepest);
153
+            }
142 154
             return true;
143 155
         }
144 156
         return false;
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
@@ -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.