Completed
Push — master ( ea75f3...6b8e06 )
by stéphane
03:22
created
yaml/YamlObject.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
     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.
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 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 \Countable) {
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->push("---");
100
+        if ($dataType->hasDocStart()) {
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/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|Y::TAG) || $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.
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/multiline_quoted_with_blank.yml');//var_dump($content);
15
+$content = file_get_contents('./tests/cases/parsing/multiline_quoted_with_blank.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, 2);
18 18
 // $yaml = Y::parseFile('./references/Example 2.27.yml', null, 1);
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
@@ -181,9 +181,9 @@
 block discarded – undo
181 181
             return;
182 182
         }
183 183
         if (in_array($first, ['{', '['])) {
184
-             $this->onCompact(trim($nodeValue));
185
-             return;
186
-         }
184
+                $this->onCompact(trim($nodeValue));
185
+                return;
186
+            }
187 187
         if (in_array($first, ['!', '&', '*'])) {
188 188
             $this->onNodeAction($nodeValue);
189 189
             return;
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -68,7 +68,9 @@  discard block
 block discarded – undo
68 68
         if ($this->type === Y::ROOT) {
69 69
             return $this;
70 70
         }
71
-        if (!is_int($indent)) return $this->parent ?? $this;
71
+        if (!is_int($indent)) {
72
+            return $this->parent ?? $this;
73
+        }
72 74
         $cursor = $this;
73 75
         while ($cursor instanceof Node && $cursor->indent >= $indent) {
74 76
             if ($cursor->indent === $indent && $cursor->type !== $type) {
@@ -110,13 +112,21 @@  discard block
 block discarded – undo
110 112
         }
111 113
         //modify type according to child
112 114
         if (is_null($this->value->type)) {
113
-            if ($child->type & Y::SET_KEY)   $this->value->type = Y::SET;
114
-            if ($child->type & Y::KEY)       $this->value->type = Y::MAPPING;
115
-            if ($child->type & Y::ITEM)      $this->value->type = Y::SEQUENCE;
115
+            if ($child->type & Y::SET_KEY) {
116
+                $this->value->type = Y::SET;
117
+            }
118
+            if ($child->type & Y::KEY) {
119
+                $this->value->type = Y::MAPPING;
120
+            }
121
+            if ($child->type & Y::ITEM) {
122
+                $this->value->type = Y::SEQUENCE;
123
+            }
116 124
         }
117 125
         $this->value->push($child);
118 126
 
119
-        if ($this->type & Y::LITTERALS)  $this->value->type = $this->type;
127
+        if ($this->type & Y::LITTERALS) {
128
+            $this->value->type = $this->type;
129
+        }
120 130
     }
121 131
 
122 132
     /**
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
             return;
190 190
         }
191 191
         // Note : php don't like '?' as an array key -_-'
192
-        if(in_array($first, ['?', ':'])) {
192
+        if (in_array($first, ['?', ':'])) {
193 193
             $this->type = $first === '?' ? Y::SET_KEY : Y::SET_VALUE;
194 194
             if (!empty(trim($v))) {
195 195
                 $this->value = new NodeList;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
             $this->onHyphen($nodeValue);
202 202
             return;
203 203
         }
204
-        $characters = [ '#' =>  [Y::COMMENT, ltrim($v)],
204
+        $characters = ['#' =>  [Y::COMMENT, ltrim($v)],
205 205
                         '%' =>  [Y::DIRECTIVE, ltrim($v)],
206 206
                         '>' =>  [Y::LITT_FOLDED, null],
207 207
                         '|' =>  [Y::LITT, null]
@@ -254,28 +254,28 @@  discard block
 block discarded – undo
254 254
     private function onCompact($value)
255 255
     {
256 256
         $this->value = json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
257
-        if (json_last_error() === JSON_ERROR_NONE){
257
+        if (json_last_error() === JSON_ERROR_NONE) {
258 258
             $this->type = Y::JSON;
259 259
             return;
260 260
         }
261 261
         $this->value = new NodeList();
262
-        if (preg_match(R::MAPPING, $value)){
262
+        if (preg_match(R::MAPPING, $value)) {
263 263
             $this->type = Y::COMPACT_MAPPING;
264 264
             $this->value->type = Y::COMPACT_MAPPING;
265
-            preg_match_all(R::MAPPING_VALUES, trim(substr($value, 1,-1)), $matches);
265
+            preg_match_all(R::MAPPING_VALUES, trim(substr($value, 1, -1)), $matches);
266 266
             foreach ($matches['k'] as $index => $property) {
267 267
                 $n = new Node('', $this->line);
268 268
                 $n->type = Y::KEY;
269
-                $n->identifier = trim($property, '"\' ');//TODO : maybe check for proper quoting first ?
269
+                $n->identifier = trim($property, '"\' '); //TODO : maybe check for proper quoting first ?
270 270
                 $n->value = new Node($matches['v'][$index], $this->line);
271 271
                 $this->value->push($n);
272 272
             }
273 273
             return;
274 274
         }
275
-        if (preg_match(R::SEQUENCE, $value)){
275
+        if (preg_match(R::SEQUENCE, $value)) {
276 276
             $this->type = Y::COMPACT_SEQUENCE;
277 277
             $this->value->type = Y::COMPACT_SEQUENCE;
278
-            $count = preg_match_all(R::SEQUENCE_VALUES, trim(substr($value, 1,-1)), $matches);
278
+            $count = preg_match_all(R::SEQUENCE_VALUES, trim(substr($value, 1, -1)), $matches);
279 279
             foreach ($matches['item'] as $key => $item) {
280 280
                 $i = new Node('', $this->line);
281 281
                 $i->type = Y::ITEM;
Please login to merge, or discard this patch.
yaml/Builder.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
         } else {
175 175
             $tmpString = null;//var_dump("PAS ICI");
176 176
             foreach ($node as $key => $child) {
177
-                 if ($child->type & (Y::SCALAR|Y::QUOTED)) {
177
+                    if ($child->type & (Y::SCALAR|Y::QUOTED)) {
178 178
                     if ($parent) {
179 179
                         $parent->setText(self::build($child, $parent));
180 180
                     } else {
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
         }
215 215
         if ($type & Y::COMMENT) self::$_root->addComment($node->line, $node->value);
216 216
         $typesActions = [Y::DIRECTIVE => 'buildDirective',
217
-                         Y::ITEM      => 'buildItem',
218
-                         Y::KEY       => 'buildKey',
219
-                         Y::SET_KEY   => 'buildSetKey',
220
-                         Y::SET_VALUE => 'buildSetValue',
221
-                         Y::TAG       => 'buildTag',
217
+                            Y::ITEM      => 'buildItem',
218
+                            Y::KEY       => 'buildKey',
219
+                            Y::SET_KEY   => 'buildSetKey',
220
+                            Y::SET_VALUE => 'buildSetValue',
221
+                            Y::TAG       => 'buildTag',
222 222
         ];
223 223
         if (isset($typesActions[$type])) {
224 224
             return self::{$typesActions[$type]}($node, $parent);
Please login to merge, or discard this patch.
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -44,10 +44,14 @@  discard block
 block discarded – undo
44 44
         }
45 45
         $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE);
46 46
         foreach ($_root->value as $child) {
47
-            if ($child->type & Y::DOC_START) $totalDocStart++;
47
+            if ($child->type & Y::DOC_START) {
48
+                $totalDocStart++;
49
+            }
48 50
             //if 0 or 1 DOC_START = we are still in first document
49 51
             $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;
50
-            if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList();
52
+            if (!isset($documents[$currentDoc])) {
53
+                $documents[$currentDoc] = new NodeList();
54
+            }
51 55
             $documents[$currentDoc]->push($child);
52 56
         }
53 57
         // $content = array_map([self::class, 'buildDocument'], $documents, array_keys($documents));
@@ -117,7 +121,9 @@  discard block
 block discarded – undo
117 121
      */
118 122
     private static function build(object $node, &$parent = null)
119 123
     {
120
-        if ($node instanceof NodeList) return self::buildNodeList($node, $parent);
124
+        if ($node instanceof NodeList) {
125
+            return self::buildNodeList($node, $parent);
126
+        }
121 127
         return self::buildNode($node, $parent);
122 128
     }
123 129
 
@@ -206,13 +212,17 @@  discard block
 block discarded – undo
206 212
             } else {
207 213
                 $tmp = Node2PHP::get($node);
208 214
             }
