Completed
Push — master ( f496ba...7a981c )
by stéphane
02:09
created
yaml/Loader.php 1 patch
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -74,9 +74,13 @@  discard block
 block discarded – undo
74 74
     public function parse($strContent = null)
75 75
     {
76 76
         $source = $this->content;
77
-        if (is_null($source)) $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE);
77
+        if (is_null($source)) {
78
+            $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE);
79
+        }
78 80
         //TODO : be more permissive on $strContent values
79
-        if (!is_array($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT);
81
+        if (!is_array($source)) {
82
+            throw new \Exception(self::EXCEPTION_LINE_SPLIT);
83
+        }
80 84
         $previous = $root = new Node();
81 85
         $emptyLines = [];
82 86
         $specialTypes = Y\LITTERALS | Y\BLANK;
@@ -93,7 +97,9 @@  discard block
 block discarded – undo
93 97
                     $deepest->parse($deepest->value.' '.ltrim($lineString));
94 98
                 } else {
95 99
                     if ($n->type & $specialTypes) {
96
-                        if ($this->onSpecialType($n, $parent, $previous, $emptyLines)) continue;
100
+                        if ($this->onSpecialType($n, $parent, $previous, $emptyLines)) {
101
+                            continue;
102
+                        }
97 103
                     }
98 104
                     foreach ($emptyLines as $key => $node) {
99 105
                         $node->getParent()->add($node);
@@ -104,7 +110,9 @@  discard block
 block discarded – undo
104 110
                     } elseif ($n->indent === $previous->indent) {
105 111
                         $parent = $previous->getParent();
106 112
                     } elseif ($n->indent > $previous->indent) {
107
-                        if ($this->onDeepestType($n, $parent, $previous, $lineString)) continue;
113
+                        if ($this->onDeepestType($n, $parent, $previous, $lineString)) {
114
+                            continue;
115
+                        }
108 116
                     }
109 117
                     $parent->add($n);
110 118
                     $previous = $n;
@@ -139,8 +147,12 @@  discard block
 block discarded – undo
139 147
             }
140 148
         }
141 149
         if ($n->type & Y\BLANK) {
142
-            if ($previous->type & Y\SCALAR) $emptyLines[] = $n->setParent($previous->getParent());
143
-            if ($deepest->type & Y\LITTERALS) $emptyLines[] = $n->setParent($deepest);
150
+            if ($previous->type & Y\SCALAR) {
151
+                $emptyLines[] = $n->setParent($previous->getParent());
152
+            }
153
+            if ($deepest->type & Y\LITTERALS) {
154
+                $emptyLines[] = $n->setParent($deepest);
155
+            }
144 156
             return true;
145 157
         }
146 158
         return false;
Please login to merge, or discard this patch.
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/Builder.php 1 patch
Braces   +20 added lines, -8 removed lines patch added patch discarded remove patch
@@ -19,7 +19,9 @@  discard block
 block discarded – undo
19 19
 
20 20
     private static function build(object $node, &$parent = null)
21 21
     {
22
-        if ($node instanceof DLL) return self::buildDLL($node, $parent);
22
+        if ($node instanceof DLL) {
23
+            return self::buildDLL($node, $parent);
24
+        }
23 25
         return self::buildNode($node, $parent);
24 26
     }
25 27
 
@@ -61,12 +63,15 @@  discard block
 block discarded – undo
61 63
             case Y\REF_DEF: //fall through
62 64
             case Y\REF_CALL://TODO: self::build returns what ?
63 65
                 $tmp = is_object($value) ? self::build($value, $parent) : $node->getPhpValue();
64
-                if ($type === Y\REF_DEF) self::$_root->addReference($identifier, $tmp);
66
+                if ($type === Y\REF_DEF) {
67
+                    self::$_root->addReference($identifier, $tmp);
68
+                }
65 69
                 return self::$_root->getReference($identifier);
66 70
             case Y\SET_KEY:
