Passed
Branch master (f496ba)
by stéphane
02:11
created
Node.php 1 patch
Braces   +45 added lines, -15 removed lines patch added patch discarded remove patch
@@ -38,7 +38,9 @@  discard block
 block discarded – undo
38 38
 
39 39
     public function getParent($indent = null):Node
40 40
     {
41
-        if (is_null($indent)) return $this->parent ?? $this;
41
+        if (is_null($indent)) {
42
+            return $this->parent ?? $this;
43
+        }
42 44
         $cursor = $this;
43 45
         while ($cursor->indent >= $indent) {
44 46
             $cursor = $cursor->parent;
@@ -50,7 +52,9 @@  discard block
 block discarded – undo
50 52
     {
51 53
         $child->setParent($this);
52 54
         $current = $this->value;
53
-        if (in_array($this->type, T::$LITTERALS)) $child->type = T::SCALAR;
55
+        if (in_array($this->type, T::$LITTERALS)) {
56
+            $child->type = T::SCALAR;
57
+        }
54 58
         if (is_null($current)) {
55 59
             $this->value = $child;
56 60
             return;
@@ -114,8 +118,12 @@  discard block
 block discarded – undo
114 118
             $type = R::isProperlyQuoted($nodeValue) ? T::QUOTED : T::PARTIAL;
115 119
             return [$type, $nodeValue];
116 120
         }
117
-        if (in_array($nodeValue[0], ['{', '[']))      return $this->onObject($nodeValue);
118
-        if (in_array($nodeValue[0], ['!', '&', '*'])) return $this->onNodeAction($nodeValue);
121
+        if (in_array($nodeValue[0], ['{', '['])) {
122
+            return $this->onObject($nodeValue);
123
+        }
124
+        if (in_array($nodeValue[0], ['!', '&', '*'])) {
125
+            return $this->onNodeAction($nodeValue);
126
+        }
119 127
         switch ($nodeValue[0]) {
120 128
             case '#': return [T::COMMENT, ltrim($v)];
121 129
             case "-": return $this->onHyphen($nodeValue);
@@ -154,9 +162,15 @@  discard block
 block discarded – undo
154 162
     private function onObject($value):array
155 163
     {
156 164
         json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
157
-        if (json_last_error() === JSON_ERROR_NONE)  return [T::JSON, $value];
158
-        if (preg_match(R::MAPPING, $value))         return [T::MAPPING_SHORT, $value];
159
-        if (preg_match(R::SEQUENCE, $value))        return [T::SEQUENCE_SHORT, $value];
165
+        if (json_last_error() === JSON_ERROR_NONE) {
166
+            return [T::JSON, $value];
167
+        }
168
+        if (preg_match(R::MAPPING, $value)) {
169
+            return [T::MAPPING_SHORT, $value];
170
+        }
171
+        if (preg_match(R::SEQUENCE, $value)) {
172
+            return [T::SEQUENCE_SHORT, $value];
173
+        }
160 174
         return [T::PARTIAL, $value];
161 175
     }
162 176
 
@@ -164,7 +178,9 @@  discard block
 block discarded – undo
164 178
     {
165 179
         if (substr($nodeValue, 0, 3) === '---') {
166 180
             $rest = trim(substr($nodeValue, 3));
167
-            if (empty($rest)) return [T::DOC_START, null];
181
+            if (empty($rest)) {
182
+                return [T::DOC_START, null];
183
+            }
168 184
             $n = new Node($rest, $this->line);
169 185
             $n->indent = $this->indent + 4;
170 186
             return [T::DOC_START, $n->setParent($this)];
@@ -193,7 +209,9 @@  discard block
 block discarded – undo
193 209
     public function getPhpValue()
194 210
     {
195 211
         $v = $this->value;
196
-        if (is_null($v)) return null;
212
+        if (is_null($v)) {
213
+            return null;
214
+        }
197 215
         switch ($this->type) {
198 216
             case T::JSON:   return json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR);
199 217
             case T::QUOTED: return substr($v, 1, -1);
@@ -222,16 +240,26 @@  discard block
 block discarded – undo
222 240
                   '-.inf' => -INF,
223 241
                   '.nan'  => NAN
224 242
         ];
225
-        if (in_array(strtolower($v), array_keys($types))) return $types[strtolower($v)];
226
-        if (R::isDate($v))   return date_create($v);
227
-        if (R::isNumber($v)) return self::getNumber($v);
243
+        if (in_array(strtolower($v), array_keys($types))) {
244
+            return $types[strtolower($v)];
245
+        }
246
+        if (R::isDate($v)) {
247
+            return date_create($v);
248
+        }
249
+        if (R::isNumber($v)) {
250
+            return self::getNumber($v);
251
+        }
228 252
         return strval($v);
229 253
     }
230 254
 
231 255
     private static function getNumber($v)
232 256
     {
233
-        if (preg_match("/^(0o\d+)$/i", $v))      return intval(base_convert($v, 8, 10));
234
-        if (preg_match("/^(0x[\da-f]+)$/i", $v)) return intval(base_convert($v, 16, 10));
257
+        if (preg_match("/^(0o\d+)$/i", $v)) {
258
+            return intval(base_convert($v, 8, 10));
259
+        }
260
+        if (preg_match("/^(0x[\da-f]+)$/i", $v)) {
261
+            return intval(base_convert($v, 16, 10));
262
+        }
235 263
         // if preg_match("/^([\d.]+e[-+]\d{1,2})$/", $v)://fall through
236 264
         // if preg_match("/^([-+]?(?:\d+|\d*.\d+))$/", $v):
237 265
             return is_bool(strpos($v, '.')) ? intval($v) : floatval($v);
@@ -254,7 +282,9 @@  discard block
 block discarded – undo
254 282
                 'indent'=> $this->indent,
255 283
                 'type'  => T::getName($this->type),
256 284
                 'value' => $this->value];
257
-        if (!is_null($this->identifier)) $out['type'] .= "($this->identifier)";
285
+        if (!is_null($this->identifier)) {
286
+            $out['type'] .= "($this->identifier)";
287
+        }
258 288
         return $out;
259 289
     }
260 290
 }
Please login to merge, or discard this patch.
Loader.php 1 patch
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -66,9 +66,13 @@  discard block
 block discarded – undo
66 66
     public function parse($strContent = null)
67 67
     {
68 68
         $source = $this->content;
69
-        if (is_null($source)) $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE);
69
+        if (is_null($source)) {
70
+            $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE);
71
+        }
70 72
         //TODO : be more permissive on $strContent values
71
-        if (!is_array($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT);
73
+        if (!is_array($source)) {
74
+            throw new \Exception(self::EXCEPTION_LINE_SPLIT);
75
+        }
72 76
         $previous = $root = new Node();
73 77
         $emptyLines = [];
74 78
         $specialTypes = [T::LITTERAL, T::LITTERAL_FOLDED, T::EMPTY];
@@ -85,7 +89,9 @@  discard block
 block discarded – undo
85 89
                     $deepest->parse($deepest->value.' '.ltrim($lineString));
86 90
                 } else {
87 91
                     if (in_array($n->type, $specialTypes)) {
88
-                        if ($this->onSpecialType($n, $parent, $previous, $emptyLines)) continue;
92
+                        if ($this->onSpecialType($n, $parent, $previous, $emptyLines)) {
93
+                            continue;
94
+                        }
89 95
                     }
90 96
                     foreach ($emptyLines as $key => $node) {
91 97
                         $node->getParent()->add($node);
@@ -96,7 +102,9 @@  discard block
 block discarded – undo
96 102
                     } elseif ($n->indent === $previous->indent) {
97 103
                         $parent = $previous->getParent();
98 104
                     } elseif ($n->indent > $previous->indent) {
99
-                        if ($this->onDeepestType($n, $parent, $previous, $lineString)) continue;
105
+                        if ($this->onDeepestType($n, $parent, $previous, $lineString)) {
106
+                            continue;
107
+                        }
100 108
                     }
101 109
                     $parent->add($n);
102 110
                     $previous = $n;
@@ -125,8 +133,12 @@  discard block
 block discarded – undo
125 133
         $deepest = $previous->getDeepestNode();
126 134
         switch ($n->type) {
127 135
             case T::EMPTY:
128
-                if ($previous->type === T::SCALAR) $emptyLines[] = $n->setParent($previous->getParent());
129
-                if (in_array($deepest->type, T::$LITTERALS)) $emptyLines[] = $n->setParent($deepest);
136
+                if ($previous->type === T::SCALAR) {
137
+                    $emptyLines[] = $n->setParent($previous->getParent());
138
+                }
139
+                if (in_array($deepest->type, T::$LITTERALS)) {
140
+                    $emptyLines[] = $n->setParent($deepest);
141
+                }
130 142
                 return true;
131 143
             case T::LITTERAL://fall through
132 144
             case T::LITTERAL_FOLDED://var_dump($deepest);exit();
Please login to merge, or discard this patch.
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 T::REF_DEF: //fall through
62 64
             case T::REF_CALL://TODO: self::build returns what ?
63 65
                 $tmp = is_object($value) ? self::build($value, $parent) : $node->getPhpValue();
64
-                if ($type === T::REF_DEF) self::$root->addReference($identifier, $tmp);
66
+                if ($type === T::REF_DEF) {
67
+                    self::$root->addReference($identifier, $tmp);
68
+                }
65 69
                 return self::$root->getReference($identifier);
66 70
             case T::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 T::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 = T::RAW;
89
-                        else $value->type = T::RAW;
93
+                        if ($value->value instanceof DLL) {
94
+                            $value->value->type = T::RAW;
95
+                        } else {
96
+                            $value->type = T::RAW;
97
+                        }
90 98
                     }
91 99
                     $val = is_null($value) ? null : self::build($value, $node);
92 100
                     return new Tag($identifier, $val);
@@ -148,10 +156,14 @@  discard block
 block discarded – undo
148 156
         }
149 157
         $root->value->setIteratorMode(DLL::IT_MODE_DELETE);
150 158
         foreach ($root->value as $child) {
151
-            if ($child->type === T::DOC_START) $totalDocStart++;
159
+            if ($child->type === T::DOC_START) {
160
+                $totalDocStart++;
161
+            }
152 162
             //if 0 or 1 DOC_START = we are still in first document
153 163
             $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;
154
-            if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new DLL();
164
+            if (!isset($documents[$currentDoc])) {
165
+                $documents[$currentDoc] = new DLL();
166
+            }
155 167
             $documents[$currentDoc]->push($child);
156 168
         }
157 169
         $debug >= 2 && var_dump($documents);
Please login to merge, or discard this patch.
Dumper.php 1 patch
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,12 +21,16 @@  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
     public static function toString($dataType, int $options):string
28 30
     {
29
-        if (is_null($dataType)) throw new \Exception(self::class.": No content to convert to Yaml", 1);
31
+        if (is_null($dataType)) {
32
+            throw new \Exception(self::class.": No content to convert to Yaml", 1);
33
+        }
30 34
         self::$options = is_int($options) ? $options : self::$options;
31 35
         self::$result = new DLL;
32 36
         self::$result->setIteratorMode(DLL::IT_MODE_FIFO | DLL::IT_MODE_DELETE);
@@ -55,8 +59,12 @@  discard block
 block discarded – undo
55 59
         if (is_scalar($dataType)) {
56 60
             switch (gettype($dataType)) {
57 61
                 case 'boolean': return $dataType ? 'true' : 'false';break;
58
-                case 'float': if (is_infinite($dataType)) return $dataType > 0 ? '.inf' : '-.inf';
59
-                case 'double': if (is_nan($dataType)) return '.nan';
62
+                case 'float': if (is_infinite($dataType)) {
63
+                    return $dataType > 0 ? '.inf' : '-.inf';
64
+                }
65
+                case 'double': if (is_nan($dataType)) {
66
+                    return '.nan';
67
+                }
60 68
                 default:
61 69
                     return $dataType;
62 70
             }
Please login to merge, or discard this patch.