@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE); |
38 | 38 | foreach ($_root->value as $child) { |
39 | 39 | if ($child->type & Y::DOC_START) { |
40 | - if(++$totalDocStart > 1){ |
|
40 | + if (++$totalDocStart > 1) { |
|
41 | 41 | $documents[] = self::buildDocument($buffer, count($documents)); |
42 | 42 | $buffer = new NodeList($child); |
43 | 43 | } |
@@ -82,13 +82,13 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return mixed The parent (object|array) or a string representing the NodeList. |
84 | 84 | */ |
85 | - public static function buildNodeList(NodeList $node, &$parent=null) |
|
85 | + public static function buildNodeList(NodeList $node, &$parent = null) |
|
86 | 86 | { |
87 | 87 | $node->forceType(); |
88 | - if ($node->type & (Y::RAW | Y::LITTERALS)) { |
|
88 | + if ($node->type & (Y::RAW|Y::LITTERALS)) { |
|
89 | 89 | return self::buildLitteral($node, (int) $node->type); |
90 | 90 | } |
91 | - $action = function ($child, &$parent, &$out) { |
|
91 | + $action = function($child, &$parent, &$out) { |
|
92 | 92 | self::build($child, $out); |
93 | 93 | }; |
94 | 94 | if ($node->type & (Y::COMPACT_MAPPING|Y::MAPPING|Y::SET)) { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $out = $parent ?? []; |
98 | 98 | } else { |
99 | 99 | $out = ''; |
100 | - $action = function ($child, &$parent, &$out) { |
|
100 | + $action = function($child, &$parent, &$out) { |
|
101 | 101 | if ($child->type & (Y::SCALAR|Y::QUOTED)) { |
102 | 102 | if ($parent) { |
103 | 103 | $parent->setText(self::build($child)); |
@@ -136,11 +136,11 @@ discard block |
||
136 | 136 | ]; |
137 | 137 | if (isset($actions[$type])) { |
138 | 138 | return TB::{$actions[$type]}($node, $parent); |
139 | - } elseif ($type & Y::COMMENT) { |
|
139 | + } elseif ($type&Y::COMMENT) { |
|
140 | 140 | self::$_root->addComment($line, $value); |
141 | - } elseif ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) { |
|
141 | + } elseif ($type&(Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) { |
|
142 | 142 | return self::buildNodeList($value, $parent); |
143 | - } elseif ($type & (Y::REF_DEF | Y::REF_CALL)) { |
|
143 | + } elseif ($type&(Y::REF_DEF|Y::REF_CALL)) { |
|
144 | 144 | return TB::buildReference($node, $parent); |
145 | 145 | } elseif ($value instanceof Node) { |
146 | 146 | return self::buildNode($value, $parent); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | //remove trailing blank |
167 | 167 | while ($list->top()->type & Y::BLANK) $list->pop(); |
168 | 168 | $result = ''; |
169 | - $separator = [ Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type]; |
|
169 | + $separator = [Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type]; |
|
170 | 170 | foreach ($list as $child) { |
171 | 171 | if ($child->value instanceof NodeList) { |
172 | 172 | $result .= self::buildLitteral($child->value, $type).$separator; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | private static function setLiteralValue(Node $child, string &$result, int $refIndent, string $separator, int $type) |
181 | 181 | { |
182 | 182 | $val = $child->type & (Y::SCALAR) ? $child->value : substr($child->raw, $refIndent); |
183 | - if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
183 | + if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
184 | 184 | if ($result[-1] === $separator) |
185 | 185 | $result[-1] = "\n"; |
186 | 186 | if ($result[-1] === "\n") |
@@ -70,7 +70,9 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public static function build(object $node, &$parent = null) |
72 | 72 | { |
73 | - if ($node instanceof NodeList) return self::buildNodeList($node, $parent); |
|
73 | + if ($node instanceof NodeList) { |
|
74 | + return self::buildNodeList($node, $parent); |
|
75 | + } |
|
74 | 76 | return self::buildNode($node, $parent); |
75 | 77 | } |
76 | 78 | |
@@ -164,7 +166,9 @@ discard block |
||
164 | 166 | $list->rewind(); |
165 | 167 | $refIndent = $list->current()->indent; |
166 | 168 | //remove trailing blank |
167 | - while ($list->top()->type & Y::BLANK) $list->pop(); |
|
169 | + while ($list->top()->type & Y::BLANK) { |
|
170 | + $list->pop(); |
|
171 | + } |
|
168 | 172 | $result = ''; |
169 | 173 | $separator = [ Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type]; |
170 | 174 | foreach ($list as $child) { |
@@ -181,10 +185,12 @@ discard block |
||
181 | 185 | { |
182 | 186 | $val = $child->type & (Y::SCALAR) ? $child->value : substr($child->raw, $refIndent); |
183 | 187 | if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
184 | - if ($result[-1] === $separator) |
|
185 | - $result[-1] = "\n"; |
|
186 | - if ($result[-1] === "\n") |
|
187 | - $result .= $val; |
|
188 | + if ($result[-1] === $separator) { |
|
189 | + $result[-1] = "\n"; |
|
190 | + } |
|
191 | + if ($result[-1] === "\n") { |
|
192 | + $result .= $val; |
|
193 | + } |
|
188 | 194 | return; |
189 | 195 | } |
190 | 196 | $result .= $val.$separator; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @throws \ParseError if Key has no name(identifier) Note: empty string is allowed |
32 | 32 | * @return null |
33 | 33 | */ |
34 | - public static function buildKey(Node $node, &$parent=null) |
|
34 | + public static function buildKey(Node $node, &$parent = null) |
|
35 | 35 | { |
36 | 36 | extract((array) $node, EXTR_REFS); |
37 | 37 | if (is_null($identifier)) { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $numKeys = array_filter(array_keys($ref), 'is_int'); |
79 | 79 | $key = count($numKeys) > 0 ? max($numKeys) + 1 : 0; |
80 | 80 | if ($value instanceof Node) { |
81 | - if($value->type & Y::KEY) { |
|
81 | + if ($value->type & Y::KEY) { |
|
82 | 82 | self::buildKey($node->value, $parent); |
83 | 83 | return; |
84 | 84 | } elseif ($value->type & Y::ITEM) { |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | public function buildSetKey(Node $node, &$parent) |
103 | 103 | { |
104 | 104 | $built = is_object($node->value) ? Builder::build($node->value) : null; |
105 | - $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
|
105 | + $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built; |
|
106 | 106 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
107 | 107 | if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
108 | 108 | $parent->{trim($key, '\'" ')} = null; |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | { |
119 | 119 | $prop = array_keys(get_object_vars($parent)); |
120 | 120 | $key = end($prop); |
121 | - if ($node->value->type & (Y::ITEM|Y::KEY )) { |
|
121 | + if ($node->value->type & (Y::ITEM|Y::KEY)) { |
|
122 | 122 | $node->value = new NodeList($node->value); |
123 | 123 | } |
124 | 124 | $parent->{$key} = Builder::build($node->value); |
@@ -17,7 +17,9 @@ discard block |
||
17 | 17 | public static function buildReference($node, $parent) |
18 | 18 | { |
19 | 19 | $tmp = is_null($node->value) ? null : Builder::build($node->value, $parent); |
20 | - if ($node->type === Y::REF_DEF) Builder::$_root->addReference($node->identifier, $tmp); |
|
20 | + if ($node->type === Y::REF_DEF) { |
|
21 | + Builder::$_root->addReference($node->identifier, $tmp); |
|
22 | + } |
|
21 | 23 | return Builder::$_root->getReference($node->identifier); |
22 | 24 | } |
23 | 25 | |
@@ -104,7 +106,9 @@ discard block |
||
104 | 106 | $built = is_object($node->value) ? Builder::build($node->value) : null; |
105 | 107 | $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
106 | 108 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
107 | - if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
|
109 | + if (empty($key)) { |
|
110 | + throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
|
111 | + } |
|
108 | 112 | $parent->{trim($key, '\'" ')} = null; |
109 | 113 | } |
110 | 114 |