67 71
                 $key = json_encode(self::build($value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
68
-                if (empty($key))
69
-                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
72
+                if (empty($key)) {
73
+                                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
74
+                }
70 75
                 $parent->{$key} = null;
71 76
                 return;
72 77
             case Y\SET_VALUE:
@@ -85,8 +90,11 @@  discard block
 block discarded – undo
85 90
                     $parent->addTag($identifier);return;
86 91
                 } else {
87 92
                     if (in_array($identifier, ['!binary', '!str'])) {
88
-                        if ($value->value instanceof DLL) $value->value->type = Y\RAW;
89
-                        else $value->type = Y\RAW;
93
+                        if ($value->value instanceof DLL) {
94
+                            $value->value->type = Y\RAW;
95
+                        } else {
96
+                            $value->type = Y\RAW;
97
+                        }
90 98
                     }
91 99
                     $val = is_null($value) ? null : self::build($value, $node);
92 100
                     return new Tag($identifier, $val);
@@ -151,10 +159,14 @@  discard block
 block discarded – undo
151 159
         }
152 160
         $_root->value->setIteratorMode(DLL::IT_MODE_DELETE);
153 161
         foreach ($_root->value as $child) {
154
-            if ($child->type & Y\DOC_START) $totalDocStart++;
162
+            if ($child->type & Y\DOC_START) {
163
+                $totalDocStart++;
164
+            }
155 165
             //if 0 or 1 DOC_START = we are still in first document
156 166
             $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;
157
-            if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new DLL();
167
+            if (!isset($documents[$currentDoc])) {
168
+                $documents[$currentDoc] = new DLL();
169
+            }
158 170
             $documents[$currentDoc]->push($child);
159 171
         }
160 172
         $_debug >= 2 && var_dump($documents);//var_dump($documents);die("documents");
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):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($dataType)) return $dataType > 0 ? '.inf' : '-.inf';
78
-                case 'double': if (is_nan($dataType)) return '.nan';
81
+                case 'float': if (is_infinite($dataType)) {
82
+                    return $dataType > 0 ? '.inf' : '-.inf';
83
+                }
84
+                case 'double': if (is_nan($dataType)) {
85
+                    return '.nan';
86
+                }
79 87
                 default:
80 88
                     return $dataType;
81 89
             }
Please login to merge, or discard this patch.
yaml/Node.php 1 patch
Braces   +42 added lines, -14 removed lines patch added patch discarded remove patch
@@ -56,7 +56,9 @@  discard block
 block discarded – undo
56 56
      */
57 57
     public function getParent(int $indent = null):Node
