Completed
Push — master ( 569899...5bb983 )
by stéphane
02:08
created
yaml/YamlObject.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,8 +52,12 @@
 block discarded – undo
52 52
     {
53 53
         $prop = get_object_vars($this);
54 54
         unset($prop["__yaml__object__api"]);
55
-        if (count($prop) > 0) return $prop;
56
-        if (count($this) > 0) return iterator_to_array($this);
55
+        if (count($prop) > 0) {
56
+            return $prop;
57
+        }
58
+        if (count($this) > 0) {
59
+            return iterator_to_array($this);
60
+        }
57 61
         return $this->__yaml__object__api->value ?? "Empty YamlObject";
58 62
     }
59 63
 }
Please login to merge, or discard this patch.
yaml/Dumper.php 1 patch
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -40,7 +40,9 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public static function toString($dataType, int $options = null):string
42 42
     {
43
-        if (is_null($dataType)) throw new \Exception(self::class.": No content to convert to Yaml", 1);
43
+        if (is_null($dataType)) {
44
+            throw new \Exception(self::class.": No content to convert to Yaml", 1);
45
+        }
44 46
         self::$options = is_int($options) ? $options : self::OPTIONS;
45 47
         self::$result = new DLL;
46 48
         if ($dataType instanceof YamlObject) {
@@ -76,9 +78,13 @@  discard block
 block discarded – undo
76 78
         if (is_scalar($dataType)) {
77 79
             switch (gettype($dataType)) {
78 80
                 case 'boolean': return $dataType ? 'true' : 'false';
79
-                case 'float': if (is_infinite($dataType)) return $dataType > 0 ? '.inf' : '-.inf';
81
+                case 'float': if (is_infinite($dataType)) {
82
+                    return $dataType > 0 ? '.inf' : '-.inf';
83
+                }
80 84
                               return sprintf('%.2F', $dataType);
81
-                case 'double': if (is_nan((float) $dataType)) return '.nan';
85
+                case 'double': if (is_nan((float) $dataType)) {
86
+                    return '.nan';
87
+                }
82 88
                 default:
83 89
                     return $dataType;
84 90
             }
@@ -91,7 +97,9 @@  discard block
 block discarded – undo
91 97
 
92 98
     private static function dumpYamlObject(YamlObject $dataType)
93 99
     {
94
-        if ($dataType->hasDocStart() && self::$result instanceof DLL) self::$result->push("---");
100
+        if ($dataType->hasDocStart() && self::$result instanceof DLL) {
101
+            self::$result->push("---");
102
+        }
95 103
         // self::dump($dataType, 0);
96 104
         if (count($dataType) > 0) {
97 105
             self::dumpSequence($dataType->getArrayCopy(), 0);
@@ -142,9 +150,13 @@  discard block
 block discarded – undo
142 150
                 self::add(self::dump($obj->value, $indent + self::INDENT), $indent + self::INDENT);
143 151
             }
144 152
         }
145
-        if ($obj instanceof Compact) return self::dumpCompact($obj, $indent);
153
+        if ($obj instanceof Compact) {
154
+            return self::dumpCompact($obj, $indent);
155
+        }
146 156
         //TODO:  consider dumping datetime as date strings according to a format provided by user or default
147
-        if ($obj instanceof \DateTime) return $obj->format('Y-m-d');
157
+        if ($obj instanceof \DateTime) {
158
+            return $obj->format('Y-m-d');
159
+        }
148 160
         // if ($obj instanceof \SplString) {var_dump('splstrin',$obj);return '"'.$obj.'"';}
149 161
         $propList = get_object_vars($obj);
150 162
         foreach ($propList as $property => $value) {
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
@@ -77,7 +77,9 @@  discard block
 block discarded – undo
77 77
     {
78 78
         $source = $this->content ?? preg_split("/\n/m", preg_replace('/(\r\n|\r)/', "\n", $strContent), 0, PREG_SPLIT_DELIM_CAPTURE);
79 79
         //TODO : be more permissive on $strContent values
80
-        if (!is_array($source) || !count($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT);
80
+        if (!is_array($source) || !count($source)) {
81
+            throw new \Exception(self::EXCEPTION_LINE_SPLIT);
82
+        }
81 83
         return function () use($source) {
82 84
             foreach ($source as $key => $value) {
83 85
                 yield ++$key => $value;
@@ -105,7 +107,9 @@  discard block
 block discarded – undo
105 107
                 $n = new Node($lineString, $lineNb);
106 108
                 $deepest = $previous->getDeepestNode();
107 109
                 if ($n->type & (Y::LITTERALS|Y::BLANK|Y::COMMENT|Y::TAG) || $deepest->type & Y::PARTIAL) {
108
-                    if ($this->onSpecialType($n, $previous, $emptyLines, $lineString)) continue;
110
+                    if ($this->onSpecialType($n, $previous, $emptyLines, $lineString)) {
111
+                        continue;
112
+                    }
109 113
                 }
110 114
                 //Note: 6.6 comments: Note that outside scalar content, a line containing only white space characters is taken to be a comment line.
111 115
                 foreach ($emptyLines as $blankNode) {
@@ -134,7 +138,9 @@  discard block
 block discarded – undo
134 138
                             }
135 139
                         }
136 140
                 }
137
-                if ($this->onContextType($n, $target, $lineString)) continue;
141
+                if ($this->onContextType($n, $target, $lineString)) {
142
+                    continue;
143
+                }
138 144
                 $target->add($n);
139 145
                 $previous = $n;
140 146
             }
@@ -171,8 +177,12 @@  discard block
 block discarded – undo
171 177
             return true;
172 178
         }
173 179
         if ($n->type & Y::BLANK) {
174
-            if ($previous->type & Y::SCALAR)   $emptyLines[] = $n->setParent($previous->getParent());
175
-            if ($deepest->type & Y::LITTERALS) $emptyLines[] = $n->setParent($deepest);
180
+            if ($previous->type & Y::SCALAR) {
181
+                $emptyLines[] = $n->setParent($previous->getParent());
182
+            }
183
+            if ($deepest->type & Y::LITTERALS) {
184
+                $emptyLines[] = $n->setParent($deepest);
185
+            }
176 186
             return true;
177 187
         } elseif ($n->type & Y::COMMENT
178 188
                   && !($previous->getParent()->value->type & Y::LITTERALS)
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
@@ -30,8 +30,12 @@
 block discarded – undo
30 30
     public function jsonSerialize():array
31 31
     {
32 32
         $prop = get_object_vars($this);
33
-        if (count($prop) > 0) return $prop;
34
-        if (count($this) > 0) return iterator_to_array($this);
33
+        if (count($prop) > 0) {
34
+            return $prop;
35
+        }
36
+        if (count($this) > 0) {
37
+            return iterator_to_array($this);
38
+        }
35 39
         return $this;//new \Stdclass;
36 40
     }
37 41
 
Please login to merge, or discard this patch.
yaml/Node2PHP.php 1 patch
Braces   +21 added lines, -7 removed lines patch added patch discarded remove patch
@@ -23,9 +23,15 @@  discard block
 block discarded – undo
23 23
      */
24 24
     public static function get(Node $n)
25 25
     {
26
-        if (is_null($n->value)) return null;
27
-        if ($n->type & (Y::REF_CALL|Y::SCALAR)) return self::getScalar((string) $n->value);
28
-        if ($n->type & Y::JSON) return $n->value;
26
+        if (is_null($n->value)) {
27
+            return null;
28
+        }
29
+        if ($n->type & (Y::REF_CALL|Y::SCALAR)) {
30
+            return self::getScalar((string) $n->value);
31
+        }
32
+        if ($n->type & Y::JSON) {
33
+            return $n->value;
34
+        }
29 35
         $expected = [Y::QUOTED => trim((string) $n->value, "\"'"),
30 36
                      Y::RAW    => strval((string) $n->value)];
31 37
         return $expected[$n->type] ?? null;
@@ -41,8 +47,12 @@  discard block
 block discarded – undo
41 47
      */
42 48
     private static function getScalar(string $v)
43 49
     {
44
-        if (R::isDate($v))   return self::$dateAsString ? $v : date_create($v);
45
-        if (R::isNumber($v)) return self::getNumber($v);
50
+        if (R::isDate($v)) {
51
+            return self::$dateAsString ? $v : date_create($v);
52
+        }
53
+        if (R::isNumber($v)) {
54
+            return self::getNumber($v);
55
+        }
46 56
         $types = ['yes'   => true,
47 57
                     'no'    => false,
48 58
                     'true'  => true,
@@ -64,8 +74,12 @@  discard block
 block discarded – undo
64 74
      */
65 75
     private static function getNumber(string $v)
66 76
     {
67
-        if (preg_match(R::OCTAL_NUM, $v)) return intval(base_convert($v, 8, 10));
68
-        if (preg_match(R::HEX_NUM, $v))   return intval(base_convert($v, 16, 10));
77
+        if (preg_match(R::OCTAL_NUM, $v)) {
78
+            return intval(base_convert($v, 8, 10));
79
+        }
80
+        if (preg_match(R::HEX_NUM, $v)) {
81
+            return intval(base_convert($v, 16, 10));
82
+        }
69 83
         return is_bool(strpos($v, '.')) ? intval($v) : floatval($v);
70 84
     }
71 85
 }
72 86
\ No newline at end of file
Please login to merge, or discard this patch.
yaml/Node.php 1 patch
Braces   +18 added lines, -9 removed lines patch added patch discarded remove patch
@@ -68,8 +68,12 @@  discard block
 block discarded – undo
68 68
      */
69 69
     public function getParent(int $indent = null, $type = 0):Node
70 70
     {
71
-        if ($this->type === Y::ROOT) return $this;
72
-        if (!is_int($indent)) return $this->parent ?? $this;
71
+        if ($this->type === Y::ROOT) {
72
+            return $this;
73
+        }
74
+        if (!is_int($indent)) {
75
+            return $this->parent ?? $this;
76
+        }
73 77
         $cursor = $this;
74 78
         while ($cursor instanceof Node && $cursor->indent >= $indent) {
75 79
             if ($cursor->indent === $indent && $cursor->type !== $type) {
@@ -101,7 +105,7 @@  discard block
 block discarded – undo
101 105
         if (is_null($current)) {
102 106
             $this->value = $child;
103 107
             return;
104
-        }elseif ($current instanceof Node) {
108
+        } elseif ($current instanceof Node) {
105 109
             $this->value = new NodeList();
106 110
             if ($current->type & Y::LITTERALS) {
107 111
                 $this->value->type = $current->type;
@@ -179,12 +183,17 @@  discard block
 block discarded – undo
179 183
     {
180 184
         $v = ltrim(substr($nodeValue, 1));
181 185
         $first = $nodeValue[0];
182
-        if ($first === "-")                        $this->onHyphen($nodeValue);
183
-        elseif (in_array($first, ['"', "'"]))      $this->onQuoted($nodeValue);
184
-        elseif (in_array($first, ['{', '[']))      $this->onCompact($nodeValue);
185
-        elseif (in_array($first, ['?', ':']))      $this->onSetElement($nodeValue);
186
-        elseif (in_array($first, ['!', '&', '*'])) $this->onNodeAction($nodeValue);
187
-        else {
186
+        if ($first === "-") {
187
+            $this->onHyphen($nodeValue);
188
+        } elseif (in_array($first, ['"', "'"])) {
189
+            $this->onQuoted($nodeValue);
190
+        } elseif (in_array($first, ['{', '['])) {
191
+            $this->onCompact($nodeValue);
192
+        } elseif (in_array($first, ['?', ':'])) {
193
+            $this->onSetElement($nodeValue);
194
+        } elseif (in_array($first, ['!', '&', '*'])) {
195
+            $this->onNodeAction($nodeValue);
196
+        } else {
188 197
             $characters = [ '#' =>  [Y::COMMENT, $v],
189 198
                             '%' =>  [Y::DIRECTIVE, $v],
190 199
                             '>' =>  [Y::LITT_FOLDED, null],
Please login to merge, or discard this patch.
yaml/Builder.php 1 patch
Braces   +27 added lines, -11 removed lines patch added patch discarded remove patch
@@ -35,10 +35,14 @@  discard block
 block discarded – undo
35 35
         $documents = [];
36 36
         $_root->value instanceof NodeList && $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE);
37 37
         foreach ($_root->value as $child) {
38
-            if ($child->type & Y::DOC_START) $totalDocStart++;
38
+            if ($child->type & Y::DOC_START) {
39
+                $totalDocStart++;
40
+            }
39 41
             //if 0 or 1 DOC_START = we are still in first document
40 42
             $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;
41
-            if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList();
43
+            if (!isset($documents[$currentDoc])) {
44
+                $documents[$currentDoc] = new NodeList();
45
+            }
42 46
             $documents[$currentDoc]->push($child);
43 47
         }
44 48
         $content = [];
@@ -63,7 +67,9 @@  discard block
 block discarded – undo
63 67
      */
64 68
     private static function build(object $node, &$parent = null)
65 69
     {
66
-        if ($node instanceof NodeList) return self::buildNodeList($node, $parent);
70
+        if ($node instanceof NodeList) {
71
+            return self::buildNodeList($node, $parent);
72
+        }
67 73
         return self::buildNode($node, $parent);
68 74
     }
69 75
 
@@ -126,13 +132,17 @@  discard block
 block discarded – undo
126 132
             } else {
127 133
                 $tmp = Node2PHP::get($node);
128 134
             }
129
-            if ($type === Y::REF_DEF) self::$_root->addReference($identifier, $tmp);
135
+            if ($type === Y::REF_DEF) {
136
+                self::$_root->addReference($identifier, $tmp);
137
+            }
130 138
             return self::$_root->getReference($identifier);
131 139
         }
132 140
         if ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) {
133 141
             return self::buildNodeList($node->value, $parent);
134 142
         }
135
-        if ($type & Y::COMMENT) self::$_root->addComment($node->line, $node->value);
143
+        if ($type & Y::COMMENT) {
144
+            self::$_root->addComment($node->line, $node->value);
145
+        }
136 146
         $typesActions = [Y::DIRECTIVE => 'buildDirective',
137 147
                          Y::ITEM      => 'buildItem',
138 148
                          Y::KEY       => 'buildKey',
@@ -229,7 +239,9 @@  discard block
 block discarded – undo
229 239
         $list->rewind();
230 240
         $refIndent = $list->current()->indent;
231 241
         //remove trailing blank
232
-        while ($list->top()->type & Y::BLANK) $list->pop();
242
+        while ($list->top()->type & Y::BLANK) {
243
+            $list->pop();
244
+        }
233 245
         $result = '';
234 246
         $separator = [ 0 => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][(int) $type];
235 247
         foreach ($list as $child) {
@@ -238,10 +250,12 @@  discard block
 block discarded – undo
238 250
             } else {
239 251
                 $val = $child->type & (Y::SCALAR|Y::BLANK) ? $child->value : substr($child->raw, $refIndent);
240 252
                 if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
241
-                    if ($result[-1] === $separator)
242
-                        $result[-1] = "\n";
243
-                    if ($result[-1] === "\n")
244
-                        $result .= $val;
253
+                    if ($result[-1] === $separator) {
254
+                                            $result[-1] = "\n";
255
+                    }
256
+                    if ($result[-1] === "\n") {
257
+                                            $result .= $val;
258
+                    }
245 259
                     continue;
246 260
                 }
247 261
                 $result .= $val.$separator;
@@ -263,7 +277,9 @@  discard block
 block discarded – undo
263 277
         $built = is_object($node->value) ? self::build($node->value) : null;
264 278
         $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built;
265 279
         $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
266
-        if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1);
280
+        if (empty($key)) {
281
+            throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1);
282
+        }
267 283
         $parent->{trim($key, '\'" ')} = null;
268 284
     }
269 285
 
Please login to merge, or discard this patch.