@@ -40,8 +40,12 @@ |
||
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 | } |
@@ -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)) { |
@@ -27,8 +27,12 @@ |
||
27 | 27 | public function jsonSerialize() |
28 | 28 | { |
29 | 29 | $prop = get_object_vars($this); |
30 | - if (count($prop) > 0) return $prop; |
|
31 | - if (count($this) > 0) return iterator_to_array($this); |
|
30 | + if (count($prop) > 0) { |
|
31 | + return $prop; |
|
32 | + } |
|
33 | + if (count($this) > 0) { |
|
34 | + return iterator_to_array($this); |
|
35 | + } |
|
32 | 36 | } |
33 | 37 | |
34 | 38 | public static function wrap($arrayOrObject) |
@@ -21,7 +21,9 @@ discard block |
||
21 | 21 | |
22 | 22 | public function __construct(int $options = null) |
23 | 23 | { |
24 | - if (is_int($options)) self::$options = $options; |
|
24 | + if (is_int($options)) { |
|
25 | + self::$options = $options; |
|
26 | + } |
|
25 | 27 | } |
26 | 28 | |
27 | 29 | /** |
@@ -36,7 +38,9 @@ discard block |
||
36 | 38 | */ |
37 | 39 | public static function toString($dataType, int $options = null):string |
38 | 40 | { |
39 | - if (is_null($dataType)) throw new \Exception(self::class.": No content to convert to Yaml", 1); |
|
41 | + if (is_null($dataType)) { |
|
42 | + throw new \Exception(self::class.": No content to convert to Yaml", 1); |
|
43 | + } |
|
40 | 44 | self::$options = is_int($options) ? $options : self::OPTIONS; |
41 | 45 | self::$result = new DLL; |
42 | 46 | self::$result->setIteratorMode(DLL::IT_MODE_FIFO|DLL::IT_MODE_DELETE); |
@@ -74,8 +78,12 @@ discard block |
||
74 | 78 | if (is_scalar($dataType)) { |
75 | 79 | switch (gettype($dataType)) { |
76 | 80 | case 'boolean': return $dataType ? 'true' : 'false'; |
77 | - case 'float': if (is_infinite((float) $dataType)) return $dataType > 0 ? '.inf' : '-.inf'; |
|
78 | - case 'double': if (is_nan((float) $dataType)) return '.nan'; |
|
81 | + case 'float': if (is_infinite((float) $dataType)) { |
|
82 | + return $dataType > 0 ? '.inf' : '-.inf'; |
|
83 | + } |
|
84 | + case 'double': if (is_nan((float) $dataType)) { |
|
85 | + return '.nan'; |
|
86 | + } |
|
79 | 87 | default: |
80 | 88 | return $dataType; |
81 | 89 | } |
@@ -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) { |
@@ -87,7 +87,9 @@ discard block |
||
87 | 87 | { |
88 | 88 | $source = $this->content ?? preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE); |
89 | 89 | //TODO : be more permissive on $strContent values |
90 | - if (!is_array($source) || !count($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT); |
|
90 | + if (!is_array($source) || !count($source)) { |
|
91 | + throw new \Exception(self::EXCEPTION_LINE_SPLIT); |
|
92 | + } |
|
91 | 93 | $previous = $root = new Node(); |
92 | 94 | $emptyLines = []; |
93 | 95 | try { |
@@ -99,7 +101,9 @@ discard block |
||
99 | 101 | foreach ($gen() as $lineNb => $lineString) { |
100 | 102 | $n = new Node($lineString, $lineNb); |
101 | 103 | if ($n->type & (Y::LITTERALS|Y::BLANK)) { |
102 | - if ($this->onSpecialType($n, $previous, $emptyLines)) continue; |
|
104 | + if ($this->onSpecialType($n, $previous, $emptyLines)) { |
|
105 | + continue; |
|
106 | + } |
|
103 | 107 | } else { |
104 | 108 | foreach ($emptyLines as $blankNode) { |
105 | 109 | $blankNode->getParent()->add($blankNode); |
@@ -113,11 +117,15 @@ discard block |
||
113 | 117 | break; |
114 | 118 | default: $target = $previous->type & Y::SCALAR ? $previous->getParent() : $previous; |
115 | 119 | } |
116 | - if ($this->onContextType($n, $target, $lineString)) continue; |
|
120 | + if ($this->onContextType($n, $target, $lineString)) { |
|
121 | + continue; |
|
122 | + } |
|
117 | 123 | $target->add($n); |
118 | 124 | $previous = $n; |
119 | 125 | } |
120 | - if ($this->debug === 2) echo "\033[33mParsed Structure\033[0m\n",var_export($root, true); |
|
126 | + if ($this->debug === 2) { |
|
127 | + echo "\033[33mParsed Structure\033[0m\n",var_export($root, true); |
|
128 | + } |
|
121 | 129 | $out = Builder::buildContent($root, $this->debug); |
122 | 130 | return $out; |
123 | 131 | } catch (\Error|\Exception|\ParseError $e) { |
@@ -137,8 +145,12 @@ discard block |
||
137 | 145 | { |
138 | 146 | $deepest = $previous->getDeepestNode(); |
139 | 147 | if ($n->type & Y::BLANK) { |
140 | - if ($previous->type & Y::SCALAR) $emptyLines[] = $n->setParent($previous->getParent()); |
|
141 | - if ($deepest->type & Y::LITTERALS) $emptyLines[] = $n->setParent($deepest); |
|
148 | + if ($previous->type & Y::SCALAR) { |
|
149 | + $emptyLines[] = $n->setParent($previous->getParent()); |
|
150 | + } |
|
151 | + if ($deepest->type & Y::LITTERALS) { |
|
152 | + $emptyLines[] = $n->setParent($deepest); |
|
153 | + } |
|
142 | 154 | return true; |
143 | 155 | } |
144 | 156 | return false; |
@@ -37,7 +37,7 @@ |
||
37 | 37 | $matchSpaced = preg_match($spaced, $v); |
38 | 38 | $matchIso = preg_match($iso8601, $v); |
39 | 39 | if (is_bool($matchDate) || is_bool($matchCanonical) || is_bool($matchSpaced) || is_bool($matchIso)) { |
40 | - throw new \Exception("Regex date error"); |
|
40 | + throw new \Exception("Regex date error"); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | return $matchDate || $matchCanonical || $matchSpaced || $matchIso; |
@@ -261,8 +261,8 @@ |
||
261 | 261 | if ($this->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($v); |
262 | 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 | - Y::QUOTED => substr($v, 1, -1), |
|
265 | - Y::RAW => strval($v)]; |
|
264 | + Y::QUOTED => substr($v, 1, -1), |
|
265 | + Y::RAW => strval($v)]; |
|
266 | 266 | if (isset($expected[$this->type])) { |
267 | 267 | return $expected[$this->type]; |
268 | 268 | } |
@@ -59,7 +59,9 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function getParent(int $indent = null):Node |
61 | 61 | { |
62 | - if (!is_int($indent)) return $this->parent ?? $this; |
|
62 | + if (!is_int($indent)) { |
|
63 | + return $this->parent ?? $this; |
|
64 | + } |
|
63 | 65 | $cursor = $this; |
64 | 66 | while ($cursor instanceof Node && $cursor->indent >= $indent) { |
65 | 67 | $cursor = $cursor->parent; |
@@ -88,9 +90,15 @@ discard block |
||
88 | 90 | } |
89 | 91 | $this->value->push($child); |
90 | 92 | //modify type according to child |
91 | - if ($child->type & (Y::COMMENT | Y::KEY)) $this->value->type = Y::MAPPING; |
|
92 | - if ($child->type & Y::ITEM) $this->value->type = Y::SEQUENCE; |
|
93 | - if ($this->type & Y::LITTERALS) $this->value->type = $this->type; |
|
93 | + if ($child->type & (Y::COMMENT | Y::KEY)) { |
|
94 | + $this->value->type = Y::MAPPING; |
|
95 | + } |
|
96 | + if ($child->type & Y::ITEM) { |
|
97 | + $this->value->type = Y::SEQUENCE; |
|
98 | + } |
|
99 | + if ($this->type & Y::LITTERALS) { |
|
100 | + $this->value->type = $this->type; |
|
101 | + } |
|
94 | 102 | } |
95 | 103 | } |
96 | 104 | |
@@ -143,10 +151,16 @@ discard block |
||
143 | 151 | $type = R::isProperlyQuoted($nodeValue) ? Y::QUOTED : Y::PARTIAL; |
144 | 152 | return [$type, $nodeValue]; |
145 | 153 | } |
146 | - if (in_array($first, ['{', '['])) return $this->onObject($nodeValue); |
|
147 | - if (in_array($first, ['!', '&', '*'])) return $this->onNodeAction($nodeValue); |
|
154 | + if (in_array($first, ['{', '['])) { |
|
155 | + return $this->onObject($nodeValue); |
|
156 | + } |
|
157 | + if (in_array($first, ['!', '&', '*'])) { |
|
158 | + return $this->onNodeAction($nodeValue); |
|
159 | + } |
|
148 | 160 | // 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)]; |
|
161 | + if($first === '?') { |
|
162 | + return [Y::SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
|
163 | + } |
|
150 | 164 | $characters = [ '#' => [Y::COMMENT, ltrim($v)], |
151 | 165 | "-" => $this->onHyphen($nodeValue), |
152 | 166 | '%' => [Y::DIRECTIVE, ltrim($v)], |
@@ -198,9 +212,15 @@ discard block |
||
198 | 212 | private function onObject($value):array |
199 | 213 | { |
200 | 214 | json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
201 | - if (json_last_error() === JSON_ERROR_NONE) return [Y::JSON, $value]; |
|
202 | - if (preg_match(R::MAPPING, $value)) return [Y::COMPACT_MAPPING, $value]; |
|
203 | - if (preg_match(R::SEQUENCE, $value)) return [Y::COMPACT_SEQUENCE, $value]; |
|
215 | + if (json_last_error() === JSON_ERROR_NONE) { |
|
216 | + return [Y::JSON, $value]; |
|
217 | + } |
|
218 | + if (preg_match(R::MAPPING, $value)) { |
|
219 | + return [Y::COMPACT_MAPPING, $value]; |
|
220 | + } |
|
221 | + if (preg_match(R::SEQUENCE, $value)) { |
|
222 | + return [Y::COMPACT_SEQUENCE, $value]; |
|
223 | + } |
|
204 | 224 | return [Y::PARTIAL, $value]; |
205 | 225 | } |
206 | 226 | |
@@ -215,7 +235,9 @@ discard block |
||
215 | 235 | { |
216 | 236 | if (substr($nodeValue, 0, 3) === '---') { |
217 | 237 | $rest = trim(substr($nodeValue, 3)); |
218 | - if (empty($rest)) return [Y::DOC_START, null]; |
|
238 | + if (empty($rest)) { |
|
239 | + return [Y::DOC_START, null]; |
|
240 | + } |
|
219 | 241 | $n = new Node($rest, $this->line); |
220 | 242 | $n->indent = $this->indent + 4; |
221 | 243 | return [Y::DOC_START, $n->setParent($this)]; |
@@ -257,9 +279,15 @@ discard block |
||
257 | 279 | public function getPhpValue() |
258 | 280 | { |
259 | 281 | $v = &$this->value; |
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); |
|
282 | + if (is_null($v)) { |
|
283 | + return null; |
|
284 | + } |
|
285 | + if ($this->type & (Y::REF_CALL | Y::SCALAR)) { |
|
286 | + return self::getScalar($v); |
|
287 | + } |
|
288 | + if ($this->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) { |
|
289 | + return self::getCompact(substr($v, 1, -1), $this->type); |
|
290 | + } |
|
263 | 291 | $expected = [Y::JSON => json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR), |
264 | 292 | Y::QUOTED => substr($v, 1, -1), |
265 | 293 | Y::RAW => strval($v)]; |
@@ -288,9 +316,15 @@ discard block |
||
288 | 316 | '-.inf' => -INF, |
289 | 317 | '.nan' => NAN |
290 | 318 | ]; |
291 | - if (isset($types[strtolower($v)])) return $types[strtolower($v)]; |
|
292 | - if (R::isDate($v)) return date_create($v); |
|
293 | - if (R::isNumber($v)) return self::getNumber($v); |
|
319 | + if (isset($types[strtolower($v)])) { |
|
320 | + return $types[strtolower($v)]; |
|
321 | + } |
|
322 | + if (R::isDate($v)) { |
|
323 | + return date_create($v); |
|
324 | + } |
|
325 | + if (R::isNumber($v)) { |
|
326 | + return self::getNumber($v); |
|
327 | + } |
|
294 | 328 | return strval($v); |
295 | 329 | } |
296 | 330 | |
@@ -303,8 +337,12 @@ discard block |
||
303 | 337 | */ |
304 | 338 | private static function getNumber(string $v) |
305 | 339 | { |
306 | - if (preg_match("/^(0o\d+)$/i", $v)) return intval(base_convert($v, 8, 10)); |
|
307 | - if (preg_match("/^(0x[\da-f]+)$/i", $v)) return intval(base_convert($v, 16, 10)); |
|
340 | + if (preg_match("/^(0o\d+)$/i", $v)) { |
|
341 | + return intval(base_convert($v, 8, 10)); |
|
342 | + } |
|
343 | + if (preg_match("/^(0x[\da-f]+)$/i", $v)) { |
|
344 | + return intval(base_convert($v, 16, 10)); |
|
345 | + } |
|
308 | 346 | return is_bool(strpos($v, '.')) ? intval($v) : floatval($v); |
309 | 347 | } |
310 | 348 |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | } |
95 | 95 | $this->value->push($child); |
96 | 96 | //modify type according to child |
97 | - if ($child->type & (Y::COMMENT | Y::KEY)) $this->value->type = Y::MAPPING; |
|
97 | + if ($child->type & (Y::COMMENT|Y::KEY)) $this->value->type = Y::MAPPING; |
|
98 | 98 | if ($child->type & Y::ITEM) $this->value->type = Y::SEQUENCE; |
99 | 99 | if ($this->type & Y::LITTERALS) $this->value->type = $this->type; |
100 | 100 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | if (in_array($first, ['{', '['])) return $this->onObject($nodeValue); |
159 | 159 | if (in_array($first, ['!', '&', '*'])) return $this->onNodeAction($nodeValue); |
160 | 160 | // Note : php don't like '?' as an array key -_- |
161 | - if($first === '?') return [Y::SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
|
162 | - $characters = [ '#' => [Y::COMMENT, ltrim($v)], |
|
161 | + if ($first === '?') return [Y::SET_KEY, empty($v) ? null : new Node(ltrim($v), $this->line)]; |
|
162 | + $characters = ['#' => [Y::COMMENT, ltrim($v)], |
|
163 | 163 | "-" => $this->onHyphen($nodeValue), |
164 | 164 | '%' => [Y::DIRECTIVE, ltrim($v)], |
165 | 165 | ':' => [Y::SET_VALUE, empty($v) ? null : new Node(ltrim($v), $this->line)], |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | { |
278 | 278 | $v = &$this->value; |
279 | 279 | if (is_null($v)) return null; |
280 | - if ($this->type & (Y::REF_CALL | Y::SCALAR)) return self::getScalar($v); |
|
281 | - if ($this->type & (Y::COMPACT_MAPPING | Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type); |
|
280 | + if ($this->type & (Y::REF_CALL|Y::SCALAR)) return self::getScalar($v); |
|
281 | + if ($this->type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) return self::getCompact(substr($v, 1, -1), $this->type); |
|
282 | 282 | $expected = [Y::JSON => json_decode($v, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR), |
283 | 283 | Y::QUOTED => substr($v, 1, -1), |
284 | 284 | Y::RAW => strval($v)]; |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | //TODO : this should handle references present inside the string |
341 | 341 | $out = new Compact(); |
342 | 342 | if ($type === Y::COMPACT_SEQUENCE) { |
343 | - $f = function ($e) { return self::getScalar(trim($e));}; |
|
343 | + $f = function($e) { return self::getScalar(trim($e)); }; |
|
344 | 344 | //TODO : that's not robust enough, improve it |
345 | 345 | foreach (array_map($f, explode(",", $mappingOrSeqString)) as $key => $value) { |
346 | 346 | $out[$key] = $value; |
@@ -65,12 +65,12 @@ |
||
65 | 65 | return self::$_root->getReference($identifier); |
66 | 66 | } |
67 | 67 | $typesActions = [Y::COMMENT => 'buildComment', |
68 | - Y::DIRECTIVE => 'buildDirective', |
|
69 | - Y::ITEM => 'buildItem', |
|
70 | - Y::KEY => 'buildKey', |
|
71 | - Y::SET_KEY => 'buildSetKey', |
|
72 | - Y::SET_VALUE => 'buildSetValue', |
|
73 | - Y::TAG => 'buildTag', |
|
68 | + Y::DIRECTIVE => 'buildDirective', |
|
69 | + Y::ITEM => 'buildItem', |
|
70 | + Y::KEY => 'buildKey', |
|
71 | + Y::SET_KEY => 'buildSetKey', |
|
72 | + Y::SET_VALUE => 'buildSetValue', |
|
73 | + Y::TAG => 'buildTag', |
|
74 | 74 | ]; |
75 | 75 | if (isset($typesActions[$type])) { |
76 | 76 | return self::{$typesActions[$type]}($node, $parent); |
@@ -43,14 +43,14 @@ discard block |
||
43 | 43 | */ |
44 | 44 | private static function buildNodeList(NodeList $node, &$parent) |
45 | 45 | { |
46 | - if ($node->type & (Y::RAW | Y::LITTERALS)) { |
|
46 | + if ($node->type & (Y::RAW|Y::LITTERALS)) { |
|
47 | 47 | return self::buildLitteral($node, $node->type); |
48 | 48 | } |
49 | 49 | $p = $parent; |
50 | 50 | switch ($node->type) { |
51 | 51 | case Y::MAPPING: //fall through |
52 | 52 | case Y::SET: $p = new \StdClass; break; |
53 | - case Y::SEQUENCE: $p = [];break; |
|
53 | + case Y::SEQUENCE: $p = []; break; |
|
54 | 54 | // case Y::KEY: $p = $parent;break; |
55 | 55 | } |
56 | 56 | $out = null; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | private static function buildNode(Node $node, &$parent) |
79 | 79 | { |
80 | 80 | extract((array) $node, EXTR_REFS); |
81 | - if ($type & (Y::REF_DEF | Y::REF_CALL)) { |
|
81 | + if ($type&(Y::REF_DEF|Y::REF_CALL)) { |
|
82 | 82 | if (is_object($value)) { |
83 | 83 | $tmp = self::build($value, $parent) ?? $parent; |
84 | 84 | } else { |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | { |
194 | 194 | self::$_root = new YamlObject(); |
195 | 195 | $childTypes = $list->getTypes(); |
196 | - $isaMapping = (bool) (Y::KEY | Y::MAPPING) & $childTypes; |
|
196 | + $isaMapping = (bool) (Y::KEY|Y::MAPPING)&$childTypes; |
|
197 | 197 | $isaSequence = (bool) Y::ITEM & $childTypes; |
198 | 198 | $isaSet = (bool) Y::SET_VALUE & $childTypes; |
199 | 199 | if ($isaMapping && $isaSequence) { |
200 | 200 | throw new \ParseError(sprintf(self::INVALID_DOCUMENT, $key)); |
201 | 201 | } else { |
202 | 202 | switch (true) { |
203 | - case $isaSequence: $list->type = Y::SEQUENCE;break; |
|
204 | - case $isaSet: $list->type = Y::SET;break; |
|
203 | + case $isaSequence: $list->type = Y::SEQUENCE; break; |
|
204 | + case $isaSet: $list->type = Y::SET; break; |
|
205 | 205 | default: $list->type = Y::MAPPING; |
206 | 206 | } |
207 | 207 | } |
@@ -236,15 +236,15 @@ discard block |
||
236 | 236 | $lines[] = self::buildLitteral($child->value, $type); |
237 | 237 | } else { |
238 | 238 | $prefix = ''; |
239 | - if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
239 | + if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
240 | 240 | $prefix = "\n"; |
241 | 241 | } |
242 | 242 | $lines[] = $prefix.$child->value; |
243 | 243 | } |
244 | 244 | } |
245 | - if ($type & Y::RAW) return implode('', $lines); |
|
246 | - if ($type & Y::LITT) return implode("\n", $lines); |
|
247 | - if ($type & Y::LITT_FOLDED) return implode(' ', $lines); |
|
245 | + if ($type&Y::RAW) return implode('', $lines); |
|
246 | + if ($type&Y::LITT) return implode("\n", $lines); |
|
247 | + if ($type&Y::LITT_FOLDED) return implode(' ', $lines); |
|
248 | 248 | return ''; |
249 | 249 | } |
250 | 250 |
@@ -29,7 +29,9 @@ discard block |
||
29 | 29 | */ |
30 | 30 | private static function build(object $node, &$parent = null) |
31 | 31 | { |
32 | - if ($node instanceof NodeList) return self::buildNodeList($node, $parent); |
|
32 | + if ($node instanceof NodeList) { |
|
33 | + return self::buildNodeList($node, $parent); |
|
34 | + } |
|
33 | 35 | return self::buildNode($node, $parent); |
34 | 36 | } |
35 | 37 | |
@@ -84,7 +86,9 @@ discard block |
||
84 | 86 | } else { |
85 | 87 | $tmp = $node->getPhpValue(); |
86 | 88 | } |
87 | - if ($type === Y::REF_DEF) self::$_root->addReference($identifier, $tmp); |
|
89 | + if ($type === Y::REF_DEF) { |
|
90 | + self::$_root->addReference($identifier, $tmp); |
|
91 | + } |
|
88 | 92 | return self::$_root->getReference($identifier); |
89 | 93 | } |
90 | 94 | $typesActions = [Y::COMMENT => 'buildComment', |
@@ -169,10 +173,14 @@ discard block |
||
169 | 173 | } |
170 | 174 | $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE); |
171 | 175 | foreach ($_root->value as $child) { |
172 | - if ($child->type & Y::DOC_START) $totalDocStart++; |
|
176 | + if ($child->type & Y::DOC_START) { |
|
177 | + $totalDocStart++; |
|
178 | + } |
|
173 | 179 | //if 0 or 1 DOC_START = we are still in first document |
174 | 180 | $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0; |
175 | - if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList(); |
|
181 | + if (!isset($documents[$currentDoc])) { |
|
182 | + $documents[$currentDoc] = new NodeList(); |
|
183 | + } |
|
176 | 184 | $documents[$currentDoc]->push($child); |
177 | 185 | } |
178 | 186 | $content = array_map([self::class, 'buildDocument'], $documents, array_keys($documents)); |
@@ -242,9 +250,15 @@ discard block |
||
242 | 250 | $lines[] = $prefix.$child->value; |
243 | 251 | } |
244 | 252 | } |
245 | - if ($type & Y::RAW) return implode('', $lines); |
|
246 | - if ($type & Y::LITT) return implode("\n", $lines); |
|
247 | - if ($type & Y::LITT_FOLDED) return implode(' ', $lines); |
|
253 | + if ($type & Y::RAW) { |
|
254 | + return implode('', $lines); |
|
255 | + } |
|
256 | + if ($type & Y::LITT) { |
|
257 | + return implode("\n", $lines); |
|
258 | + } |
|
259 | + if ($type & Y::LITT_FOLDED) { |
|
260 | + return implode(' ', $lines); |
|
261 | + } |
|
248 | 262 | return ''; |
249 | 263 | } |
250 | 264 | |
@@ -259,8 +273,9 @@ discard block |
||
259 | 273 | private function buildSetKey(Node $node, $parent):void |
260 | 274 | { |
261 | 275 | $key = json_encode(self::build($node->value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
262 | - if (empty($key)) |
|
263 | - throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
|
276 | + if (empty($key)) { |
|
277 | + throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
|
278 | + } |
|
264 | 279 | $parent->{$key} = null; |
265 | 280 | } |
266 | 281 | |
@@ -299,8 +314,11 @@ discard block |
||
299 | 314 | } |
300 | 315 | //TODO: have somewhere a list of common tags and their treatment |
301 | 316 | if (in_array($node->identifier, ['!binary', '!str'])) { |
302 | - if ($node->value->value instanceof NodeList) $node->value->value->type = Y::RAW; |
|
303 | - else $node->value->type = Y::RAW; |
|
317 | + if ($node->value->value instanceof NodeList) { |
|
318 | + $node->value->value->type = Y::RAW; |
|
319 | + } else { |
|
320 | + $node->value->type = Y::RAW; |
|
321 | + } |
|
304 | 322 | } |
305 | 323 | $val = is_null($node->value) ? null : self::build(/** @scrutinizer ignore-type */ $node->value, $node); |
306 | 324 | return new Tag($node->identifier, $val); |