Completed
Branch master (a11ddd)
by stéphane
02:27
created
Dumper.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
         }
33 33
         $options = is_null($options) ? self::options : $options;
34 34
         self::$result = new DLL;
35
-        self::$result->setIteratorMode(DLL::IT_MODE_FIFO | DLL::IT_MODE_DELETE);
35
+        self::$result->setIteratorMode(DLL::IT_MODE_FIFO|DLL::IT_MODE_DELETE);
36 36
         if ($dataType instanceof YamlObject) {
37 37
             return self::dumpYamlObject($dataType);
38 38
         } elseif (is_array($dataType) && $dataType[0] instanceof YamlObject) {
Please login to merge, or discard this patch.
Regex.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@  discard block
 block discarded – undo
14 14
     const AN = "[\w ]+";
15 15
     const NUM = "-?[\d.e]+";
16 16
     const SIMPLE = "(?P<sv>".self::NULL."|".
17
-                                  self::FALSE."|".
18
-                                  self::TRUE."|".
19
-                                  self::AN."|".
20
-                                  self::NUM.")";
17
+                                    self::FALSE."|".
18
+                                    self::TRUE."|".
19
+                                    self::AN."|".
20
+                                    self::NUM.")";
21 21
     private const seqForMap = "(?P<seq>\[(?:(?:(?P>sv)|(?P>seq)|(?P>map)),?\s*)+\])";
22 22
     private const mapForSeq = "(?P<map>{\s*(?:".self::AN."\s*:\s*(?:(?P>sv)|(?P>seq)|(?P>map)),?\s*)+})";
23 23
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
         $matchSpaced    = preg_match($spaced, $v);
42 42
         $matchIso       = preg_match($iso8601, $v);
43 43
         if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso))
44
-          throw new \Exception("Regex date error");
44
+            throw new \Exception("Regex date error");
45 45
 
46 46
         return $matchDate || $matchCanonical || $matchSpaced || $matchIso;
47 47
     }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@
 block discarded – undo
32 32
     {
33 33
         $d         = "\\d{4}([-\\/])\\d{2}\\1\\d{2}";
34 34
         $h         = "\\d{2}(:)\\d{2}\\2\\d{2}";
35
-        $date      =  "/^$d$/";// 2002-12-14, 2002/12/14
36
-        $canonical =  "/^$d(?:t| )$h\\.\\dz?$/im";// 2001-12-15T02:59:43.1Z
37
-        $spaced    =  "/^$d(?:t| )$h\\.\\d{2} [-+]\\d$/im";// 2001-12-14 21:59:43.10 -5
38
-        $iso8601   =  "/^$d(?:t| )$h\\.\\d{2}[-+]\\d{2}\\2\\d{2}/im";// 2001-12-14t21:59:43.10-05:00
35
+        $date      = "/^$d$/"; // 2002-12-14, 2002/12/14
36
+        $canonical = "/^$d(?:t| )$h\\.\\dz?$/im"; // 2001-12-15T02:59:43.1Z
37
+        $spaced    = "/^$d(?:t| )$h\\.\\d{2} [-+]\\d$/im"; // 2001-12-14 21:59:43.10 -5
38
+        $iso8601   = "/^$d(?:t| )$h\\.\\d{2}[-+]\\d{2}\\2\\d{2}/im"; // 2001-12-14t21:59:43.10-05:00
39 39
         $matchDate      = preg_match($date, $v);
40 40
         $matchCanonical = preg_match($canonical, $v);
41 41
         $matchSpaced    = preg_match($spaced, $v);
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,8 +40,9 @@
 block discarded – undo
40 40
         $matchCanonical = preg_match($canonical, $v);
41 41
         $matchSpaced    = preg_match($spaced, $v);
42 42
         $matchIso       = preg_match($iso8601, $v);
43
-        if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso))
44
-          throw new \Exception("Regex date error");
43
+        if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso)) {
44
+                  throw new \Exception("Regex date error");
45
+        }
45 46
 
