Passed
Push — master ( 419cde...d38a64 )
by stéphane
02:51
created
yaml/Loader.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,17 +17,17 @@  discard block
 block discarded – undo
17 17
     //public
18 18
     public $errors = [];
19 19
 
20
-    public const EXCLUDE_DIRECTIVES = 1;//DONT include_directive
21
-    public const IGNORE_COMMENTS    = 2;//DONT include_comments
22
-    public const NO_PARSING_EXCEPTIONS = 4;//THROW Exception on parsing Errors
23
-    public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object
20
+    public const EXCLUDE_DIRECTIVES = 1; //DONT include_directive
21
+    public const IGNORE_COMMENTS    = 2; //DONT include_comments
22
+    public const NO_PARSING_EXCEPTIONS = 4; //THROW Exception on parsing Errors
23
+    public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object
24 24
     //privates
25 25
     /* @var null|string */
26 26
     private $content;
27 27
     /* @var null|string */
28 28
     private $filePath;
29 29
     /* @var integer */
30
-    private $debug = 0;///TODO: determine levels
30
+    private $debug = 0; ///TODO: determine levels
31 31
     /* @var integer */
32 32
     private $options = 0;
33 33
     //Exceptions messages
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
                     }
113 113
                     $emptyLines = [];
114 114
                     switch ($n->indent <=> $previous->indent) {
115
-                        case -1: $previous->getParent($n->indent)->add($n);break;
116
-                        case 0:  $previous->getParent()->add($n);break;
115
+                        case -1: $previous->getParent($n->indent)->add($n); break;
116
+                        case 0:  $previous->getParent()->add($n); break;
117 117
                         default:
118 118
                             if ($this->onDeepestType($n, $previous, $lineString)) continue 2;
119 119
                             $previous->add($n);
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -84,9 +84,13 @@  discard block
 block discarded – undo
84 84
     public function parse($strContent = null)
85 85
     {
86 86
         $source = $this->content;
87
-        if (is_null($source)) $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE);
87
+        if (is_null($source)) {
88
+            $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE);
89
+        }
88 90
         //TODO : be more permissive on $strContent values
89
-        if (!is_array($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT);
91
+        if (!is_array($source)) {
92
+            throw new \Exception(self::EXCEPTION_LINE_SPLIT);
93
+        }
90 94
         $previous = $root = new Node();
91 95
         $emptyLines = [];
92 96
         $specialTypes = Y\LITTERALS|Y\BLANK;
@@ -115,7 +119,9 @@  discard block
 block discarded – undo
115 119
                         case -1: $previous->getParent($n->indent)->add($n);break;
116 120
                         case 0:  $previous->getParent()->add($n);break;
117 121
                         default:
118
-                            if ($this->onDeepestType($n, $previous, $lineString)) continue 2;
122
+                            if ($this->onDeepestType($n, $previous, $lineString)) {
123
+                                continue 2;
124
+                            }
119 125
                             $previous->add($n);
120 126
                     }
121 127
                     $previous = $n;
@@ -155,8 +161,12 @@  discard block
 block discarded – undo
155 161
             }
156 162
         }
157 163
         if ($n->type & Y\BLANK) {
158
-            if ($previous->type & Y\SCALAR) $emptyLines[] = $n->setParent($previous->getParent());
159
-            if ($deepest->type & Y\LITTERALS) $emptyLines[] = $n->setParent($deepest);
164
+            if ($previous->type & Y\SCALAR) {
165
+                $emptyLines[] = $n->setParent($previous->getParent());
166
+            }
167
+            if ($deepest->type & Y\LITTERALS) {
168
+                $emptyLines[] = $n->setParent($deepest);
169
+            }
160 170
             return true;
161 171
         }
162 172
         return false;