209
-            if ($type === Y::REF_DEF) self::$_root->addReference($identifier, $tmp);
215
+            if ($type === Y::REF_DEF) {
216
+                self::$_root->addReference($identifier, $tmp);
217
+            }
210 218
             return self::$_root->getReference($identifier);
211 219
         }
212 220
         if ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) {
213 221
             return self::buildNodeList($node->value, $parent);
214 222
         }
215
-        if ($type & Y::COMMENT) self::$_root->addComment($node->line, $node->value);
223
+        if ($type & Y::COMMENT) {
224
+            self::$_root->addComment($node->line, $node->value);
225
+        }
216 226
         $typesActions = [Y::DIRECTIVE => 'buildDirective',
217 227
                          Y::ITEM      => 'buildItem',
218 228
                          Y::KEY       => 'buildKey',
@@ -351,9 +361,15 @@  discard block
 block discarded – undo
351 361
                 $lines[] = $prefix.$val;
352 362
             }
353 363
         }
354
-        if ($type & Y::RAW)         return implode('',   $lines);
355
-        if ($type & Y::LITT)        return implode("\n", $lines);
356
-        if ($type & Y::LITT_FOLDED) return preg_replace(['/ +(\n)/','/(\n+) +/'], "$1", implode(' ',  $lines));
364
+        if ($type & Y::RAW) {
365
+            return implode('',   $lines);
366
+        }
367
+        if ($type & Y::LITT) {
368
+            return implode("\n", $lines);
369
+        }
370
+        if ($type & Y::LITT_FOLDED) {
371
+            return preg_replace(['/ +(\n)/','/(\n+) +/'], "$1", implode(' ',  $lines));
372
+        }
357 373
         return '';