46 47
         return $matchDate || $matchCanonical || $matchSpaced || $matchIso;
47 48
     }
Please login to merge, or discard this patch.
example.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-require_once __DIR__ . '/vendor/autoload.php';
2
+require_once __DIR__.'/vendor/autoload.php';
3 3
 
4 4
 use \Dallgoot\Yaml\Loader;
5 5
 
Please login to merge, or discard this patch.
Node.php 3 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     public function getParent($indent = null):Node
32 32
     {
33 33
         if (is_null($indent)) {
34
-             return $this->_parent ?? $this;
34
+                return $this->_parent ?? $this;
35 35
         }
36 36
         $cursor = $this;
37 37
         while ($cursor->indent >= $indent) {
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
         return $cursor;
77 77
     }
78 78
     /**
79
-    *  CAUTION : the types assumed here are NOT FINAL : they CAN be adjusted according to parent
80
-    */
79
+     *  CAUTION : the types assumed here are NOT FINAL : they CAN be adjusted according to parent
80
+     */
81 81
     public function parse(String $nodeString):Node
82 82
     {
83 83
         $nodeValue = preg_replace("/^\t+/m", " ", $nodeString);//permissive to tabs but replacement
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
     private function getScalar($v)
210 210
     {
211 211
         $types = ['yes'   => true,
212
-                  'no'    => false,
213
-                  'true'  => true,
214
-                  'false' => false,
215
-                  'null'  => null,
216
-                  '.inf'  => INF,
217
-                  '-.inf' => -INF,
218
-                  '.nan'  => NAN
212
+                    'no'    => false,
213
+                    'true'  => true,
214
+                    'false' => false,
215
+                    'null'  => null,
216
+                    '.inf'  => INF,
217
+                    '-.inf' => -INF,
218
+                    '.nan'  => NAN
219 219
         ];
220 220
         if (in_array(strtolower($v), array_keys($types))) return $types[strtolower($v)];
221 221
         if (R::isDate($v))   return date_create($v);
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
         //modify type according to child
61 61
         if ($this->value instanceof DLL && !property_exists($this->value, "type")) {
62 62
             switch ($child->type) {
63
-                case T::KEY:    $this->value->type = T::MAPPING;break;
64
-                case T::ITEM:   $this->value->type = T::SEQUENCE;break;
65
-                case T::SCALAR: $this->value->type = $this->type;break;
63
+                case T::KEY:    $this->value->type = T::MAPPING; break;
64
+                case T::ITEM:   $this->value->type = T::SEQUENCE; break;
65
+                case T::SCALAR: $this->value->type = $this->type; break;
66 66
             }
67 67
         }
68 68
     }
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     */
81 81
     public function parse(String $nodeString):Node
82 82
     {
83
-        $nodeValue = preg_replace("/^\t+/m", " ", $nodeString);//permissive to tabs but replacement
83
+        $nodeValue = preg_replace("/^\t+/m", " ", $nodeString); //permissive to tabs but replacement
84 84
         $this->indent = strspn($nodeValue, ' ');
85 85
         $nodeValue = ltrim($nodeValue);
86 86
         if ($nodeValue === '') {
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
             case '#': return [T::COMMENT, ltrim($v)];
117 117
             case "-": return $this->_onMinus($nodeValue);
118 118
             case '%': return [T::DIRECTIVE, ltrim($v)];
119
-            case '?': return [T::SET_KEY,   empty($v) ? null : new Node(ltrim($v), $this->line)];
119
+            case '?': return [T::SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)];
120 120
             case ':': return [T::SET_VALUE, empty($v) ? null : new Node(ltrim($v), $this->line)];
121 121
             case '>': return [T::LITTERAL_FOLDED, null];
122 122
             case '|': return [T::LITTERAL, null];
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
             if (!is_bool($hasComment)) {
137 137
                 $tmpNode = new Node(trim(substr($keyValue, 0, $hasComment)), $this->line);
138 138
                 if ($tmpNode->type !== T::PARTIAL) {
139
-                    $comment = new Node(trim(substr($keyValue, $hasComment+1)), $this->line);
139
+                    $comment = new Node(trim(substr($keyValue, $hasComment + 1)), $this->line);
140 140
                     $this->add($comment);
141 141
                     $n = $tmpNode;
142 142
                 }
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
         $type = ['!' => T::TAG, '&' => T::REF_DEF, '*' => T::REF_CALL][$nodeValue[0]];
182 182
         $pos = strpos($v, ' ');
183 183
         $this->name = is_bool($pos) ? $v : strstr($v, ' ', true);
184
-        $n = is_bool($pos) ? null : (new Node(trim(substr($nodeValue, $pos+1)), $this->line))->setParent($this);
184
+        $n = is_bool($pos) ? null : (new Node(trim(substr($nodeValue, $pos + 1)), $this->line))->setParent($this);
185 185
         return [$type, $n];
186 186
     }
187 187
 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
             case T::MAPPING_SHORT:  return $this->getShortMapping(substr($this->value, 1, -1));
199 199
             //TODO : that's not robust enough, improve it
200 200
             case T::SEQUENCE_SHORT:
201
-                $f = function ($e) { return self::getScalar(trim($e));};
201
+                $f = function($e) { return self::getScalar(trim($e)); };
202 202
                 return array_map($f, explode(",", substr($this->value, 1, -1)));
203 203
             default:
204 204
                 trigger_error("Error can not get PHP type for ".T::getName($this->type), E_USER_WARNING);
Please login to merge, or discard this patch.
Braces   +36 added lines, -12 removed lines patch added patch discarded remove patch
@@ -110,8 +110,12 @@  discard block
 block discarded – undo
110 110
             $type = R::isProperlyQuoted($nodeValue) ? T::QUOTED : T::PARTIAL;
111 111
             return [$type, $nodeValue];
112 112
         }
113
-        if (in_array($nodeValue[0], ['{', '[']))      return $this->_onObject($nodeValue);
114
-        if (in_array($nodeValue[0], ['!', '&', '*'])) return $this->_onNodeAction($nodeValue);
113
+        if (in_array($nodeValue[0], ['{', '['])) {
114
+            return $this->_onObject($nodeValue);
115
+        }
116
+        if (in_array($nodeValue[0], ['!', '&', '*'])) {
117
+            return $this->_onNodeAction($nodeValue);
118
+        }
115 119
         switch ($nodeValue[0]) {
116 120
             case '#': return [T::COMMENT, ltrim($v)];
117 121
             case "-": return $this->_onMinus($nodeValue);
@@ -149,9 +153,15 @@  discard block
 block discarded – undo
149 153
     private function _onObject($value):array
150 154
     {
151 155
         json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
152
-        if (json_last_error() === JSON_ERROR_NONE)  return [T::JSON, $value];
153
-        if (preg_match(R::MAPPING, $value))         return [T::MAPPING_SHORT, $value];
154
-        if (preg_match(R::SEQUENCE, $value))        return [T::SEQUENCE_SHORT, $value];
156
+        if (json_last_error() === JSON_ERROR_NONE) {
157
+            return [T::JSON, $value];
158
+        }
159
+        if (preg_match(R::MAPPING, $value)) {
160
+            return [T::MAPPING_SHORT, $value];
161
+        }
162
+        if (preg_match(R::SEQUENCE, $value)) {
163
+            return [T::SEQUENCE_SHORT, $value];
164
+        }
155 165
         return [T::PARTIAL, $value];
156 166
     }
157 167
 
@@ -159,7 +169,9 @@  discard block
 block discarded – undo
159 169
     {
160 170
         if (substr($nodeValue, 0, 3) === '---') {
161 171
             $rest = trim(substr($nodeValue, 3));
162
-            if (empty($rest)) return [T::DOC_START, null];
172
+            if (empty($rest)) {
173
+                return [T::DOC_START, null];
174
+            }
163 175
             $n = new Node($rest, $this->line);
164 176
             $n->indent = $this->indent + 4;
165 177
             return [T::DOC_START, $n->setParent($this)];
@@ -188,7 +200,9 @@  discard block
 block discarded – undo
188 200
     public function getPhpValue()
189 201
     {
190 202
         $v = $this->value;
191
-        if (is_null($v)) return null;
203
+        if (is_null($v)) {
204
+            return null;
205
+        }
192 206
         switch ($this->type) {
193 207
             case T::JSON:   return json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR);
194 208
             case T::QUOTED: return substr($v, 1, -1);
@@ -217,16 +231,26 @@  discard block
 block discarded – undo
217 231
                   '-.inf' => -INF,
218 232
                   '.nan'  => NAN
219 233
         ];
220
-        if (in_array(strtolower($v), array_keys($types))) return $types[strtolower($v)];
221
-        if (R::isDate($v))   return date_create($v);
222
-        if (R::isNumber($v)) return $this->getNumber($v);
234
+        if (in_array(strtolower($v), array_keys($types))) {
235
+            return $types[strtolower($v)];
236
+        }
237
+        if (R::isDate($v)) {
238
+            return date_create($v);
239
+        }
240
+        if (R::isNumber($v)) {
241
+            return $this->getNumber($v);
242
+        }
223 243
         return strval($v);
224 244
     }
225 245
 
226 246
     private function getNumber($v)
227 247
     {
228
-        if (preg_match("/^(0o\d+)$/i", $v))      return intval(base_convert($v, 8, 10));
229
-        if (preg_match("/^(0x[\da-f]+)$/i", $v)) return intval(base_convert($v, 16, 10));
248
+        if (preg_match("/^(0o\d+)$/i", $v)) {
249
+            return intval(base_convert($v, 8, 10));
250
+        }
251
+        if (preg_match("/^(0x[\da-f]+)$/i", $v)) {
252
+            return intval(base_convert($v, 16, 10));
253
+        }
230 254
         // if preg_match("/^([\d.]+e[-+]\d{1,2})$/", $v)://fall through
231 255
         // if preg_match("/^([-+]?(?:\d+|\d*.\d+))$/", $v):
232 256
             return is_bool(strpos($v, '.')) ? intval($v) : floatval($v);
Please login to merge, or discard this patch.
YamlObject.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@
 block discarded – undo
14 14
 
15 15
     public function __construct()
16 16
     {
17
-        parent::__construct([], 1);//1 = Array indices can be accessed as properties in read/write.
17
+        parent::__construct([], 1); //1 = Array indices can be accessed as properties in read/write.
18 18
         $this->__yaml__object__api = new API();
19 19
     }
20 20
 
21 21
     public function __call($funcName, $arguments)
22 22
     {
23 23
         $reflectAPI = new \ReflectionClass(get_class($this->__yaml__object__api));
24
-        $getName = function ($o) { return $o->name; };
24
+        $getName = function($o) { return $o->name; };
25 25
         $publicApi  = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PUBLIC));
26 26
         $privateApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PRIVATE));
27 27
         if (!in_array($funcName, $publicApi) &&
Please login to merge, or discard this patch.
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.
Builder.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
         $p = $parent;
33 33
         switch ($type) {
34 34
             case T::MAPPING: //fall through
35
-            case T::SET:      $p = new \StdClass;break;
36
-            case T::SEQUENCE: $p = [];break;
35
+            case T::SET:      $p = new \StdClass; break;
36
+            case T::SEQUENCE: $p = []; break;
37 37
             // case T::KEY: $p = $parent;break;
38 38
         }
39 39
         $out = null;
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
     private static function buildNode(Node $node, &$parent)
54 54
     {
55 55
         list($line, $type, $value) = [$node->line, $node->type, $node->value];
56
-        $name  = property_exists($node, "name") ? $node->name : null;
56
+        $name = property_exists($node, "name") ? $node->name : null;
57 57
         switch ($type) {
58
-            case T::COMMENT: self::$root->addComment($line, $value);return;
59
-            case T::DIRECTIVE: return;//TODO
60
-            case T::ITEM: self::buildItem($value, $parent);return;
61
-            case T::KEY:  self::buildKey($node, $parent);return;
58
+            case T::COMMENT: self::$root->addComment($line, $value); return;
59
+            case T::DIRECTIVE: return; //TODO
60
+            case T::ITEM: self::buildItem($value, $parent); return;
61
+            case T::KEY:  self::buildKey($node, $parent); return;
62 62
             case T::REF_DEF: //fall through
63 63
             case T::REF_CALL:
64 64
                 $tmp = is_object($value) ? self::build($value, $parent) : $node->getPhpValue();
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
                 $prop = array_keys(get_object_vars($parent));
75 75
                 $key = end($prop);
76 76
                 if (property_exists($value, "type") && in_array($value->type, [T::ITEM, T::MAPPING])) {
77
-                    $p = $value->type === T::ITEM  ? [] : new \StdClass;
77
+                    $p = $value->type === T::ITEM ? [] : new \StdClass;
78 78
                     self::build($value, $p);
79 79
                 } else {
80 80
                     $p = self::build($value, $parent->{$key});
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
                 return;
84 84
             case T::TAG:
85 85
                 if ($parent === self::$root) {
86
-                    $parent->addTag($name);return;
86
+                    $parent->addTag($name); return;
87 87
                 } else {
88 88
                     if (in_array($name, ['!binary', '!str'])) {
89 89
                         if (is_object($value->value)) $value->value->type = T::RAW;
@@ -171,8 +171,8 @@  discard block
 block discarded – undo
171 171
             throw new \ParseError(sprintf(self::INVALID_DOCUMENT, $key));
172 172
         } else {
173 173
             switch (true) {
174
-                case $isSequence: $list->type = T::SEQUENCE;break;
175
-                case $isSet: $list->type = T::SET;break;
174
+                case $isSequence: $list->type = T::SEQUENCE; break;
175
+                case $isSet: $list->type = T::SET; break;
176 176
                 case $isMapping://fall through
177 177
                 default:$list->type = T::MAPPING;
178 178
             }
@@ -196,10 +196,10 @@  discard block
 block discarded – undo
196 196
         $children->rewind();
197 197
         $refIndent = $children->current()->indent;
198 198
         $separator = $type === T::RAW ? '' : "\n";
199
-        $action = function ($c) { return $c->value; };
199
+        $action = function($c) { return $c->value; };
200 200
         if ($type === T::LITTERAL_FOLDED) {
201 201
             $separator = ' ';
202
-            $action = function ($c) use ($refIndent) {
202
+            $action = function($c) use ($refIndent) {
203 203
                 return $c->indent > $refIndent || $c->type === T::EMPTY ? "\n".$c->value : $c->value;
204 204
             };
205 205
         }
Please login to merge, or discard this patch.
Braces   +20 added lines, -8 removed lines patch added patch discarded remove patch
@@ -19,7 +19,9 @@  discard block
 block discarded – undo
19 19
 
20 20
     private static function build(object $node, &$parent = null)
21 21
     {
22
-        if ($node instanceof DLL) return self::buildDLL($node, $parent);
22
+        if ($node instanceof DLL) {
23
+            return self::buildDLL($node, $parent);
24
+        }
23 25
         return self::buildNode($node, $parent);
24 26
     }
25 27
 
@@ -62,12 +64,15 @@  discard block
 block discarded – undo
62 64
             case T::REF_DEF: //fall through
63 65
             case T::REF_CALL:
64 66
                 $tmp = is_object($value) ? self::build($value, $parent) : $node->getPhpValue();
65
-                if ($type === T::REF_DEF) self::$root->addReference($name, $tmp);
67
+                if ($type === T::REF_DEF) {
68
+                    self::$root->addReference($name, $tmp);
69
+                }
66 70
                 return self::$root->getReference($name);
67 71
             case T::SET_KEY:
68 72
                 $key = json_encode(self::build($value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES);
69
-                if (empty($key))
70
-                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
73
+                if (empty($key)) {
74
+                                    throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1);
75
+                }
71 76
                 $parent->{$key} = null;
72 77
                 return;
73 78
             case T::SET_VALUE:
@@ -86,8 +91,11 @@  discard block
 block discarded – undo
86 91
                     $parent->addTag($name);return;
87 92
                 } else {
88 93
                     if (in_array($name, ['!binary', '!str'])) {
89
-                        if (is_object($value->value)) $value->value->type = T::RAW;
90
-                        else $value->type = T::RAW;
94
+                        if (is_object($value->value)) {
95
+                            $value->value->type = T::RAW;
96
+                        } else {
97
+                            $value->type = T::RAW;
98
+                        }
91 99
                     }
92 100
                     $val = is_null($value) ? null : self::build($value, $node);
93 101
                     return new Tag($name, $val);
@@ -149,10 +157,14 @@  discard block
 block discarded – undo
149 157
         }
150 158
         $root->value->setIteratorMode(DLL::IT_MODE_DELETE);
151 159
         foreach ($root->value as $child) {
152
-            if ($child->type === T::DOC_START) $totalDocStart++;
160
+            if ($child->type === T::DOC_START) {
161
+                $totalDocStart++;
162
+            }
153 163
             //if 0 or 1 DOC_START = we are still in first document
154 164
             $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0;
155
-            if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new DLL();
165
+            if (!isset($documents[$currentDoc])) {
166
+                $documents[$currentDoc] = new DLL();
167
+            }
156 168
             $documents[$currentDoc]->push($child);
157 169
         }
158 170
         $debug >= 2 && var_dump($documents);
Please login to merge, or discard this patch.
Types.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 
4 4
 class Types
5 5
 {
6
-    const DIRECTIVE  = 0;
6
+    const DIRECTIVE = 0;
7 7
     const DOC_START = 1;
8 8
     const DOC_END = 2;
9 9
 
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     const LITTERAL = 72;
25 25
     const LITTERAL_FOLDED = 82;
26 26
 
27
-    const SCALAR    = 102;
27
+    const SCALAR = 102;
28 28
     const TAG = 132;
29 29
     const JSON = 142;
30 30
 
Please login to merge, or discard this patch.
Tag.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
         if (is_null($tagName)) {
17 17
             throw new \Exception(self::class.": a tag MUST have a name", 1);
18 18
         }
19
-        $this->tagName  = $tagName;
19
+        $this->tagName = $tagName;
20 20
         $this->value = $value;
21 21
     }
22 22
 
Please login to merge, or discard this patch.
Loader.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@  discard block
 block discarded – undo
9 9
 {
10 10
     public $errors = [];
11 11
     //options
12
-    public const EXCLUDE_DIRECTIVES = 0001;//DONT include_directive
13
-    public const IGNORE_COMMENTS    = 0010;//DONT include_comments
14
-    public const EXCEPTIONS_PARSING = 0100;//THROW Exception on parsing Errors
15
-    public const NO_OBJECT_FOR_DATE = 1000;//DONT import date strings as dateTime Object
12
+    public const EXCLUDE_DIRECTIVES = 0001; //DONT include_directive
13
+    public const IGNORE_COMMENTS    = 0010; //DONT include_comments
14
+    public const EXCEPTIONS_PARSING = 0100; //THROW Exception on parsing Errors
15
+    public const NO_OBJECT_FOR_DATE = 1000; //DONT import date strings as dateTime Object
16 16
     //
17 17
     private $_content;
18 18
     private $filePath;
19
-    private $_debug   = 0;//TODO: determine levels
19
+    private $_debug   = 0; //TODO: determine levels
20 20
     private $_options = 0;
21 21
     //Exceptions
22 22
     const INVALID_VALUE        = self::class.": at line %d";
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
         $specialTypes = [T::LITTERAL, T::LITTERAL_FOLDED, T::EMPTY];
75 75
         try {
76 76
             foreach ($source as $lineNb => $lineString) {
77
-                $n = new Node($lineString, $lineNb + 1);//TODO: useful???-> $this->_debug && var_dump($n);
77
+                $n = new Node($lineString, $lineNb + 1); //TODO: useful???-> $this->_debug && var_dump($n);
78 78
                 $parent  = $previous;
79 79
                 $deepest = $previous->getDeepestNode();
80 80
                 if ($deepest->type === T::PARTIAL) {
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
         switch ($deepest->type) {
148 148
             case T::LITTERAL:
149 149
             case T::LITTERAL_FOLDED:
150
-                $n->value = trim($lineString);//fall through
150
+                $n->value = trim($lineString); //fall through
151 151
             case T::REF_DEF://fall through
152 152
             case T::SET_VALUE://fall through
153 153
             case T::TAG:
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
             case T::EMPTY:
157 157
             case T::SCALAR:
158 158
                 if ($n->type === T::SCALAR &&
159
-                    !in_array($deepest->getParent()->type, T::$LITTERALS) ) {
159
+                    !in_array($deepest->getParent()->type, T::$LITTERALS)) {
160 160
                     $deepest->type = T::SCALAR;
161 161
                     $deepest->value .= "\n".$n->value;
162 162
                     return true;
Please login to merge, or discard this patch.
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -66,9 +66,13 @@  discard block
 block discarded – undo
66 66
     public function parse($strContent = null)
67 67
     {
68 68
         $source = $this->_content;
69
-        if (is_null($source)) $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE);
69
+        if (is_null($source)) {
70
+            $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE);
71
+        }
70 72
         //TODO : be more permissive on $strContent values
71
-        if (!is_array($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT);
73
+        if (!is_array($source)) {
74
+            throw new \Exception(self::EXCEPTION_LINE_SPLIT);
75
+        }
72 76
         $previous = $root = new Node();
73 77
         $emptyLines = [];
74 78
         $specialTypes = [T::LITTERAL, T::LITTERAL_FOLDED, T::EMPTY];
@@ -85,7 +89,9 @@  discard block
 block discarded – undo
85 89
                     $deepest->parse($deepest->value.' '.ltrim($lineString));
86 90
                 } else {
87 91
                     if (in_array($n->type, $specialTypes)) {
88
-                        if ($this->_onSpecialType($n, $parent, $previous, $emptyLines)) continue;
92
+                        if ($this->_onSpecialType($n, $parent, $previous, $emptyLines)) {
93
+                            continue;
94
+                        }
89 95
                     }
90 96
                     foreach ($emptyLines as $key => $node) {
91 97
                         $node->getParent()->add($node);
@@ -96,7 +102,9 @@  discard block
 block discarded – undo
96 102
                     } elseif ($n->indent === $previous->indent) {
97 103
                         $parent = $previous->getParent();
98 104
                     } elseif ($n->indent > $previous->indent) {
99
-                        if ($this->_onDeepestType($n, $parent, $previous, $lineString)) continue;
105
+                        if ($this->_onDeepestType($n, $parent, $previous, $lineString)) {
106
+                            continue;
107
+                        }
100 108
                     }
101 109
                     $parent->add($n);
102 110
                     $previous = $n;
@@ -125,8 +133,12 @@  discard block
 block discarded – undo
125 133
         $deepest = $previous->getDeepestNode();
126 134
         switch ($n->type) {
127 135
             case T::EMPTY:
128
-                if ($previous->type === T::SCALAR) $emptyLines[] = $n->setParent($previous->getParent());
129
-                if (in_array($deepest->type, T::$LITTERALS)) $emptyLines[] = $n->setParent($deepest);
136
+                if ($previous->type === T::SCALAR) {
137
+                    $emptyLines[] = $n->setParent($previous->getParent());
138
+                }
139
+                if (in_array($deepest->type, T::$LITTERALS)) {
140
+                    $emptyLines[] = $n->setParent($deepest);
141
+                }
130 142
                 return true;
131 143
                 break;
132 144
             case T::LITTERAL://fall through
Please login to merge, or discard this patch.