Completed
Branch master (a11ddd)
by stéphane
02:27
created
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.
Node.php 1 patch
Braces   +36 added lines, -12 removed lines patch added patch discarded remove patch
@@ -110,8 +110,12 @@  discard block
 block discarded – undo
110 110
             $type = R::isProperlyQuoted($nodeValue) ? T::QUOTED : T::PARTIAL;
111 111
             return [$type, $nodeValue];
112 112
         }
113
-        if (in_array($nodeValue[0], ['{', '[']))      return $this->_onObject($nodeValue);
114
-        if (in_array($nodeValue[0], ['!', '&', '*'])) return $this->_onNodeAction($nodeValue);
113
+        if (in_array($nodeValue[0], ['{', '['])) {
114
+            return $this->_onObject($nodeValue);
115
+        }
116
+        if (in_array($nodeValue[0], ['!', '&', '*'])) {
117
+            return $this->_onNodeAction($nodeValue);
118
+        }
115 119
         switch ($nodeValue[0]) {
116 120
             case '#': return [T::COMMENT, ltrim($v)];
117 121
             case "-": return $this->_onMinus($nodeValue);
@@ -149,9 +153,15 @@  discard block
 block discarded – undo
149 153
     private function _onObject($value):array
150 154
     {
151 155
         json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
152
-        if (json_last_error() === JSON_ERROR_NONE)  return [T::JSON, $value];
153
-        if (preg_match(R::MAPPING, $value))         return [T::MAPPING_SHORT, $value];
154
-        if (preg_match(R::SEQUENCE, $value))        return [T::SEQUENCE_SHORT, $value];
156
+        if (json_last_error() === JSON_ERROR_NONE) {
157
+            return [T::JSON, $value];
158
+        }
159
+        if (preg_match(R::MAPPING, $value)) {
160
+            return [T::MAPPING_SHORT, $value];
161
+        }
162
+        if (preg_match(R::SEQUENCE, $value)) {
163
+            return [T::SEQUENCE_SHORT, $value];
164
+        }
155 165
         return [T::PARTIAL, $value];
156 166
     }
157 167
 
@@ -159,7 +169,9 @@  discard block
 block discarded – undo
159 169
     {
160 170
         if (substr($nodeValue, 0, 3) === '---') {
161 171
             $rest = trim(substr($nodeValue, 3));
162
-            if (empty($rest)) return [T::DOC_START, null];
172
+            if (empty($rest)) {
173
+                return [T::DOC_START, null];
174
+            }
163 175
             $n = new Node($rest, $this->line);
164 176
             $n->indent = $this->indent + 4;
165 177
             return [T::DOC_START, $n->setParent($this)];
@@ -188,7 +200,9 @@  discard block
 block discarded – undo
188 200
     public function getPhpValue()
189 201
     {
190 202
         $v = $this->value;
191
-        if (is_null($v)) return null;
203
+        if (is_null($v)) {
204
+            return null;
205
+        }
192 206
         switch ($this->type) {
193 207
             case T::JSON:   return json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR);
194 208
             case T::QUOTED: return substr($v, 1, -1);
@@ -217,16 +231,26 @@  discard block
 block discarded – undo
217 231
                   '-.inf' => -INF,
218 232
                   '.nan'  => NAN
219 233
         ];
220
-        if (in_array(strtolower($v), array_keys($types))) return $types[strtolower($v)];
221
-        if (R::isDate($v))   return date_create($v);
222
-        if (R::isNumber($v)) return $this->getNumber($v);
234
+        if (in_array(strtolower($v), array_keys($types))) {
235
+            return $types[strtolower($v)];
236
+        }
237
+        if (R::isDate($v)) {
238
+            return date_create($v);
239
+        }
240
+        if (R::isNumber($v)) {
241
+            return $this->getNumber($v);
242
+        }
223 243
         return strval($v);
224 244
     }
225 245
 
226 246
     private function getNumber($v)
227 247
     {
228
-        if (preg_match("/^(0o\d+)$/i", $v))      return intval(base_convert($v, 8, 10));
229
-        if (preg_match("/^(0x[\da-f]+)$/i", $v)) return intval(base_convert($v, 16, 10));
248
+        if (preg_match("/^(0o\d+)$/i", $v)) {
249
+            return intval(base_convert($v, 8, 10));
250
+        }
251
+        if (preg_match("/^(0x[\da-f]+)$/i", $v)) {
252
+            return intval(base_convert($v, 16, 10));
253
+        }
230 254
         // if preg_match("/^([\d.]+e[-+]\d{1,2})$/", $v)://fall through
231 255
         // if preg_match("/^([-+]?(?:\d+|\d*.\d+))$/", $v):
232 256
             return is_bool(strpos($v, '.')) ? intval($v) : floatval($v);
Please login to merge, or discard this patch.
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.
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
 
@@ -62,12 +64,15 @@  discard block
 block discarded – undo
62 64
             case T::REF_DEF: //fall through
63 65
             case T::REF_CALL:
64 66
                 $tmp = is_object($value) ? self::build($value, $parent) : $node->getPhpValue();
65
-                if ($type === T::REF_DEF) self::$root->addReference($name, $tmp);
67
+                if ($type === T::REF_DEF) {
68
+                    self::$root->addReference($name, $tmp);
69
+                }
66 70
                 return self::$root->getReference($name);
67 71
             case T::SET_KEY:
68 72
                 $key = json_encode(self::build($value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
69
-                if (empty($key))
70
-                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
73
+                if (empty($key)) {
74
+                                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
75
+                }
71 76
                 $parent->{$key} = null;
72 77
                 return;
73 78
             case T::SET_VALUE:
@@ -86,8 +91,11 @@  discard block
 block discarded – undo
86 91
                     $parent->addTag($name);return;
87 92
                 } else {
88 93
                     if (in_array($name, ['!binary', '!str'])) {
89
-                        if (is_object($value->value)) $value->value->type = T::RAW;
90
-                        else $value->type = T::RAW;
94
+                        if (is_object($value->value)) {
95
+                            $value->value->type = T::RAW;
96
+                        } else {
97
+                            $value->type = T::RAW;
98
+                        }
91 99
                     }
92 100
                     $val = is_null($value) ? null : self::build($value, $node);
93 101
                     return new Tag($name, $val);
@@ -149,10 +157,14 @@  discard block
 block discarded – undo
149 157
         }
150 158
         $root->value->setIteratorMode(DLL::IT_MODE_DELETE);
151 159
         foreach ($root->value as $child) {
152
-            if ($child->type === T::DOC_START) $totalDocStart++;
160
+            if ($child->type === T::DOC_START) {
161
+                $totalDocStart++;
162
+            }
153 163
             //if 0 or 1 DOC_START = we are still in first document
154 164
             $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;
155
-            if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new DLL();
165
+            if (!isset($documents[$currentDoc])) {
166
+                $documents[$currentDoc] = new DLL();
167
+            }
156 168
             $documents[$currentDoc]->push($child);
157 169
         }
158 170
         $debug >= 2 && var_dump($documents);
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
                 break;
132 144
             case T::LITTERAL://fall through
Please login to merge, or discard this patch.