Passed
Push — master ( 6b8e06...02b784 )
by stéphane
04:35
created
yaml/YamlObject.php 1 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/Node.php 1 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.
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, 3);
18 18
 // $yaml = Y::parseFile('./references/Example 2.27.yml', null, 1);
Please login to merge, or discard this patch.
yaml/Loader.php 1 patch
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|false|array| */
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
                 }
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
                     case 0:
117 117
                         if ($n->type & Y::KEY && $n->indent === 0) {
118 118
                             $target = $root;
119
-                        } elseif($n->type & Y::ITEM && $deepest->type & Y::KEY && is_null($deepest->value)) {
119
+                        } elseif ($n->type & Y::ITEM && $deepest->type & Y::KEY && is_null($deepest->value)) {
120 120
                             $target = $deepest;
121 121
                         } else {
122 122
                             $target = $previous->getParent();
Please login to merge, or discard this patch.
yaml/Builder.php 1 patch
Spacing   +24 added lines, -24 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,29 +87,29 @@  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
-        if ($node->type & (Y::RAW | Y::LITTERALS)) {
109
+        if ($node->type & (Y::RAW|Y::LITTERALS)) {
110 110
             return self::buildLitteral($node, (int) $node->type);
111 111
         }
112
-        $action = function ($child, &$parent, &$out) {
112
+        $action = function($child, &$parent, &$out) {
113 113
             self::build($child, $out);
114 114
         };
115 115
         if ($node->type & (Y::COMPACT_MAPPING|Y::MAPPING|Y::SET)) {
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
             $out = $parent ?? [];
119 119
         } else {
120 120
             $out = '';
121
-            $action = function ($child, &$out) {
121
+            $action = function($child, &$out) {
122 122
                 if ($child->type & (Y::SCALAR|Y::QUOTED)) {
123 123
                     if ($parent) {
124 124
                         $parent->setText(self::build($child));
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
     private static function buildNode(Node $node, &$parent)
149 149
     {
150 150
         extract((array) $node, EXTR_REFS);
151
-        if ($type & (Y::REF_DEF | Y::REF_CALL)) {
151
+        if ($type&(Y::REF_DEF|Y::REF_CALL)) {
152 152
             if (is_object($value)) {
153 153
                 $tmp = self::build($value, $parent) ?? $parent;
154 154
             } else {
@@ -157,10 +157,10 @@  discard block
 block discarded – undo
157 157
             if ($type === Y::REF_DEF) self::$_root->addReference($identifier, $tmp);
158 158
             return self::$_root->getReference($identifier);
159 159
         }
160
-        if ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) {
160
+        if ($type&(Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) {
161 161
             return self::buildNodeList($node->value, $parent);
162 162
         }
163
-        if ($type & Y::COMMENT) self::$_root->addComment($node->line, $node->value);
163
+        if ($type&Y::COMMENT) self::$_root->addComment($node->line, $node->value);
164 164
         $typesActions = [Y::DIRECTIVE => 'buildDirective',
165 165
                          Y::ITEM      => 'buildItem',
166 166
                          Y::KEY       => 'buildKey',
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
      * @throws \ParseError if Key has no name(identifier) Note: empty string is allowed
184 184
      * @return null
185 185
      */
186
-    private static function buildKey(Node $node, &$parent=null)
186
+    private static function buildKey(Node $node, &$parent = null)
187 187
     {
188 188
         extract((array) $node, EXTR_REFS);
189 189
         if (is_null($identifier)) {
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
             }
202 202
             if ($value instanceof NodeList) {
203 203
                 $childTypes = $value->getTypes();
204
-                if (is_null($value->type) && $childTypes & Y::SCALAR && !($childTypes & Y::COMMENT)) {
204
+                if (is_null($value->type) && $childTypes&Y::SCALAR && !($childTypes&Y::COMMENT)) {
205 205
                     $result = self::buildLitteral($value, Y::LITT_FOLDED);
206 206
                 } else {
207 207
                     $result = self::buildNodeList($value);
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
      */
231 231
     private static function buildItem(Node $node, &$parent)
232 232
     {
233
-        extract((array) $node, EXTR_REFS);//var_dump(__METHOD__);
233
+        extract((array) $node, EXTR_REFS); //var_dump(__METHOD__);
234 234
         if (!is_array($parent) && !($parent instanceof \ArrayIterator)) {
235 235
             throw new \Exception("parent must be an Iterable not ".(is_object($parent) ? get_class($parent) : gettype($parent)), 1);
236 236
         }
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
         $numKeys = array_filter(array_keys($ref), 'is_int');
239 239
         $key = count($numKeys) > 0 ? max($numKeys) + 1 : 0;
240 240
         if ($value instanceof Node) {
241
-            if($value->type & Y::KEY) {
241
+            if ($value->type & Y::KEY) {
242 242
                 self::buildKey($node->value, $parent);
243 243
                 return;
244 244
             } elseif ($value->type & Y::ITEM) {
@@ -282,13 +282,13 @@  discard block
 block discarded – undo
282 282
                 $lines[] = self::buildLitteral($child->value, $type);
283 283
             } else {
284 284
                 $prefix = '';
285
-                if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
285
+                if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
286 286
                     $prefix = "\n";
287 287
                 }
288 288
                 if (!($child->type & (Y::SCALAR|Y::BLANK))) {
289 289
                     switch ($child->type) {
290
-                        case Y::ITEM:    $child->value = '- '.$child->value;break;
291
-                        case Y::COMMENT: $child->value = '# '.$child->value;break;
290
+                        case Y::ITEM:    $child->value = '- '.$child->value; break;
291
+                        case Y::COMMENT: $child->value = '# '.$child->value; break;
292 292
                         default: //die(__METHOD__.Y::getName($child->type));
293 293
                     }
294 294
                 }
@@ -299,9 +299,9 @@  discard block
 block discarded – undo
299 299
                 $lines[] = $prefix.trim($val);
300 300
             }
301 301
         }
302
-        if ($type & Y::RAW)         return implode('',   $lines);
303
-        if ($type & Y::LITT)        return implode("\n", $lines);
304
-        if ($type & Y::LITT_FOLDED) return preg_replace(['/ +(\n)/','/(\n+) +/'], "$1", implode(' ',  $lines));
302
+        if ($type&Y::RAW)         return implode('', $lines);
303
+        if ($type&Y::LITT)        return implode("\n", $lines);
304
+        if ($type&Y::LITT_FOLDED) return preg_replace(['/ +(\n)/', '/(\n+) +/'], "$1", implode(' ', $lines));
305 305
         // TODO : rewrite without 'preg_replace' if ($type & Y::LITT_FOLDED) return implode(' ',  $lines);
306 306
         return '';
307 307
     }
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
     private function buildSetKey(Node $node, &$parent)
318 318
     {
319 319
         $built = is_object($node->value) ? self::build($node->value) : null;
320
-        $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built;
320
+        $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built;
321 321
         $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
322 322
         // if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1);
323 323
         $parent->{trim($key, '\'" ')} = null;
Please login to merge, or discard this patch.
yaml/Dumper.php 1 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.