@@ -19,17 +19,17 @@ discard block |
||
19 | 19 | /* @var null|string */ |
20 | 20 | public $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 |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $previous = $root = new Node(); |
92 | 92 | $emptyLines = []; |
93 | 93 | try { |
94 | - $gen = function () use($source) { |
|
94 | + $gen = function() use($source) { |
|
95 | 95 | foreach ($source as $key => $value) { |
96 | 96 | yield ++$key => $value; |
97 | 97 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $target->add($n); |
118 | 118 | $previous = $n; |
119 | 119 | } |
120 | - if ($this->debug === 2) echo "\033[33mParsed Structure\033[0m\n",var_export($root, true); |
|
120 | + if ($this->debug === 2) echo "\033[33mParsed Structure\033[0m\n", var_export($root, true); |
|
121 | 121 | $out = Builder::buildContent($root, $this->debug); |
122 | 122 | return $out; |
123 | 123 | } catch (\Error|\Exception|\ParseError $e) { |
@@ -32,7 +32,7 @@ |
||
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)) { |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | } |
89 | 89 | $this->value->push($child); |
90 | 90 | //modify type according to child |
91 | - if ($child->type & (Y::COMMENT | Y::KEY)) $this->value->type = Y::MAPPING; |
|
91 | + if ($child->type & (Y::COMMENT|Y::KEY)) $this->value->type = Y::MAPPING; |
|
92 | 92 | if ($child->type & Y::ITEM) $this->value->type = Y::SEQUENCE; |
93 | 93 | if ($this->type & Y::LITTERALS) $this->value->type = $this->type; |
94 | 94 | } |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | if (in_array($first, ['{', '['])) return $this->onObject($nodeValue); |
147 | 147 | if (in_array($first, ['!', '&', '*'])) return $this->onNodeAction($nodeValue); |
148 | 148 | // Note : php don't like '?' as an array key -_- |
149 | - if($first === '?') return [Y::SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
|
150 | - $characters = [ '#' => [Y::COMMENT, ltrim($v)], |
|
149 | + if ($first === '?') return [Y::SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
|
150 | + $characters = ['#' => [Y::COMMENT, ltrim($v)], |
|
151 | 151 | "-" => $this->onHyphen($nodeValue), |
152 | 152 | '%' => [Y::DIRECTIVE, ltrim($v)], |
153 | 153 | ':' => [Y::SET_VALUE, empty($v) ? null : new Node(ltrim($v), $this->line)], |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | { |
259 | 259 | $v = &$this->value; |
260 | 260 | if (is_null($v)) return null; |
261 | - if ($this->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($v); |
|
262 | - if ($this->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type); |
|
261 | + if ($this->type & (Y::REF_CALL|Y::SCALAR)) return self::getScalar($v); |
|
262 | + if ($this->type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type); |
|
263 | 263 | $expected = [Y::JSON => json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR), |
264 | 264 | Y::QUOTED => substr($v, 1, -1), |
265 | 265 | Y::RAW => strval($v)]; |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | { |
313 | 313 | $out = new Compact(); |
314 | 314 | if ($type === Y::COMPACT_SEQUENCE) { |
315 | - $f = function ($e) { return self::getScalar(trim($e));}; |
|
315 | + $f = function($e) { return self::getScalar(trim($e)); }; |
|
316 | 316 | //TODO : that's not robust enough, improve it |
317 | 317 | foreach (array_map($f, explode(",", $mappingOrSeqString)) as $key => $value) { |
318 | 318 | $out[$key] = $value; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | private static function buildNodeList(NodeList $node, &$parent) |
30 | 30 | { |
31 | - if ($node->type & (Y::RAW | Y::LITTERALS)) { |
|
31 | + if ($node->type & (Y::RAW|Y::LITTERALS)) { |
|
32 | 32 | return self::buildLitteral($node, $node->type); |
33 | 33 | } |
34 | 34 | $p = $parent; |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | private static function buildNode(Node $node, &$parent) |
56 | 56 | { |
57 | 57 | extract((array) $node, EXTR_REFS); |
58 | - if ($type & (Y::REF_DEF | Y::REF_CALL)) { |
|
58 | + if ($type&(Y::REF_DEF|Y::REF_CALL)) { |
|
59 | 59 | if (is_object($value)) { |
60 | 60 | $tmp = self::build($value, $parent) ?? $parent; |
61 | 61 | } else { |
@@ -151,15 +151,15 @@ discard block |
||
151 | 151 | { |
152 | 152 | self::$_root = new YamlObject(); |
153 | 153 | $childTypes = $list->getTypes(); |
154 | - $isaMapping = (bool) (Y::KEY | Y::MAPPING) & $childTypes; |
|
154 | + $isaMapping = (bool) (Y::KEY|Y::MAPPING)&$childTypes; |
|
155 | 155 | $isaSequence = (bool) Y::ITEM & $childTypes; |
156 | 156 | $isaSet = (bool) Y::SET_VALUE & $childTypes; |
157 | 157 | if ($isaMapping && $isaSequence) { |
158 | 158 | throw new \ParseError(sprintf(self::INVALID_DOCUMENT, $key)); |
159 | 159 | } else { |
160 | 160 | switch (true) { |
161 | - case $isaSequence: $list->type = Y::SEQUENCE;break; |
|
162 | - case $isaSet: $list->type = Y::SET;break; |
|
161 | + case $isaSequence: $list->type = Y::SEQUENCE; break; |
|
162 | + case $isaSet: $list->type = Y::SET; break; |
|
163 | 163 | default: $list->type = Y::MAPPING; |
164 | 164 | } |
165 | 165 | } |
@@ -186,15 +186,15 @@ discard block |
||
186 | 186 | $lines[] = self::buildLitteral($child->value, $type); |
187 | 187 | } else { |
188 | 188 | $prefix = ''; |
189 | - if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
189 | + if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
190 | 190 | $prefix = "\n"; |
191 | 191 | } |
192 | 192 | $lines[] = $prefix.$child->value; |
193 | 193 | } |
194 | 194 | } |
195 | - if ($type & Y::RAW) return implode('', $lines); |
|
196 | - if ($type & Y::LITT) return implode("\n", $lines); |
|
197 | - if ($type & Y::LITT_FOLDED) return implode(' ', $lines); |
|
195 | + if ($type&Y::RAW) return implode('', $lines); |
|
196 | + if ($type&Y::LITT) return implode("\n", $lines); |
|
197 | + if ($type&Y::LITT_FOLDED) return implode(' ', $lines); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | private function buildSetKey(Node $node, $parent):void |