58 58
     {
59
-        if (!is_int($indent)) return $this->parent ?? $this;
59
+        if (!is_int($indent)) {
60
+            return $this->parent ?? $this;
61
+        }
60 62
         $cursor = $this;
61 63
         while ($cursor instanceof Node && $cursor->indent >= $indent) {
62 64
             $cursor = $cursor->parent;
@@ -76,7 +78,9 @@  discard block
 block discarded – undo
76 78
     {
77 79
         $child->setParent($this);
78 80
         $current = $this->value;
79
-        if ($this->type & Y\LITTERALS) $child->type = Y\SCALAR;
81
+        if ($this->type & Y\LITTERALS) {
82
+            $child->type = Y\SCALAR;
83
+        }
80 84
         if (is_null($current)) {
81 85
             $this->value = $child;
82 86
             return;
@@ -147,8 +151,12 @@  discard block
 block discarded – undo
147 151
             $type = R::isProperlyQuoted($nodeValue) ? Y\QUOTED : Y\PARTIAL;
148 152
             return [$type, $nodeValue];
149 153
         }
150
-        if (in_array($nodeValue[0], ['{', '[']))      return $this->onObject($nodeValue);
151
-        if (in_array($nodeValue[0], ['!', '&', '*'])) return $this->onNodeAction($nodeValue);
154
+        if (in_array($nodeValue[0], ['{', '['])) {
155
+            return $this->onObject($nodeValue);
156
+        }
157
+        if (in_array($nodeValue[0], ['!', '&', '*'])) {
158
+            return $this->onNodeAction($nodeValue);
159
+        }
152 160
         switch ($nodeValue[0]) {
153 161
             case '#': return [Y\COMMENT, ltrim($v)];
154 162
             case "-": return $this->onHyphen($nodeValue);
@@ -200,9 +208,15 @@  discard block
 block discarded – undo
200 208
     private function onObject($value):array
201 209
     {
202 210
         json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
203
-        if (json_last_error() === JSON_ERROR_NONE)  return [Y\JSON, $value];
204
-        if (preg_match(R::MAPPING, $value))         return [Y\MAPPING_SHORT, $value];
205
-        if (preg_match(R::SEQUENCE, $value))        return [Y\SEQUENCE_SHORT, $value];
211
+        if (json_last_error() === JSON_ERROR_NONE) {
212
+            return [Y\JSON, $value];
213
+        }
214
+        if (preg_match(R::MAPPING, $value)) {
215
+            return [Y\MAPPING_SHORT, $value];
216
+        }
217
+        if (preg_match(R::SEQUENCE, $value)) {
218
+            return [Y\SEQUENCE_SHORT, $value];
219
+        }
206 220
         return [Y\PARTIAL, $value];
207 221
     }
208 222
 
@@ -217,7 +231,9 @@  discard block
 block discarded – undo
217 231
     {
218 232
         if (substr($nodeValue, 0, 3) === '---') {
219 233
             $rest = trim(substr($nodeValue, 3));
220
-            if (empty($rest)) return [Y\DOC_START, null];
234
+            if (empty($rest)) {
235
+                return [Y\DOC_START, null];
236
+            }
221 237
             $n = new Node($rest, $this->line);
222 238
             $n->indent = $this->indent + 4;
223 239
             return [Y\DOC_START, $n->setParent($this)];
@@ -260,7 +276,9 @@  discard block
 block discarded – undo
260 276
     public function getPhpValue()
261 277
     {
262 278
         $v = $this->value;
263
-        if (is_null($v)) return null;
279
+        if (is_null($v)) {
280
+            return null;
281
+        }
264 282
         switch ($this->type) {
265 283
             case Y\JSON:   return json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR);
266 284
             case Y\QUOTED: return substr($v, 1, -1);
@@ -296,9 +314,15 @@  discard block
 block discarded – undo
296 314
                   '-.inf' => -INF,
297 315
                   '.nan'  => NAN
298 316
         ];
299
-        if (isset($types[strtolower($v)])) return $types[strtolower($v)];
300
-        if (R::isDate($v))   return date_create($v);
301
-        if (R::isNumber($v)) return self::getNumber($v);
317
+        if (isset($types[strtolower($v)])) {
318
+            return $types[strtolower($v)];
319
+        }
320
+        if (R::isDate($v)) {
321
+            return date_create($v);
322
+        }
323
+        if (R::isNumber($v)) {
324
+            return self::getNumber($v);
325
+        }
302 326
         return strval($v);
303 327
     }
304 328
 
@@ -311,8 +335,12 @@  discard block
 block discarded – undo
311 335
      */
312 336
     private static function getNumber(string $v)
313 337
     {
314
-        if (preg_match("/^(0o\d+)$/i", $v))      return intval(base_convert($v, 8, 10));
315
-        if (preg_match("/^(0x[\da-f]+)$/i", $v)) return intval(base_convert($v, 16, 10));
338
+        if (preg_match("/^(0o\d+)$/i", $v)) {
339
+            return intval(base_convert($v, 8, 10));
340
+        }
341
+        if (preg_match("/^(0x[\da-f]+)$/i", $v)) {
342
+            return intval(base_convert($v, 16, 10));
343
+        }
316 344
         // TODO: remove these if not needed
317 345
         // if preg_match("/^([\d.]+e[-+]\d{1,2})$/", $v)://fall through
318 346
         // if preg_match("/^([-+]?(?:\d+|\d*.\d+))$/", $v):
Please login to merge, or discard this patch.