Test Failed
Push — master ( 44c6e4...f07b2d )
by stéphane
03:54 queued 11s
created
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/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.
yaml/Loader.php 1 patch
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.
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/Node.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
          } elseif (in_array($first, ['!', '&', '*'])) {
187 187
             $this->onNodeAction($nodeValue);
188 188
             return;
189
-        } elseif(in_array($first, ['?', ':'])) {// Note : php don't like '?' as an array key -_-'
189
+        } elseif (in_array($first, ['?', ':'])) {// Note : php don't like '?' as an array key -_-'
190 190
             $this->type = $first === '?' ? Y::SET_KEY : Y::SET_VALUE;
191 191
             if (!empty(trim($v))) {
192 192
                 $this->value = new NodeList;
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
             $this->onHyphen($nodeValue);
198 198
             return;
199 199
         }
200
-        $characters = [ '#' =>  [Y::COMMENT, $v],
200
+        $characters = ['#' =>  [Y::COMMENT, $v],
201 201
                         '%' =>  [Y::DIRECTIVE, $v],
202 202
                         '>' =>  [Y::LITT_FOLDED, null],
203 203
                         '|' =>  [Y::LITT, null]
@@ -249,28 +249,28 @@  discard block
 block discarded – undo
249 249
     private function onCompact($value)
250 250
     {
251 251
         $this->value = json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
252
-        if (json_last_error() === JSON_ERROR_NONE){
252
+        if (json_last_error() === JSON_ERROR_NONE) {
253 253
             $this->type = Y::JSON;
254 254
             return;
255 255
         }
256 256
         $this->value = new NodeList();
257
-        if (preg_match(R::MAPPING, $value)){
257
+        if (preg_match(R::MAPPING, $value)) {
258 258
             $this->type = Y::COMPACT_MAPPING;
259 259
             $this->value->type = Y::COMPACT_MAPPING;
260
-            preg_match_all(R::MAPPING_VALUES, trim(substr($value, 1,-1)), $matches);
260
+            preg_match_all(R::MAPPING_VALUES, trim(substr($value, 1, -1)), $matches);
261 261
             foreach ($matches['k'] as $index => $property) {
262 262
                 $n = new Node('', $this->line);
263 263
                 $n->type = Y::KEY;
264
-                $n->identifier = trim($property, '"\' ');//TODO : maybe check for proper quoting first ?
264
+                $n->identifier = trim($property, '"\' '); //TODO : maybe check for proper quoting first ?
265 265
                 $n->value = new Node($matches['v'][$index], $this->line);
266 266
                 $this->value->push($n);
267 267
             }
268 268
             return;
269 269
         }
270
-        if (preg_match(R::SEQUENCE, $value)){
270
+        if (preg_match(R::SEQUENCE, $value)) {
271 271
             $this->type = Y::COMPACT_SEQUENCE;
272 272
             $this->value->type = Y::COMPACT_SEQUENCE;
273
-            $count = preg_match_all(R::SEQUENCE_VALUES, trim(substr($value, 1,-1)), $matches);
273
+            $count = preg_match_all(R::SEQUENCE_VALUES, trim(substr($value, 1, -1)), $matches);
274 274
             foreach ($matches['item'] as $key => $item) {
275 275
                 $i = new Node('', $this->line);
276 276
                 $i->type = Y::ITEM;
Please login to merge, or discard this patch.
yaml/YamlObject.php 1 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/Builder.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
      *
81 81
      * @return mixed    The parent (object|array) or a string representing the NodeList.
82 82
      */
83
-    private static function buildNodeList(NodeList $node, &$parent=null)
83
+    private static function buildNodeList(NodeList $node, &$parent = null)
84 84
     {
85 85
         $node->forceType();
86
-        if ($node->type & (Y::RAW | Y::LITTERALS)) {
86
+        if ($node->type & (Y::RAW|Y::LITTERALS)) {
87 87
             return self::buildLitteral($node, (int) $node->type);
88 88
         }
89
-        $action = function ($child, &$parent, &$out) {
89
+        $action = function($child, &$parent, &$out) {
90 90
             self::build($child, $out);
91 91
         };
92 92
         if ($node->type & (Y::COMPACT_MAPPING|Y::MAPPING|Y::SET)) {
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             $out = $parent ?? [];
96 96
         } else {
97 97
             $out = '';
98
-            $action = function ($child, &$parent, &$out) {
98
+            $action = function($child, &$parent, &$out) {
99 99
                 if ($child->type & (Y::SCALAR|Y::QUOTED)) {
100 100
                     if ($parent) {
101 101
                         $parent->setText(self::build($child));
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
     private static function buildNode(Node $node, &$parent)
126 126
     {
127 127
         extract((array) $node, EXTR_REFS);
128
-        if ($type & (Y::REF_DEF | Y::REF_CALL)) {
128
+        if ($type&(Y::REF_DEF|Y::REF_CALL)) {
129 129
             if (is_object($value)) {
130 130
                 $tmp = self::build($value, $parent) ?? $parent;
131 131
             } else {
@@ -134,10 +134,10 @@  discard block
 block discarded – undo
134 134
             if ($type === Y::REF_DEF) self::$_root->addReference($identifier, $tmp);
135 135
             return self::$_root->getReference($identifier);
136 136
         }
137
-        if ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) {
137
+        if ($type&(Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) {
138 138
             return self::buildNodeList($node->value, $parent);
139 139
         }
140
-        if ($type & Y::COMMENT) self::$_root->addComment($node->line, $node->value);
140
+        if ($type&Y::COMMENT) self::$_root->addComment($node->line, $node->value);
141 141
         $typesActions = [Y::DIRECTIVE => 'buildDirective',
142 142
                          Y::ITEM      => 'buildItem',
143 143
                          Y::KEY       => 'buildKey',
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
      * @throws \ParseError if Key has no name(identifier) Note: empty string is allowed
161 161
      * @return null
162 162
      */
163
-    private static function buildKey(Node $node, &$parent=null)
163
+    private static function buildKey(Node $node, &$parent = null)
164 164
     {
165 165
         extract((array) $node, EXTR_REFS);
166 166
         if (is_null($identifier)) {
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
             }
179 179
             if ($value instanceof NodeList) {
180 180
                 $childTypes = $value->getTypes();
181
-                if (is_null($value->type) && $childTypes & Y::SCALAR && !($childTypes & Y::COMMENT)) {
181
+                if (is_null($value->type) && $childTypes&Y::SCALAR && !($childTypes&Y::COMMENT)) {
182 182
                     $result = self::buildLitteral($value, Y::LITT_FOLDED);
183 183
                 } else {
184 184
                     $result = self::buildNodeList($value);
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
         $numKeys = array_filter(array_keys($ref), 'is_int');
216 216
         $key = count($numKeys) > 0 ? max($numKeys) + 1 : 0;
217 217
         if ($value instanceof Node) {
218
-            if($value->type & Y::KEY) {
218
+            if ($value->type & Y::KEY) {
219 219
                 self::buildKey($node->value, $parent);
220 220
                 return;
221 221
             } elseif ($value->type & Y::ITEM) {
@@ -250,14 +250,14 @@  discard block
 block discarded – undo
250 250
         }
251 251
         $result = '';
252 252
         $separator = '';
253
-        if ($type & Y::LITT)         $separator = "\n";
254
-        if ($type & Y::LITT_FOLDED)  $separator = ' ';
253
+        if ($type&Y::LITT)         $separator = "\n";
254
+        if ($type&Y::LITT_FOLDED)  $separator = ' ';
255 255
         foreach ($list as $child) {
256 256
             if ($child->value instanceof NodeList) {
257 257
                 $result .= self::buildLitteral($child->value, $type).$separator;
258 258
             } else {
259 259
                 $val = $child->type & (Y::SCALAR|Y::BLANK) ? $child->value : substr($child->raw, $refIndent);
260
-                if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
260
+                if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) {
261 261
                     if ($result[-1] === $separator)
262 262
                         $result[-1] = "\n";
263 263
                     if ($result[-1] === "\n")
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
     private function buildSetKey(Node $node, &$parent)
282 282
     {
283 283
         $built = is_object($node->value) ? self::build($node->value) : null;
284
-        $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built;
284
+        $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built;
285 285
         $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
286 286
         if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1);
287 287
         $parent->{trim($key, '\'" ')} = null;
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     {
298 298
         $prop = array_keys(get_object_vars($parent));
299 299
         $key = end($prop);
300
-        if ($node->value->type & (Y::ITEM|Y::KEY )) {
300
+        if ($node->value->type & (Y::ITEM|Y::KEY)) {
301 301
             $nl = new NodeList;
302 302
             $nl->push($node->value);
303 303
             $node->value = $nl;
Please login to merge, or discard this patch.
yaml/Compact.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
         $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.