Please login to merge, or discard this patch.
yaml/Builder.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     private static function buildNodeList(NodeList $node, &$parent)
30 30
     {
31 31
         $type = &$node->type;
32
-        if ($type & (Y\RAW | Y\LITTERALS)) {
32
+        if ($type&(Y\RAW|Y\LITTERALS)) {
33 33
             return self::litteral($node, $type);
34 34
         }
35 35
         $p = $parent;
@@ -182,15 +182,15 @@  discard block
 block discarded – undo
182 182
     {
183 183
         self::$_root = new YamlObject();
184 184
         $childTypes = $list->getTypes();
185
-        $isMapping  = (Y\KEY | Y\MAPPING) & $childTypes;
185
+        $isMapping  = (Y\KEY|Y\MAPPING)&$childTypes;
186 186
         $isSequence = Y\ITEM & $childTypes;
187 187
         $isSet      = Y\SET_VALUE & $childTypes;
188 188
         if ($isMapping && $isSequence) {
189 189
             throw new \ParseError(sprintf(self::INVALID_DOCUMENT, $key));
190 190
         } else {
191 191
             switch (true) {
192
-                case $isSequence: $list->type = Y\SEQUENCE;break;
193
-                case $isSet:      $list->type = Y\SET;break;
192
+                case $isSequence: $list->type = Y\SEQUENCE; break;
193
+                case $isSet:      $list->type = Y\SET; break;
194 194
                 default:          $list->type = Y\MAPPING;
195 195
             }
196 196
         }
@@ -212,10 +212,10 @@  discard block
 block discarded – undo
212 212
         $children->rewind();
213 213
         $refIndent = $children->current()->indent;
214 214
         $separator = $type === Y\RAW ? '' : "\n";
215
-        $action = function ($c) { return $c->value; };
216
-        if ($type & Y\LITT_FOLDED) {
215
+        $action = function($c) { return $c->value; };
216
+        if ($type&Y\LITT_FOLDED) {
217 217
             $separator = ' ';
218
-            $action = function ($c) use ($refIndent) {
218
+            $action = function($c) use ($refIndent) {
219 219
                 return $c->indent > $refIndent || ($c->type & Y\BLANK) ? "\n".$c->value : $c->value;
220 220
             };
221 221
         }
Please login to merge, or discard this patch.
Braces   +20 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
 
23 23
     private static function build(object $node, &$parent = null)
24 24
     {
25
-        if ($node instanceof NodeList) return self::buildNodeList($node, $parent);
25
+        if ($node instanceof NodeList) {
26
+            return self::buildNodeList($node, $parent);
27
+        }
26 28
         return self::buildNode($node, $parent);
27 29
     }
28 30
 
@@ -74,12 +76,15 @@  discard block
 block discarded – undo
74 76
                     $tmp = $node->getPhpValue();
75 77
                 }
76 78
                 // $tmp = is_object($value) ? self::build($value, $parent) : $node->getPhpValue();
77
-                if ($type === Y\REF_DEF) self::$_root->addReference($identifier, $tmp);
79
+                if ($type === Y\REF_DEF) {
80
+                    self::$_root->addReference($identifier, $tmp);
81
+                }
78 82
                 return self::$_root->getReference($identifier);
79 83
             case Y\SET_KEY:
80 84
                 $key = json_encode(self::build($value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
81
-                if (empty($key))
82
-                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
85
+                if (empty($key)) {
86
+                                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
87
+                }
83 88
                 $parent->{$key} = null;
84 89
                 return;
85 90
             case Y\SET_VALUE:
@@ -98,8 +103,11 @@  discard block
 block discarded – undo
98 103
                     $parent->addTag($identifier); return;
99 104
                 } else {//TODO: have somewhere a list of common tags and their treatment
100 105
                     if (in_array($identifier, ['!binary', '!str'])) {
101
-                        if ($value->value instanceof NodeList) $value->value->type = Y\RAW;
102
-                        else $value->type = Y\RAW;
106
+                        if ($value->value instanceof NodeList) {
107
+                            $value->value->type = Y\RAW;
108
+                        } else {
109
+                            $value->type = Y\RAW;
110
+                        }
103 111
                     }
104 112
                     $val = is_null($value) ? null : self::build(/** @scrutinizer ignore-type */ $value, $node);
105 113
                     return new Tag($identifier, $val);
@@ -168,10 +176,14 @@  discard block
 block discarded – undo
168 176
         }
169 177
         $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE);
170 178
         foreach ($_root->value as $child) {
171
-            if ($child->type & Y\DOC_START) $totalDocStart++;
179
+            if ($child->type & Y\DOC_START) {
180
+                $totalDocStart++;
181
+            }
172 182
             //if 0 or 1 DOC_START = we are still in first document
173 183
             $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;
174
-            if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList();
184
+            if (!isset($documents[$currentDoc])) {
185
+                $documents[$currentDoc] = new NodeList();
186
+            }
175 187
             $documents[$currentDoc]->push($child);
176 188
         }
177 189
         $content = array_map([self::class, 'buildDocument'], $documents, array_keys($documents));
Please login to merge, or discard this patch.
yaml/Node.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
             //modify type according to child
95 95
             switch ($child->type) {
96 96
                 case Y\COMMENT: //fall through
97
-                case Y\KEY:     $this->value->type = Y\MAPPING;break;
98
-                case Y\ITEM:    $this->value->type = Y\SEQUENCE;break;
97
+                case Y\KEY:     $this->value->type = Y\MAPPING; break;
98
+                case Y\ITEM:    $this->value->type = Y\SEQUENCE; break;
99 99
             }
100 100
             $this->type & Y\LITTERALS && $this->value->type = $this->type;
101 101
         }
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      */
120 120
     public function parse(string $nodeString):Node
121 121
     {
122
-        $nodeValue = preg_replace("/^\t+/m", " ", $nodeString);//permissive to tabs but replacement
122
+        $nodeValue = preg_replace("/^\t+/m", " ", $nodeString); //permissive to tabs but replacement
123 123
         $this->indent = strspn($nodeValue, ' ');
124 124
         $nodeValue = ltrim($nodeValue);
125 125
         if ($nodeValue === '') {
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
             case '#': return [Y\COMMENT, ltrim($v)];
157 157
             case "-": return $this->onHyphen($nodeValue);
158 158
             case '%': return [Y\DIRECTIVE, ltrim($v)];
159
-            case '?': return [Y\SET_KEY,   empty($v) ? null : new Node(ltrim($v), $this->line)];
159
+            case '?': return [Y\SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)];
160 160
             case ':': return [Y\SET_VALUE, empty($v) ? null : new Node(ltrim($v), $this->line)];
161 161
             case '>': return [Y\LITT_FOLDED, null];
162 162
             case '|': return [Y\LITT, null];
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
             if (!is_bool($hasComment)) {
182 182
                 $tmpNode = new Node(trim(substr($value, 0, $hasComment)), $this->line);
183 183
                 if ($tmpNode->type !== Y\PARTIAL) {
184
-                    $comment = new Node(trim(substr($value, $hasComment+1)), $this->line);
185
-                    $comment->identifier = true;//to specify it is NOT a fullline comment
184
+                    $comment = new Node(trim(substr($value, $hasComment + 1)), $this->line);
185
+                    $comment->identifier = true; //to specify it is NOT a fullline comment
186 186
                     $this->add($comment);
187 187
                     $n = $tmpNode;
188 188
                 }
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
         $type = ['!' => Y\TAG, '&' => Y\REF_DEF, '*' => Y\REF_CALL][$nodeValue[0]];
251 251
         $pos = strpos($v, ' ');
252 252
         $this->identifier = is_bool($pos) ? $v : strstr($v, ' ', true);
253
-        $n = is_bool($pos) ? null : (new Node(trim(substr($nodeValue, $pos+1)), $this->line))->setParent($this);
253
+        $n = is_bool($pos) ? null : (new Node(trim(substr($nodeValue, $pos + 1)), $this->line))->setParent($this);
254 254
         return [$type, $n];
255 255
     }
256 256
 
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
     {
265 265
         $v = $this->value;
266 266
         if (is_null($v)) return null;
267
-        if ($this->type & (Y\REF_CALL | Y\SCALAR)) return self::getScalar($v);
268
-        if ($this->type & (Y\COMPACT_MAPPING | Y\COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type);
267
+        if ($this->type & (Y\REF_CALL|Y\SCALAR)) return self::getScalar($v);
268
+        if ($this->type & (Y\COMPACT_MAPPING|Y\COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type);
269 269
         switch ($this->type) {
270 270
             case Y\JSON:   return json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR);
271 271
             case Y\QUOTED: return substr($v, 1, -1);
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     {
322 322
         $out = new Compact();
323 323
         if ($type === Y\COMPACT_SEQUENCE) {
324
-            $f = function ($e) { return self::getScalar(trim($e));};
324
+            $f = function($e) { return self::getScalar(trim($e)); };
325 325
             //TODO : that's not robust enough, improve it
326 326
             foreach (array_map($f, explode(",", $mappingOrSeqString)) as $key => $value) {
327 327
                 $out[$key] = $value;
Please login to merge, or discard this patch.
yaml/NodeList.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
 class NodeList extends \SplDoublyLinkedList
14 14
 {
15 15
     /* @var null|int */
16
-    public $type = null;//Y\LITT_FOLDED;
16
+    public $type = null; //Y\LITT_FOLDED;
17 17
 
18 18
     public function __construct()
19 19
     {
Please login to merge, or discard this patch.