358 374
     }
359 375
 
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
             $q->push($_root->value);
39 39
             // return self::buildNodeList($q, new YamlObject);
40 40
             self::$_root = new YamlObject;
41
-            $tmp =  self::buildNodeList($q, self::$_root);
41
+            $tmp = self::buildNodeList($q, self::$_root);
42 42
             // var_dump('alone', $tmp);
43 43
             return $tmp;
44 44
         }
@@ -87,31 +87,31 @@  discard block
 block discarded – undo
87 87
      *
88 88
      * @return mixed    The parent (object|array) or a string representing the NodeList.
89 89
      */
90
-    private static function buildNodeList(NodeList $node, &$parent=null)
90
+    private static function buildNodeList(NodeList $node, &$parent = null)
91 91
     {
92 92
         if (is_null($node->type)) {
93
-            $childTypes  = $node->getTypes();
94
-            if ($childTypes & (Y::KEY|Y::SET_KEY)) {
95
-                if ($childTypes & Y::ITEM) {
93
+            $childTypes = $node->getTypes();
94
+            if ($childTypes&(Y::KEY|Y::SET_KEY)) {
95
+                if ($childTypes&Y::ITEM) {
96 96
                     // TODO: replace the document index in HERE ----------v
97 97
                     throw new \ParseError(sprintf(self::INVALID_DOCUMENT, 0));
98 98
                 } else {
99 99
                     $node->type = Y::MAPPING;
100 100
                 }
101 101
             } else {
102
-                if ($childTypes & Y::ITEM) {
102
+                if ($childTypes&Y::ITEM) {
103 103
                     $node->type = Y::SEQUENCE;
104
-                } elseif (!($childTypes & Y::COMMENT)) {
104
+                } elseif (!($childTypes&Y::COMMENT)) {
105 105
                     $node->type = Y::LITT_FOLDED;
106 106
                 }
107 107
             }
108 108
         }
109 109
         // var_dump('nodetype:'.Y::getName($node->type) );
110
-        if ($node->type & (Y::RAW | Y::LITTERALS)) {
110
+        if ($node->type & (Y::RAW|Y::LITTERALS)) {
111 111
             return self::buildLitteral($node, $node->type);
112 112
         }
113 113
         if ($node->type & (Y::COMPACT_MAPPING|Y::MAPPING|Y::SET)) {
114
-            $out = $parent ?? new \StdClass;//var_dump("PAS LA");
114
+            $out = $parent ?? new \StdClass; //var_dump("PAS LA");
115 115
             foreach ($node as $key => $child) {
116 116
                 if ($child->type & (Y::KEY)) {
117 117
                     self::buildKey($child, $out);
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                 $out = new Compact($out);
124 124
             }
125 125
         } elseif ($node->type & (Y::COMPACT_SEQUENCE|Y::SEQUENCE)) {
126
-            $out = $parent ?? [];//var_dump("HERE");
126
+            $out = $parent ?? []; //var_dump("HERE");
127 127
             foreach ($node as $key => $child) {
128 128
                 if ($child->type & Y::ITEM) {
129 129
                     self::buildItem($child, $out);
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
                 $out = new Compact($out);
136 136
             }
137 137
         } else {
138
-            $tmpString = null;//var_dump("PAS ICI");
138
+            $tmpString = null; //var_dump("PAS ICI");
139 139
             foreach ($node as $key => $child) {
140 140
                  if ($child->type & (Y::SCALAR|Y::QUOTED)) {
141 141
                     if ($parent) {
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
     private static function buildNode(Node $node, &$parent)
164 164
     {
165 165
         extract((array) $node, EXTR_REFS);
166
-        if ($type & (Y::REF_DEF | Y::REF_CALL)) {
166
+        if ($type&(Y::REF_DEF|Y::REF_CALL)) {
167 167
             if (is_object($value)) {
168 168
                 $tmp = self::build($value, $parent) ?? $parent;
169 169
             } else {
@@ -172,10 +172,10 @@  discard block
 block discarded – undo
172 172
             if ($type === Y::REF_DEF) self::$_root->addReference($identifier, $tmp);
173 173
             return self::$_root->getReference($identifier);
174 174
         }
175
-        if ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) {
175
+        if ($type&(Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) {
176 176
             return self::buildNodeList($node->value, $parent);
177 177
         }
178
-        if ($type & Y::COMMENT) self::$_root->addComment($node->line, $node->value);
178
+        if ($type&Y::COMMENT) self::$_root->addComment($node->line, $node->value);
179 179
         $typesActions = [Y::DIRECTIVE => 'buildDirective',
180 180
                          Y::ITEM      => 'buildItem',
181 181
                          Y::KEY       => 'buildKey',
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
      * @throws \ParseError if Key has no name(identifier) Note: empty string is allowed
199 199
      * @return null
200 200
      */
201
-    private static function buildKey(Node $node, &$parent=null)
201
+    private static function buildKey(Node $node, &$parent = null)
202 202
     {
203 203
         extract((array) $node, EXTR_REFS);
204 204
         if (is_null($identifier)) {
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
             }
217 217
             if ($value instanceof NodeList) {
218 218
                 $childTypes = $value->getTypes();
219
-                if (is_null($value->type) && $childTypes & Y::SCALAR && !($childTypes & Y::COMMENT)) {
219
+                if (is_null($value->type) && $childTypes&Y::SCALAR && !($childTypes&Y::COMMENT)) {
220 220
                     $result = self::buildLitteral($value, Y::LITT_FOLDED);
221 221
                 } else {
222 222
                     $result = self::buildNodeList($value);
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
      */
246 246
     private static function buildItem(Node $node, &$parent)
247 247
     {
248
-        extract((array) $node, EXTR_REFS);//var_dump(__METHOD__);
248
+        extract((array) $node, EXTR_REFS); //var_dump(__METHOD__);
249 249
         if (!is_array($parent) && !($parent instanceof \ArrayIterator)) {
250 250
             throw new \Exception("parent must be an Iterable not ".(is_object($parent) ? get_class($parent) : gettype($parent)), 1);
251 251
         }
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
         $numKeys = array_filter(array_keys($ref), 'is_int');
254 254
         $key = count($numKeys) > 0 ? max($numKeys) + 1 : 0;
255 255
         if ($value instanceof Node) {
256
-            if($value->type & Y::KEY) {
256
+            if ($value->type & Y::KEY) {
257 257
                 self::buildKey($node->value, $parent);
258 258
                 return;
259 259
             } elseif ($value->type & Y::ITEM) {
@@ -297,13 +297,13 @@  discard block
 block discarded – undo
297 297
                 $lines[] = self::buildLitteral($child->value, $type);
298 298
             } else {
299 299
                 $prefix = '';
300
-                if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
300
+                if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
301 301
                     $prefix = "\n";
302 302
                 }
303 303
                 if (!($child->type & (Y::SCALAR|Y::BLANK))) {
304 304
                     switch ($child->type) {
305
-                        case Y::ITEM:    $child->value = '- '.$child->value;break;
306
-                        case Y::COMMENT: $child->value = '# '.$child->value;break;
305
+                        case Y::ITEM:    $child->value = '- '.$child->value; break;
306
+                        case Y::COMMENT: $child->value = '# '.$child->value; break;
307 307
                         default: //die(__METHOD__.Y::getName($child->type));
308 308
                     }
309 309
                 }
@@ -314,9 +314,9 @@  discard block
 block discarded – undo
314 314
                 $lines[] = $prefix.$val;
315 315
             }
316 316
         }
317
-        if ($type & Y::RAW)         return implode('',   $lines);
318
-        if ($type & Y::LITT)        return implode("\n", $lines);
319
-        if ($type & Y::LITT_FOLDED) return preg_replace(['/ +(\n)/','/(\n+) +/'], "$1", implode(' ',  $lines));
317
+        if ($type&Y::RAW)         return implode('', $lines);
318
+        if ($type&Y::LITT)        return implode("\n", $lines);
319
+        if ($type&Y::LITT_FOLDED) return preg_replace(['/ +(\n)/', '/(\n+) +/'], "$1", implode(' ', $lines));
320 320
         return '';
321 321
     }
322 322
 
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
     private function buildSetKey(Node $node, &$parent)
332 332
     {
333 333
         $built = is_object($node->value) ? self::build($node->value) : null;
334
-        $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built;
334
+        $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built;
335 335
         $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
336 336
         // if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1);
337 337
         $parent->{trim($key, '\'" ')} = null;
Please login to merge, or discard this patch.
yaml/Node2PHP.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
     public static function get(Node $n)
25 25
     {
26 26
         if (is_null($n->value)) return null;
27
-        if ($n->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($n->value);
27
+        if ($n->type & (Y::REF_CALL|Y::SCALAR)) return self::getScalar($n->value);
28 28
         if ($n->type & Y::JSON) {
29 29
             return $n->value;
30 30
         }
Please login to merge, or discard this patch.
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,8 +23,12 @@  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($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($n->value);
31
+        }
28 32
         if ($n->type & Y::JSON) {
29 33
             return $n->value;
30 34
         }
@@ -43,8 +47,12 @@  discard block
 block discarded – undo
43 47
      */
44 48
     private static function getScalar(string $v)
45 49
     {
46
-        if (R::isDate($v))   return date_create($v);
47
-        if (R::isNumber($v)) return self::getNumber($v);
50
+        if (R::isDate($v)) {
51
+            return date_create($v);
52
+        }
53
+        if (R::isNumber($v)) {
54
+            return self::getNumber($v);
55
+        }
48 56
         $types = ['yes'   => true,
49 57
                     'no'    => false,
50 58
                     'true'  => true,
@@ -66,8 +74,12 @@  discard block
 block discarded – undo
66 74
      */
67 75
     private static function getNumber(string $v)
68 76
     {
69
-        if (preg_match("/^(0o\d+)$/i", $v))      return intval(base_convert($v, 8, 10));
70
-        if (preg_match("/^(0x[\da-f]+)$/i", $v)) return intval(base_convert($v, 16, 10));
77
+        if (preg_match("/^(0o\d+)$/i", $v)) {
78
+            return intval(base_convert($v, 8, 10));
79
+        }
80
+        if (preg_match("/^(0x[\da-f]+)$/i", $v)) {
81
+            return intval(base_convert($v, 16, 10));
82
+        }
71 83
         return is_bool(strpos($v, '.')) ? intval($v) : floatval($v);
72 84
     }
73 85
 }
74 86
\ No newline at end of file
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
             return $n->value;
30 30
         }
31 31
         $expected = [Y::QUOTED => trim((string) $n->value, "\"'"),
32
-                     Y::RAW    => strval((string) $n->value)];
32
+                        Y::RAW    => strval((string) $n->value)];
33 33
         return $expected[$n->type] ?? null;
34 34
     }
35 35
 
Please login to merge, or discard this patch.