Completed
Push — master ( d95e42...809c98 )
by stéphane
02:23
created
yaml/Dumper.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@
 block discarded – undo
74 74
             switch (gettype($dataType)) {
75 75
                 case 'boolean': return $dataType ? 'true' : 'false';
76 76
                 case 'float': if (is_infinite($dataType)) return $dataType > 0 ? '.inf' : '-.inf';
77
-                              return sprintf('%.2F', $dataType);
77
+                                return sprintf('%.2F', $dataType);
78 78
                 case 'double': if (is_nan((float) $dataType)) return '.nan';
79 79
                 default:
80 80
                     return $dataType;
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         foreach ($array as $key => $item) {
117 117
             $lineStart = current($refKeys) === $key ? "- " : "- $key: ";
118 118
             if (is_scalar($item)) {
119
-                self::add($lineStart.self::dump($item,0), $indent);
119
+                self::add($lineStart.self::dump($item, 0), $indent);
120 120
             } else {
121 121
                 self::add($lineStart, $indent);
122 122
                 self::dump($item, $indent + self::INDENT);
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
         if (is_array($subject) || $subject instanceof \ArrayIterator) {
164 164
             $max = count($subject);
165 165
             $objectAsArray = is_array($subject) ? $subject : $subject->getArrayCopy();
166
-            if(array_keys($objectAsArray) !== range(0, $max)) {
166
+            if (array_keys($objectAsArray) !== range(0, $max)) {
167 167
                 $pairs = $objectAsArray;
168 168
             } else {
169
-                $valuesList = array_map(self::dump, $objectAsArray, array_fill( 0 , $max , $indent ));
169
+                $valuesList = array_map(self::dump, $objectAsArray, array_fill(0, $max, $indent));
170 170
                 return '['.implode(', ', $valuesList).']';
171 171
             }
172 172
         } else {
Please login to merge, or discard this 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/YamlObject.php 2 patches
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.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,9 +43,9 @@
 block discarded – undo
43 43
     public function __call($funcName, $arguments)
44 44
     {
45 45
         $reflectAPI = new \ReflectionClass(get_class($this->__yaml__object__api));
46
-        $getName = function ($o) { return $o->name; };
46
+        $getName = function($o) { return $o->name; };
47 47
         $publicApi  = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PUBLIC));
48
-        if (!in_array($funcName, $publicApi) ) {
48
+        if (!in_array($funcName, $publicApi)) {
49 49
             throw new \BadMethodCallException(sprintf(self::UNDEFINED_METHOD, $funcName, implode(",", $publicApi)), 1);
50 50
         }
51 51
         return call_user_func_array([$this->__yaml__object__api, $funcName], $arguments);
Please login to merge, or discard this patch.
yaml/Loader.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
     //public
18 18
     /* @var null|string */
19 19
     public static $error;
20
-    public const IGNORE_DIRECTIVES = 1;//DONT include_directive
21
-    public const IGNORE_COMMENTS    = 2;//DONT include_comments
22
-    public const NO_PARSING_EXCEPTIONS = 4;//DONT throw Exception on parsing errors
23
-    public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object
20
+    public const IGNORE_DIRECTIVES = 1; //DONT include_directive
21
+    public const IGNORE_COMMENTS    = 2; //DONT include_comments
22
+    public const NO_PARSING_EXCEPTIONS = 4; //DONT throw Exception on parsing errors
23
+    public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object
24 24
 
25 25
     //privates
26 26
     /* @var null|false|array */
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
     /* @var null|string */
29 29
     private $filePath;
30 30
     /* @var integer */
31
-    private $debug = 0;///TODO: determine levels
31
+    private $debug = 0; ///TODO: determine levels
32 32
     /* @var integer */
33 33
     private $options = 0;
34 34
     //Exceptions messages
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
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 80
         if (!is_array($source) || !count($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT);
81
-        return function () use($source) {
81
+        return function() use($source) {
82 82
             foreach ($source as $key => $value) {
83 83
                 yield ++$key => $value;
84 84
             }
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                     case 0:
121 121
                         if ($n->type & Y::KEY && $n->indent === 0) {
122 122
                             $target = $root;
123
-                        } elseif($n->type & Y::ITEM && $deepest->type & Y::KEY && is_null($deepest->value)) {
123
+                        } elseif ($n->type & Y::ITEM && $deepest->type & Y::KEY && is_null($deepest->value)) {
124 124
                             $target = $deepest;
125 125
                         } else {
126 126
                             $target = $previous->getParent();
Please login to merge, or discard this 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/NodeList.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -45,16 +45,16 @@
 block discarded – undo
45 45
     public function forceType()
46 46
     {
47 47
         if (is_null($this->type)) {
48
-            $childTypes  = $this->getTypes();
49
-            if ($childTypes & (Y::KEY|Y::SET_KEY)) {
50
-                if ($childTypes & Y::ITEM) {
48
+            $childTypes = $this->getTypes();
49
+            if ($childTypes&(Y::KEY|Y::SET_KEY)) {
50
+                if ($childTypes&Y::ITEM) {
51 51
                     throw new \ParseError(self::class.": Error conflicting types found");
52 52
                 }
53 53
                 $this->type = Y::MAPPING;
54 54
             } else {
55
-                if ($childTypes & Y::ITEM) {
55
+                if ($childTypes&Y::ITEM) {
56 56
                     $this->type = Y::SEQUENCE;
57
-                } elseif (!($childTypes & Y::COMMENT)) {
57
+                } elseif (!($childTypes&Y::COMMENT)) {
58 58
                     $this->type = Y::LITT_FOLDED;
59 59
                 }
60 60
             }
Please login to merge, or discard this patch.
yaml/Compact.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
         $prop = get_object_vars($this);
33 33
         if (count($prop) > 0) return $prop;
34 34
         if (count($this) > 0) return iterator_to_array($this);
35
-        return $this;//new \Stdclass;
35
+        return $this; //new \Stdclass;
36 36
     }
37 37
 
38 38
     /**
Please login to merge, or discard this 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 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
         if ($n->type & (Y::REF_CALL|Y::SCALAR)) return self::getScalar((string) $n->value);
28 28
         if ($n->type & Y::JSON) return $n->value;
29 29
         $expected = [Y::QUOTED => trim((string) $n->value, "\"'"),
30
-                     Y::RAW    => strval((string) $n->value)];
30
+                        Y::RAW    => strval((string) $n->value)];
31 31
         return $expected[$n->type] ?? null;
32 32
     }
33 33
 
Please login to merge, or discard this 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 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         elseif (in_array($first, ['?', ':']))      $this->onSetElement($nodeValue);
183 183
         elseif (in_array($first, ['!', '&', '*'])) $this->onNodeAction($nodeValue);
184 184
         else {
185
-            $characters = [ '#' =>  [Y::COMMENT, $v],
185
+            $characters = ['#' =>  [Y::COMMENT, $v],
186 186
                             '%' =>  [Y::DIRECTIVE, $v],
187 187
                             '>' =>  [Y::LITT_FOLDED, null],
188 188
                             '|' =>  [Y::LITT, null]
@@ -251,28 +251,28 @@  discard block
 block discarded – undo
251 251
     private function onCompact($value)
252 252
     {
253 253
         $this->value = json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
254
-        if (json_last_error() === JSON_ERROR_NONE){
254
+        if (json_last_error() === JSON_ERROR_NONE) {
255 255
             $this->type = Y::JSON;
256 256
             return;
257 257
         }
258 258
         $this->value = new NodeList();
259
-        if (preg_match(R::MAPPING, $value)){
259
+        if (preg_match(R::MAPPING, $value)) {
260 260
             $this->type = Y::COMPACT_MAPPING;
261 261
             $this->value->type = Y::COMPACT_MAPPING;
262
-            preg_match_all(R::MAPPING_VALUES, trim(substr($value, 1,-1)), $matches);
262
+            preg_match_all(R::MAPPING_VALUES, trim(substr($value, 1, -1)), $matches);
263 263
             foreach ($matches['k'] as $index => $property) {
264 264
                 $n = new Node('', $this->line);
265 265
                 $n->type = Y::KEY;
266
-                $n->identifier = trim($property, '"\' ');//TODO : maybe check for proper quoting first ?
266
+                $n->identifier = trim($property, '"\' '); //TODO : maybe check for proper quoting first ?
267 267
                 $n->value = new Node($matches['v'][$index], $this->line);
268 268
                 $this->value->push($n);
269 269
             }
270 270
             return;
271 271
         }
272
-        if (preg_match(R::SEQUENCE, $value)){
272
+        if (preg_match(R::SEQUENCE, $value)) {
273 273
             $this->type = Y::COMPACT_SEQUENCE;
274 274
             $this->value->type = Y::COMPACT_SEQUENCE;
275
-            preg_match_all(R::SEQUENCE_VALUES, trim(substr($value, 1,-1)), $matches);
275
+            preg_match_all(R::SEQUENCE_VALUES, trim(substr($value, 1, -1)), $matches);
276 276
             foreach ($matches['item'] as $key => $item) {
277 277
                 $i = new Node('', $this->line);
278 278
                 $i->type = Y::ITEM;
Please login to merge, or discard this 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) {
@@ -100,7 +104,7 @@  discard block
 block discarded – undo
100 104
         if (is_null($this->value)) {
101 105
             $this->value = $child;
102 106
             return;
103
-        }elseif ($this->value instanceof Node) {
107
+        } elseif ($this->value instanceof Node) {
104 108
             if ($this->value->type & Y::LITTERALS) {
105 109
                 $type = $this->value->type;
106 110
                 $this->value = new NodeList();
@@ -176,12 +180,17 @@  discard block
 block discarded – undo
176 180
     {
177 181
         $v = ltrim(substr($nodeValue, 1));
178 182
         $first = $nodeValue[0];
179
-        if ($first === "-")                        $this->onHyphen($nodeValue);
180
-        elseif (in_array($first, ['"', "'"]))      $this->onQuoted($nodeValue);
181
-        elseif (in_array($first, ['{', '[']))      $this->onCompact($nodeValue);
182
-        elseif (in_array($first, ['?', ':']))      $this->onSetElement($nodeValue);
183
-        elseif (in_array($first, ['!', '&', '*'])) $this->onNodeAction($nodeValue);
184
-        else {
183
+        if ($first === "-") {
184
+            $this->onHyphen($nodeValue);
185
+        } elseif (in_array($first, ['"', "'"])) {
186
+            $this->onQuoted($nodeValue);
187
+        } elseif (in_array($first, ['{', '['])) {
188
+            $this->onCompact($nodeValue);
189
+        } elseif (in_array($first, ['?', ':'])) {
190
+            $this->onSetElement($nodeValue);
191
+        } elseif (in_array($first, ['!', '&', '*'])) {
192
+            $this->onNodeAction($nodeValue);
193
+        } else {
185 194
             $characters = [ '#' =>  [Y::COMMENT, $v],
186 195
                             '%' =>  [Y::DIRECTIVE, $v],
187 196
                             '>' =>  [Y::LITT_FOLDED, null],
Please login to merge, or discard this patch.
example.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
 /**
7 7
  * Display some use cases for Yaml library
8 8
  */
9
-const JSON_OPTIONS = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_LINE_TERMINATORS | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_PARTIAL_OUTPUT_ON_ERROR;
9
+const JSON_OPTIONS = JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_LINE_TERMINATORS|JSON_UNESCAPED_UNICODE|JSON_PRESERVE_ZERO_FRACTION|JSON_PARTIAL_OUTPUT_ON_ERROR;
10 10
 
11 11
 /* USE CASE 1
12 12
 * load and parse if file exists
13 13
 */
14 14
 ini_set("auto_detect_line_endings", 1);
15
-$content = file_get_contents('./tests/cases/parsing/multidoc_sequence.yml');//var_dump($content);
15
+$content = file_get_contents('./tests/cases/parsing/multidoc_sequence.yml'); //var_dump($content);
16 16
 // $content = file_get_contents('./tests/cases/examples/Example_2_17.yml');//var_dump($content);
17 17
 $yaml = Y::parse($content, null, 3);
18 18
 // $yaml = Y::parseFile('./references/Example 2.27.yml', null, 1);
Please login to merge, or discard this patch.
yaml/Builder.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
         $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE);
38 38
         foreach ($_root->value as $child) {
39 39
             if ($child->type & Y::DOC_START) {
40
-                if(++$totalDocStart > 1){
40
+                if (++$totalDocStart > 1) {
41 41
                     $documents[] = self::buildDocument($buffer, count($documents));
42 42
                     $buffer = new NodeList($child);
43 43
                 }
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
      *
83 83
      * @return mixed    The parent (object|array) or a string representing the NodeList.
84 84
      */
85
-    private static function buildNodeList(NodeList $node, &$parent=null)
85
+    private static function buildNodeList(NodeList $node, &$parent = null)
86 86
     {
87 87
         $node->forceType();
88
-        if ($node->type & (Y::RAW | Y::LITTERALS)) {
88
+        if ($node->type & (Y::RAW|Y::LITTERALS)) {
89 89
             return self::buildLitteral($node, (int) $node->type);
90 90
         }
91
-        $action = function ($child, &$parent, &$out) {
91
+        $action = function($child, &$parent, &$out) {
92 92
             self::build($child, $out);
93 93
         };
94 94
         if ($node->type & (Y::COMPACT_MAPPING|Y::MAPPING|Y::SET)) {
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
             $out = $parent ?? [];
98 98
         } else {
99 99
             $out = '';
100
-            $action = function ($child, &$parent, &$out) {
100
+            $action = function($child, &$parent, &$out) {
101 101
                 if ($child->type & (Y::SCALAR|Y::QUOTED)) {
102 102
                     if ($parent) {
103 103
                         $parent->setText(self::build($child));
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
         ];
137 137
         if (isset($actions[$type])) {
138 138
             return self::{$actions[$type]}($node, $parent);
139
-        } elseif ($type & Y::COMMENT) {
139
+        } elseif ($type&Y::COMMENT) {
140 140
             self::$_root->addComment($line, $value);
141
-        } elseif ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) {
141
+        } elseif ($type&(Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) {
142 142
             return self::buildNodeList($value, $parent);
143
-        } elseif ($type & (Y::REF_DEF | Y::REF_CALL)) {
143
+        } elseif ($type&(Y::REF_DEF|Y::REF_CALL)) {
144 144
             return self::handleReference($node, $parent);
145 145
         } elseif ($value instanceof Node) {
146 146
             return self::buildNode($value, $parent);
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      * @throws \ParseError if Key has no name(identifier) Note: empty string is allowed
167 167
      * @return null
168 168
      */
169
-    private static function buildKey(Node $node, &$parent=null)
169
+    private static function buildKey(Node $node, &$parent = null)
170 170
     {
171 171
         extract((array) $node, EXTR_REFS);
172 172
         if (is_null($identifier)) {
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
         $numKeys = array_filter(array_keys($ref), 'is_int');
214 214
         $key = count($numKeys) > 0 ? max($numKeys) + 1 : 0;
215 215
         if ($value instanceof Node) {
216
-            if($value->type & Y::KEY) {
216
+            if ($value->type & Y::KEY) {
217 217
                 self::buildKey($node->value, $parent);
218 218
                 return;
219 219
             } elseif ($value->type & Y::ITEM) {
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         //remove trailing blank
243 243
         while ($list->top()->type & Y::BLANK) $list->pop();
244 244
         $result = '';
245
-        $separator = [ Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type];
245
+        $separator = [Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type];
246 246
         foreach ($list as $child) {
247 247
             if ($child->value instanceof NodeList) {
248 248
                 $result .= self::buildLitteral($child->value, $type).$separator;
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
     private function setLiteralValue(Node $child, string &$result, int $refIndent, string $separator, int $type)
257 257
     {
258 258
         $val = $child->type & (Y::SCALAR) ? $child->value : substr($child->raw, $refIndent);
259
-        if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
259
+        if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
260 260
             if ($result[-1] === $separator)
261 261
                 $result[-1] = "\n";
262 262
             if ($result[-1] === "\n")
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
     private function buildSetKey(Node $node, &$parent)
278 278
     {
279 279
         $built = is_object($node->value) ? self::build($node->value) : null;
280
-        $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built;
280
+        $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built;
281 281
         $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
282 282
         if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1);
283 283
         $parent->{trim($key, '\'" ')} = null;
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
     {
294 294
         $prop = array_keys(get_object_vars($parent));
295 295
         $key = end($prop);
296
-        if ($node->value->type & (Y::ITEM|Y::KEY )) {
296
+        if ($node->value->type & (Y::ITEM|Y::KEY)) {
297 297
             $node->value = new NodeList($node->value);
298 298
         }
299 299
         $parent->{$key} = self::build($node->value);
Please login to merge, or discard this patch.
Braces   +18 added lines, -8 removed lines patch added patch discarded remove patch
@@ -70,7 +70,9 @@  discard block
 block discarded – undo
70 70
      */
71 71
     private static function build(object $node, &$parent = null)
72 72
     {
73
-        if ($node instanceof NodeList) return self::buildNodeList($node, $parent);
73
+        if ($node instanceof NodeList) {
74
+            return self::buildNodeList($node, $parent);
75
+        }
74 76
         return self::buildNode($node, $parent);
75 77
     }
76 78
 
@@ -152,7 +154,9 @@  discard block
 block discarded – undo
152 154
     private static function handleReference($node, $parent)
153 155
     {
154 156
         $tmp = is_null($node->value) ? null : self::build($node->value, $parent);
155
-        if ($node->type === Y::REF_DEF) self::$_root->addReference($node->identifier, $tmp);
157
+        if ($node->type === Y::REF_DEF) {
158
+            self::$_root->addReference($node->identifier, $tmp);
159
+        }
156 160
         return self::$_root->getReference($node->identifier);
157 161
     }
158 162
 
@@ -240,7 +244,9 @@  discard block
 block discarded – undo
240 244
         $list->rewind();
241 245
         $refIndent = $list->current()->indent;
242 246
         //remove trailing blank
243
-        while ($list->top()->type & Y::BLANK) $list->pop();
247
+        while ($list->top()->type & Y::BLANK) {
248
+            $list->pop();
249
+        }
244 250
         $result = '';
245 251
         $separator = [ Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type];
246 252
         foreach ($list as $child) {
@@ -257,10 +263,12 @@  discard block
 block discarded – undo
257 263
     {
258 264
         $val = $child->type & (Y::SCALAR) ? $child->value : substr($child->raw, $refIndent);
259 265
         if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
260
-            if ($result[-1] === $separator)
261
-                $result[-1] = "\n";
262
-            if ($result[-1] === "\n")
263
-                $result .= $val;
266
+            if ($result[-1] === $separator) {
267
+                            $result[-1] = "\n";
268
+            }
269
+            if ($result[-1] === "\n") {
270
+                            $result .= $val;
271
+            }
264 272
             return;
265 273
         }
266 274
         $result .= $val.$separator;
@@ -279,7 +287,9 @@  discard block
 block discarded – undo
279 287
         $built = is_object($node->value) ? self::build($node->value) : null;
280 288
         $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built;
281 289
         $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
282
-        if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1);
290
+        if (empty($key)) {
291
+            throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1);
292
+        }
283 293
         $parent->{trim($key, '\'" ')} = null;
284 294
     }
285 295
 
Please login to merge, or discard this patch.