Completed
Push — master ( 8ac133...c7418d )
by stéphane
05:47
created
yaml/YamlObject.php 2 patches
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.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
     public function __call($funcName, $arguments)
33 33
     {
34 34
         $reflectAPI = new \ReflectionClass(get_class($this->__yaml__object__api));
35
-        $getName = function ($o) { return $o->name; };
35
+        $getName = function($o) { return $o->name; };
36 36
         $publicApi  = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PUBLIC));
37 37
         $privateApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PRIVATE));
38 38
         if (!in_array($funcName, $publicApi) && !in_array($funcName, $privateApi)) {
Please login to merge, or discard this patch.
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   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -159,10 +159,10 @@
 block discarded – undo
159 159
         if (is_array($subject) || $subject instanceof \Countable) {
160 160
             $max = count($subject);
161 161
             $objectAsArray = is_array($subject) ? $subject : $subject->getArrayCopy();
162
-            if(array_keys($objectAsArray) !== range(0, $max)) {
162
+            if (array_keys($objectAsArray) !== range(0, $max)) {
163 163
                 $pairs = $objectAsArray;
164 164
             } else {
165
-                $valuesList = array_map([self, 'dump'], $objectAsArray, array_fill( 0 , $max , $indent ));
165
+                $valuesList = array_map([self, 'dump'], $objectAsArray, array_fill(0, $max, $indent));
166 166
                 return '['.implode(', ', $valuesList).']';
167 167
             }
168 168
         } else {
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -39,7 +39,9 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public static function toString($dataType, int $options = null):string
41 41
     {
42
-        if (is_null($dataType)) throw new \Exception(self::class.": No content to convert to Yaml", 1);
42
+        if (is_null($dataType)) {
43
+            throw new \Exception(self::class.": No content to convert to Yaml", 1);
44
+        }
43 45
         self::$options = is_int($options) ? $options : self::OPTIONS;
44 46
         self::$result = new DLL;
45 47
         if ($dataType instanceof YamlObject) {
@@ -73,9 +75,13 @@  discard block
 block discarded – undo
73 75
         if (is_scalar($dataType)) {
74 76
             switch (gettype($dataType)) {
75 77
                 case 'boolean': return $dataType ? 'true' : 'false';
76
-                case 'float': if (is_infinite($dataType)) return $dataType > 0 ? '.inf' : '-.inf';
78
+                case 'float': if (is_infinite($dataType)) {
79
+                    return $dataType > 0 ? '.inf' : '-.inf';
80
+                }
77 81
                               return sprintf('%.2F', $dataType);
78
-                case 'double': if (is_nan((float) $dataType)) return '.nan';
82
+                case 'double': if (is_nan((float) $dataType)) {
83
+                    return '.nan';
84
+                }
79 85
                 default:
80 86
                     return $dataType;
81 87
             }
@@ -139,9 +145,13 @@  discard block
 block discarded – undo
139 145
                 self::add(self::dump($obj->value, $indent + self::INDENT), $indent + self::INDENT);
140 146
             }
141 147
         }
142
-        if ($obj instanceof Compact) return self::dumpCompact($obj, $indent);
148
+        if ($obj instanceof Compact) {
149
+            return self::dumpCompact($obj, $indent);
150
+        }
143 151
         //TODO:  consider dumping datetime as date strings according to a format provided by user or default
144
-        if ($obj instanceof \DateTime) return $obj->format('Y-m-d');
152
+        if ($obj instanceof \DateTime) {
153
+            return $obj->format('Y-m-d');
154
+        }
145 155
         $propList = get_object_vars($obj);
146 156
         foreach ($propList as $property => $value) {
147 157
             if (is_scalar($value)) {
Please login to merge, or discard this patch.
yaml/Builder.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -89,11 +89,11 @@
 block discarded – undo
89 89
 
90 90
         if ($type & Y::COMMENT) self::$_root->addComment($node->line, $node->value);
91 91
         $typesActions = [Y::DIRECTIVE => 'buildDirective',
92
-                         Y::ITEM      => 'buildItem',
93
-                         Y::KEY       => 'buildKey',
94
-                         Y::SET_KEY   => 'buildSetKey',
95
-                         Y::SET_VALUE => 'buildSetValue',
96
-                         Y::TAG       => 'buildTag',
92
+                            Y::ITEM      => 'buildItem',
93
+                            Y::KEY       => 'buildKey',
94
+                            Y::SET_KEY   => 'buildSetKey',
95
+                            Y::SET_VALUE => 'buildSetValue',
96
+                            Y::TAG       => 'buildTag',
97 97
         ];
98 98
         if (isset($typesActions[$type])) {
99 99
             return self::{$typesActions[$type]}($node, $parent);
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
      */
44 44
     private static function buildNodeList(NodeList $node, &$parent)
45 45
     {
46
-        if ($node->type & (Y::RAW | Y::LITTERALS)) {
46
+        if ($node->type & (Y::RAW|Y::LITTERALS)) {
47 47
             return self::buildLitteral($node, $node->type);
48 48
         }
49 49
         $p = $parent;
50 50
         switch ($node->type) {
51 51
             case Y::MAPPING: // fall through
52 52
             case Y::SET:      $p = new \StdClass; break;
53
-            case Y::SEQUENCE: $p = [];break;
53
+            case Y::SEQUENCE: $p = []; break;
54 54
         }
55 55
         $out = null;
56 56
         foreach ($node as $child) {
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     private static function buildNode(Node $node, &$parent)
78 78
     {
79 79
         extract((array) $node, EXTR_REFS);
80
-        if ($type & (Y::REF_DEF | Y::REF_CALL)) {
80
+        if ($type&(Y::REF_DEF|Y::REF_CALL)) {
81 81
             if (is_object($value)) {
82 82
                 $tmp = self::build($value, $parent) ?? $parent;
83 83
             } else {
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
             return self::$_root->getReference($identifier);
88 88
         }
89 89
 
90
-        if ($type & Y::COMMENT) self::$_root->addComment($node->line, $node->value);
90
+        if ($type&Y::COMMENT) self::$_root->addComment($node->line, $node->value);
91 91
         $typesActions = [Y::DIRECTIVE => 'buildDirective',
92 92
                          Y::ITEM      => 'buildItem',
93 93
                          Y::KEY       => 'buildKey',
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
                 $target = $value->type & Y::ITEM ? [] : new \StdClass;
126 126
                 self::build($value, $target);
127 127
             } elseif (is_object($value)) {
128
-                if (is_null($value->type) && $value->getTypes() & Y::SCALAR && !($value->getTypes() & Y::COMMENT)) {
128
+                if (is_null($value->type) && $value->getTypes()&Y::SCALAR && !($value->getTypes()&Y::COMMENT)) {
129 129
                     $target = self::buildLitteral($value, Y::LITT_FOLDED);
130 130
                 } else {
131 131
                     $target = self::build($value, $target);
@@ -203,15 +203,15 @@  discard block
 block discarded – undo
203 203
     {
204 204
         self::$_root = new YamlObject();
205 205
         $childTypes = $list->getTypes();
206
-        $isaMapping  = (bool) (Y::KEY | Y::MAPPING) & $childTypes;
206
+        $isaMapping  = (bool) (Y::KEY|Y::MAPPING)&$childTypes;
207 207
         $isaSequence = (bool) Y::ITEM & $childTypes;
208 208
         $isaSet      = (bool) Y::SET_VALUE & $childTypes;
209 209
         if ($isaMapping && $isaSequence) {
210 210
             throw new \ParseError(sprintf(self::INVALID_DOCUMENT, $key));
211 211
         } else {
212 212
             switch (true) {
213
-                case $isaSequence: $list->type = Y::SEQUENCE;break;
214
-                case $isaSet:      $list->type = Y::SET;break;
213
+                case $isaSequence: $list->type = Y::SEQUENCE; break;
214
+                case $isaSet:      $list->type = Y::SET; break;
215 215
                 default:           $list->type = Y::MAPPING;
216 216
             }
217 217
         }
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
                 $lines[] = self::buildLitteral($child->value, $type);
263 263
             } else {
264 264
                 $prefix = '';
265
-                if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
265
+                if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
266 266
                     $prefix = "\n";
267 267
                 }
268 268
                 if (!($child->type & (Y::SCALAR|Y::BLANK))) {
269 269
                     switch ($child->type) {
270
-                        case Y::ITEM:    $child->value = '- '.$child->value;break;
271
-                        case Y::COMMENT: $child->value = '# '.$child->value;break;
270
+                        case Y::ITEM:    $child->value = '- '.$child->value; break;
271
+                        case Y::COMMENT: $child->value = '# '.$child->value; break;
272 272
                         default: //die(__METHOD__.Y::getName($child->type));
273 273
                     }
274 274
                 }
@@ -280,9 +280,9 @@  discard block
 block discarded – undo
280 280
                 $lines[] = $prefix.$child->value;
281 281
             }
282 282
         }
283
-        if ($type & Y::RAW)         return implode('',   $lines);
284
-        if ($type & Y::LITT)        return implode("\n", $lines);
285
-        if ($type & Y::LITT_FOLDED) return preg_replace(['/ +(\n)/','/(\n+) +/'], "$1", implode(' ',  $lines));
283
+        if ($type&Y::RAW)         return implode('', $lines);
284
+        if ($type&Y::LITT)        return implode("\n", $lines);
285
+        if ($type&Y::LITT_FOLDED) return preg_replace(['/ +(\n)/', '/(\n+) +/'], "$1", implode(' ', $lines));
286 286
         return '';
287 287
     }
288 288
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     private function buildSetKey(Node $node, &$parent)
298 298
     {
299 299
         $built = self::build($node->value, $parent);
300
-        $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built;
300
+        $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built;
301 301
         $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
302 302
         // if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1);
303 303
         $parent->{trim($key, '\'" ')} = null;
Please login to merge, or discard this patch.
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
      */
30 30
     private static function build(object $node, &$parent = null)
31 31
     {
32
-        if ($node instanceof NodeList) return self::buildNodeList($node, $parent);
32
+        if ($node instanceof NodeList) {
33
+            return self::buildNodeList($node, $parent);
34
+        }
33 35
         return self::buildNode($node, $parent);
34 36
     }
35 37
 
@@ -83,11 +85,15 @@  discard block
 block discarded – undo
83 85
             } else {
84 86
                 $tmp = Node2PHP::get($node);
85 87
             }
86
-            if ($type === Y::REF_DEF) self::$_root->addReference($identifier, $tmp);
88
+            if ($type === Y::REF_DEF) {
89
+                self::$_root->addReference($identifier, $tmp);
90
+            }
87 91
             return self::$_root->getReference($identifier);
88 92
         }
89 93
 
90
-        if ($type & Y::COMMENT) self::$_root->addComment($node->line, $node->value);
94
+        if ($type & Y::COMMENT) {
95
+            self::$_root->addComment($node->line, $node->value);
96
+        }
91 97
         $typesActions = [Y::DIRECTIVE => 'buildDirective',
92 98
                          Y::ITEM      => 'buildItem',
93 99
                          Y::KEY       => 'buildKey',
@@ -179,10 +185,14 @@  discard block
 block discarded – undo
179 185
         }
180 186
         $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE);
181 187
         foreach ($_root->value as $child) {
182
-            if ($child->type & Y::DOC_START) $totalDocStart++;
188
+            if ($child->type & Y::DOC_START) {
189
+                $totalDocStart++;
190
+            }
183 191
             //if 0 or 1 DOC_START = we are still in first document
184 192
             $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;
185
-            if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList();
193
+            if (!isset($documents[$currentDoc])) {
194
+                $documents[$currentDoc] = new NodeList();
195
+            }
186 196
             $documents[$currentDoc]->push($child);
187 197
         }
188 198
         $content = array_map([self::class, 'buildDocument'], $documents, array_keys($documents));
@@ -280,9 +290,15 @@  discard block
 block discarded – undo
280 290
                 $lines[] = $prefix.$child->value;
281 291
             }
282 292
         }
283
-        if ($type & Y::RAW)         return implode('',   $lines);
284
-        if ($type & Y::LITT)        return implode("\n", $lines);
285
-        if ($type & Y::LITT_FOLDED) return preg_replace(['/ +(\n)/','/(\n+) +/'], "$1", implode(' ',  $lines));
293
+        if ($type & Y::RAW) {
294
+            return implode('',   $lines);
295
+        }
296
+        if ($type & Y::LITT) {
297
+            return implode("\n", $lines);
298
+        }
299
+        if ($type & Y::LITT_FOLDED) {
300
+            return preg_replace(['/ +(\n)/','/(\n+) +/'], "$1", implode(' ',  $lines));
301
+        }
286 302
         return '';
287 303
     }
288 304
 
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
@@ -25,8 +25,12 @@
 block discarded – undo
25 25
     public function jsonSerialize():array
26 26
     {
27 27
         $prop = get_object_vars($this);
28
-        if (count($prop) > 0) return $prop;
29
-        if (count($this) > 0) return iterator_to_array($this);
28
+        if (count($prop) > 0) {
29
+            return $prop;
30
+        }
31
+        if (count($this) > 0) {
32
+            return iterator_to_array($this);
33
+        }
30 34
     }
31 35
 
32 36
     /**
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
@@ -19,17 +19,17 @@  discard block
 block discarded – undo
19 19
     /* @var null|string */
20 20
     public static $error;
21 21
 
22
-    public const EXCLUDE_DIRECTIVES = 1;//DONT include_directive
23
-    public const IGNORE_COMMENTS    = 2;//DONT include_comments
24
-    public const NO_PARSING_EXCEPTIONS = 4;//THROW Exception on parsing Errors
25
-    public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object
22
+    public const EXCLUDE_DIRECTIVES = 1; //DONT include_directive
23
+    public const IGNORE_COMMENTS    = 2; //DONT include_comments
24
+    public const NO_PARSING_EXCEPTIONS = 4; //THROW Exception on parsing Errors
25
+    public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object
26 26
     //privates
27 27
     /* @var null|string */
28 28
     private $content;
29 29
     /* @var null|string */
30 30
     private $filePath;
31 31
     /* @var integer */
32
-    private $debug = 0;///TODO: determine levels
32
+    private $debug = 0; ///TODO: determine levels
33 33
     /* @var integer */
34 34
     private $options = 0;
35 35
     //Exceptions messages
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
         $previous = $root = new Node();
93 93
         $emptyLines = [];
94 94
         try { //var_dump($source);
95
-            $gen = function () use($source) {
95
+            $gen = function() use($source) {
96 96
                 foreach ($source as $key => $value) {
97 97
                     yield ++$key => $value;
98 98
                 }
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
                     case 0:
120 120
                         if ($n->type & Y::KEY && $n->indent === 0) {
121 121
                             $target = $root;
122
-                        } elseif($n->type & Y::ITEM && $deepest->type & Y::KEY && is_null($deepest->value)) {
122
+                        } elseif ($n->type & Y::ITEM && $deepest->type & Y::KEY && is_null($deepest->value)) {
123 123
                             $target = $deepest;
124 124
                         } else {
125 125
                             $target = $previous->getParent();
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -88,7 +88,9 @@  discard block
 block discarded – undo
88 88
     {
89 89
         $source = $this->content ?? preg_split("/\n/m", preg_replace('/(\r\n|\r)/', "\n", $strContent), 0, PREG_SPLIT_DELIM_CAPTURE);
90 90
         //TODO : be more permissive on $strContent values
91
-        if (!is_array($source) || !count($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT);
91
+        if (!is_array($source) || !count($source)) {
92
+            throw new \Exception(self::EXCEPTION_LINE_SPLIT);
93
+        }
92 94
         $previous = $root = new Node();
93 95
         $emptyLines = [];
94 96
         try { //var_dump($source);
@@ -101,7 +103,9 @@  discard block
 block discarded – undo
101 103
                 $n = new Node($lineString, $lineNb);
102 104
                 $deepest = $previous->getDeepestNode();
103 105
                 if ($n->type & (Y::LITTERALS|Y::BLANK|Y::COMMENT) || $deepest->type & Y::PARTIAL) {
104
-                    if ($this->onSpecialType($n, $previous, $emptyLines, $lineString)) continue;
106
+                    if ($this->onSpecialType($n, $previous, $emptyLines, $lineString)) {
107
+                        continue;
108
+                    }
105 109
                 }
106 110
                 //Note: 6.6 comments: Note that outside scalar content, a line containing only white space characters is taken to be a comment line.
107 111
                     foreach ($emptyLines as $blankNode) {
@@ -135,7 +139,9 @@  discard block
 block discarded – undo
135 139
                             }
136 140
                         }
137 141
                 }
138
-                if ($this->onContextType($n, $target, $lineString)) continue;
142
+                if ($this->onContextType($n, $target, $lineString)) {
143
+                    continue;
144
+                }
139 145
                 $target->add($n);
140 146
                 $previous = $n;
141 147
             }
@@ -172,8 +178,12 @@  discard block
 block discarded – undo
172 178
             return true;
173 179
         }
174 180
         if ($n->type & Y::BLANK) {
175
-            if ($previous->type & Y::SCALAR) $emptyLines[] = $n->setParent($previous->getParent());
176
-            if ($deepest->type & Y::LITTERALS) $emptyLines[] = $n->setParent($deepest);
181
+            if ($previous->type & Y::SCALAR) {
182
+                $emptyLines[] = $n->setParent($previous->getParent());
183
+            }
184
+            if ($deepest->type & Y::LITTERALS) {
185
+                $emptyLines[] = $n->setParent($deepest);
186
+            }
177 187
             return true;
178 188
         }
179 189
         //comment is fullline : forces 'root' as parent IF NOT inside a LITTERAL
Please login to merge, or discard this patch.
yaml/Node.php 3 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -178,9 +178,9 @@
 block discarded – undo
178 178
             return;
179 179
         }
180 180
         if (in_array($first, ['{', '['])) {
181
-             $this->onCompact($nodeValue);
182
-             return;
183
-         }
181
+                $this->onCompact($nodeValue);
182
+                return;
183
+            }
184 184
         if (in_array($first, ['!', '&', '*'])) {
185 185
             $this->onNodeAction($nodeValue);
186 186
             return;
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
             return;
187 187
         }
188 188
         // Note : php don't like '?' as an array key -_-'
189
-        if(in_array($first, ['?', ':'])) {
189
+        if (in_array($first, ['?', ':'])) {
190 190
             $this->type = $first === '?' ? Y::SET_KEY : Y::SET_VALUE;
191 191
             if (!empty(trim($v))) {
192 192
                 $this->value = new NodeList;
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
             $this->onHyphen($nodeValue);
199 199
             return;
200 200
         }
201
-        $characters = [ '#' =>  [Y::COMMENT, ltrim($v)],
201
+        $characters = ['#' =>  [Y::COMMENT, ltrim($v)],
202 202
                         '%' =>  [Y::DIRECTIVE, ltrim($v)],
203 203
                         '>' =>  [Y::LITT_FOLDED, null],
204 204
                         '|' =>  [Y::LITT, null]
@@ -251,15 +251,15 @@  discard block
 block discarded – undo
251 251
     {
252 252
         $this->value = $value;
253 253
         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
-        if (preg_match(R::MAPPING, $value)){
258
+        if (preg_match(R::MAPPING, $value)) {
259 259
             $this->type = Y::COMPACT_MAPPING;
260 260
             return;
261 261
         }
262
-        if (preg_match(R::SEQUENCE, $value)){
262
+        if (preg_match(R::SEQUENCE, $value)) {
263 263
             $this->type = Y::COMPACT_SEQUENCE;
264 264
             return;
265 265
         }
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -67,7 +67,9 @@  discard block
 block discarded – undo
67 67
         if ($this->type === Y::ROOT) {
68 68
             return $this;
69 69
         }
70
-        if (!is_int($indent)) return $this->parent ?? $this;
70
+        if (!is_int($indent)) {
71
+            return $this->parent ?? $this;
72
+        }
71 73
         $cursor = $this;
72 74
         while ($cursor instanceof Node && $cursor->indent >= $indent) {
73 75
             if ($cursor->indent === $indent && $cursor->type !== $type) {
@@ -106,13 +108,21 @@  discard block
 block discarded – undo
106 108
                     $this->value->push($current);
107 109
                 }
108 110
                 //modify type according to child
109
-                if ($current->type & Y::SET_KEY)   $this->value->type = Y::SET;
110
-                if ($current->type & Y::KEY)       $this->value->type = Y::MAPPING;
111
-                if ($current->type & Y::ITEM)      $this->value->type = Y::SEQUENCE;
111
+                if ($current->type & Y::SET_KEY) {
112
+                    $this->value->type = Y::SET;
113
+                }
114
+                if ($current->type & Y::KEY) {
115
+                    $this->value->type = Y::MAPPING;
116
+                }
117
+                if ($current->type & Y::ITEM) {
118
+                    $this->value->type = Y::SEQUENCE;
119
+                }
112 120
             }
113 121
             $this->value->push($child);
114 122
 
115
-            if ($this->type & Y::LITTERALS)  $this->value->type = $this->type;
123
+            if ($this->type & Y::LITTERALS) {
124
+                $this->value->type = $this->type;
125
+            }
116 126
         }
117 127
     }
118 128
 
Please login to merge, or discard this patch.
yaml/Node2PHP.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,8 +26,8 @@
 block discarded – undo
26 26
         if ($n->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE))
27 27
             return self::getCompact(substr($n->value, 1, -1), $n->type);
28 28
         $expected = [Y::JSON   => json_decode($n->value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR),
29
-                     Y::QUOTED => trim($n->value, "\"'"),
30
-                     Y::RAW    => strval($n->value)];
29
+                        Y::QUOTED => trim($n->value, "\"'"),
30
+                        Y::RAW    => strval($n->value)];
31 31
         return $expected[$n->type] ?? null;
32 32
     }
33 33
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
     public static function get(Node $n)
23 23
     {
24 24
         if (is_null($n->value)) return null;
25
-        if ($n->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($n->value);
26
-        if ($n->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE))
25
+        if ($n->type & (Y::REF_CALL|Y::SCALAR)) return self::getScalar($n->value);
26
+        if ($n->type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE))
27 27
             return self::getCompact(substr($n->value, 1, -1), $n->type);
28 28
         $expected = [Y::JSON   => json_decode($n->value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR),
29 29
                      Y::QUOTED => trim($n->value, "\"'"),
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
         //TODO : this should handle references present inside the string
82 82
         $out = new Compact();
83 83
         if ($type === Y::COMPACT_SEQUENCE) {
84
-            $f = function ($e) { return self::getScalar(trim($e));};
84
+            $f = function($e) { return self::getScalar(trim($e)); };
85 85
             //TODO : that's not robust enough, improve it
86 86
             foreach (array_map($f, explode(",", $mappingOrSeqString)) as $key => $value) {
87 87
                 $out[$key] = $value;
Please login to merge, or discard this patch.
Braces   +21 added lines, -8 removed lines patch added patch discarded remove patch
@@ -21,10 +21,15 @@  discard block
 block discarded – undo
21 21
      */
22 22
     public static function get(Node $n)
23 23
     {
24
-        if (is_null($n->value)) return null;
25
-        if ($n->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($n->value);
26
-        if ($n->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE))
27
-            return self::getCompact(substr($n->value, 1, -1), $n->type);
24
+        if (is_null($n->value)) {
25
+            return null;
26
+        }
27
+        if ($n->type & (Y::REF_CALL | Y::SCALAR)) {
28
+            return self::getScalar($n->value);
29
+        }
30
+        if ($n->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) {
31
+                    return self::getCompact(substr($n->value, 1, -1), $n->type);
32
+        }
28 33
         $expected = [Y::JSON   => json_decode($n->value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR),
29 34
                      Y::QUOTED => trim($n->value, "\"'"),
30 35
                      Y::RAW    => strval($n->value)];
@@ -40,8 +45,12 @@  discard block
 block discarded – undo
40 45
      */
41 46
     private static function getScalar(string $v)
42 47
     {
43
-        if (R::isDate($v))   return date_create($v);
44
-        if (R::isNumber($v)) return self::getNumber($v);
48
+        if (R::isDate($v)) {
49
+            return date_create($v);
50
+        }
51
+        if (R::isNumber($v)) {
52
+            return self::getNumber($v);
53
+        }
45 54
         $types = ['yes'   => true,
46 55
                     'no'    => false,
47 56
                     'true'  => true,
@@ -63,8 +72,12 @@  discard block
 block discarded – undo
63 72
      */
64 73
     private static function getNumber(string $v)
65 74
     {
66
-        if (preg_match("/^(0o\d+)$/i", $v))      return intval(base_convert($v, 8, 10));
67
-        if (preg_match("/^(0x[\da-f]+)$/i", $v)) return intval(base_convert($v, 16, 10));
75
+        if (preg_match("/^(0o\d+)$/i", $v)) {
76
+            return intval(base_convert($v, 8, 10));
77
+        }
78
+        if (preg_match("/^(0x[\da-f]+)$/i", $v)) {
79
+            return intval(base_convert($v, 16, 10));
80
+        }
68 81
         return is_bool(strpos($v, '.')) ? intval($v) : floatval($v);
69 82
     }
70 83
 
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,14 +6,14 @@
 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 15
 // $yaml = Y::parseFile('./tests/cases/parsing/blockChompingWithInsideBlank.yml', null, 0); //->parse();
16
-$content = file_get_contents('./tests/cases/parsing/tags_in_compact.yml');//var_dump($content);
16
+$content = file_get_contents('./tests/cases/parsing/tags_in_compact.yml'); //var_dump($content);
17 17
 $yaml = Y::parse($content, null, 2); //->parse();
18 18
 // $yaml = Y::parseFile('./references/Example 2.27.yml', null, 1);
19 19
 var_dump($yaml);
Please login to merge, or discard this patch.