@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Dallgoot\Yaml; |
3 | 3 | |
4 | -require_once __DIR__ . '/../../dependencies/autoload.php'; |
|
4 | +require_once __DIR__.'/../../dependencies/autoload.php'; |
|
5 | 5 | |
6 | 6 | use Dallgoot; |
7 | 7 | |
8 | -$fileName = __DIR__ . '/../dummy.yml'; |
|
8 | +$fileName = __DIR__.'/../dummy.yml'; |
|
9 | 9 | |
10 | 10 | $yamlObject = Yaml::parseFile($fileName, $options = null, $debug = null); |
11 | 11 |
@@ -177,7 +177,7 @@ |
||
177 | 177 | elseif (in_array($first, ['?', ':'])) NodeHandlers::onSetElement($nodeValue, $this); |
178 | 178 | elseif (in_array($first, ['!', '&', '*'])) NodeHandlers::onNodeAction($nodeValue, $this); |
179 | 179 | else { |
180 | - $characters = [ '#' => [Y::COMMENT, $nodeValue], |
|
180 | + $characters = ['#' => [Y::COMMENT, $nodeValue], |
|
181 | 181 | '%' => [Y::DIRECTIVE, $nodeValue], |
182 | 182 | '>' => [Y::LITT_FOLDED, null], |
183 | 183 | '|' => [Y::LITT, null] |
@@ -68,8 +68,12 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function getParent(int $indent = null, $type = 0):Node |
70 | 70 | { |
71 | - if ($this->type === Y::ROOT) return $this; |
|
72 | - if (!is_int($indent)) return $this->parent ?? $this; |
|
71 | + if ($this->type === Y::ROOT) { |
|
72 | + return $this; |
|
73 | + } |
|
74 | + if (!is_int($indent)) { |
|
75 | + return $this->parent ?? $this; |
|
76 | + } |
|
73 | 77 | $cursor = $this; |
74 | 78 | while ($cursor instanceof Node && $cursor->indent >= $indent) { |
75 | 79 | if ($cursor->indent === $indent && $cursor->type !== $type) { |
@@ -171,12 +175,17 @@ discard block |
||
171 | 175 | { |
172 | 176 | $v = ltrim(substr($nodeValue, 1)); |
173 | 177 | $first = $nodeValue[0]; |
174 | - if ($first === "-") NodeHandlers::onHyphen($nodeValue, $this); |
|
175 | - elseif (in_array($first, ['"', "'"])) NodeHandlers::onQuoted($nodeValue, $this); |
|
176 | - elseif (in_array($first, ['{', '['])) NodeHandlers::onCompact($nodeValue, $this); |
|
177 | - elseif (in_array($first, ['?', ':'])) NodeHandlers::onSetElement($nodeValue, $this); |
|
178 | - elseif (in_array($first, ['!', '&', '*'])) NodeHandlers::onNodeAction($nodeValue, $this); |
|
179 | - else { |
|
178 | + if ($first === "-") { |
|
179 | + NodeHandlers::onHyphen($nodeValue, $this); |
|
180 | + } elseif (in_array($first, ['"', "'"])) { |
|
181 | + NodeHandlers::onQuoted($nodeValue, $this); |
|
182 | + } elseif (in_array($first, ['{', '['])) { |
|
183 | + NodeHandlers::onCompact($nodeValue, $this); |
|
184 | + } elseif (in_array($first, ['?', ':'])) { |
|
185 | + NodeHandlers::onSetElement($nodeValue, $this); |
|
186 | + } elseif (in_array($first, ['!', '&', '*'])) { |
|
187 | + NodeHandlers::onNodeAction($nodeValue, $this); |
|
188 | + } else { |
|
180 | 189 | $characters = [ '#' => [Y::COMMENT, $nodeValue], |
181 | 190 | '%' => [Y::DIRECTIVE, $nodeValue], |
182 | 191 | '>' => [Y::LITT_FOLDED, null], |
@@ -68,28 +68,28 @@ |
||
68 | 68 | public static function onCompact($value, Node $node) |
69 | 69 | { |
70 | 70 | $node->value = json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
71 | - if (json_last_error() === JSON_ERROR_NONE){ |
|
71 | + if (json_last_error() === JSON_ERROR_NONE) { |
|
72 | 72 | $node->type = Y::JSON; |
73 | 73 | return; |
74 | 74 | } |
75 | 75 | $node->value = new NodeList(); |
76 | - if (preg_match(R::MAPPING, $value)){ |
|
76 | + if (preg_match(R::MAPPING, $value)) { |
|
77 | 77 | $node->type = Y::COMPACT_MAPPING; |
78 | 78 | $node->value->type = Y::COMPACT_MAPPING; |
79 | - preg_match_all(R::MAPPING_VALUES, trim(substr($value, 1,-1)), $matches); |
|
79 | + preg_match_all(R::MAPPING_VALUES, trim(substr($value, 1, -1)), $matches); |
|
80 | 80 | foreach ($matches['k'] as $index => $property) { |
81 | 81 | $n = new Node('', $node->line); |
82 | 82 | $n->type = Y::KEY; |
83 | - $n->identifier = trim($property, '"\' ');//TODO : maybe check for proper quoting first ? |
|
83 | + $n->identifier = trim($property, '"\' '); //TODO : maybe check for proper quoting first ? |
|
84 | 84 | $n->value = new Node(trim($matches['v'][$index]), $node->line); |
85 | 85 | $node->value->push($n); |
86 | 86 | } |
87 | 87 | return; |
88 | 88 | } |
89 | - if (preg_match(R::SEQUENCE, $value)){ |
|
89 | + if (preg_match(R::SEQUENCE, $value)) { |
|
90 | 90 | $node->type = Y::COMPACT_SEQUENCE; |
91 | 91 | $node->value->type = Y::COMPACT_SEQUENCE; |
92 | - preg_match_all(R::SEQUENCE_VALUES, trim(substr($value, 1,-1)), $matches); |
|
92 | + preg_match_all(R::SEQUENCE_VALUES, trim(substr($value, 1, -1)), $matches); |
|
93 | 93 | foreach ($matches['item'] as $key => $item) { |
94 | 94 | $i = new Node('', $node->line); |
95 | 95 | $i->type = Y::ITEM; |
@@ -57,7 +57,7 @@ |
||
57 | 57 | case '!omap': $value->type = Y::SEQUENCE;break; |
58 | 58 | // assumed to be !str,!binary |
59 | 59 | default: $parent = null; |
60 | - $value->type = Y::RAW; |
|
60 | + $value->type = Y::RAW; |
|
61 | 61 | } |
62 | 62 | $this->value = Builder::buildNodeList($value, $parent); |
63 | 63 | return $this->value; |
@@ -53,8 +53,8 @@ |
||
53 | 53 | $value->forceType(); |
54 | 54 | // $parent = Builder::$_root; |
55 | 55 | switch ($this->tagName) { |
56 | - case '!set': $value->type = Y::SET;break; |
|
57 | - case '!omap': $value->type = Y::SEQUENCE;break; |
|
56 | + case '!set': $value->type = Y::SET; break; |
|
57 | + case '!omap': $value->type = Y::SEQUENCE; break; |
|
58 | 58 | // assumed to be !str,!binary |
59 | 59 | default: $parent = null; |
60 | 60 | $value->type = Y::RAW; |
@@ -98,27 +98,27 @@ discard block |
||
98 | 98 | * |
99 | 99 | * @return mixed The parent (object|array) or a string representing the NodeList. |
100 | 100 | */ |
101 | - public static function buildNodeList(NodeList $list, &$parent=null) |
|
101 | + public static function buildNodeList(NodeList $list, &$parent = null) |
|
102 | 102 | { |
103 | 103 | $list->forceType(); |
104 | - $action = function ($child, &$parent, &$out) { |
|
104 | + $action = function($child, &$parent, &$out) { |
|
105 | 105 | self::build($child, $out); |
106 | 106 | }; |
107 | 107 | $list->type = $list->type ?? Y::RAW; |
108 | 108 | if ($list->type & (Y::RAW|Y::LITTERALS)) { |
109 | - $tmp = self::buildLitteral($list, $list->type);//var_dump("ICI1",$list, $tmp); |
|
109 | + $tmp = self::buildLitteral($list, $list->type); //var_dump("ICI1",$list, $tmp); |
|
110 | 110 | return $tmp; |
111 | 111 | } elseif ($list->type & (Y::COMPACT_MAPPING|Y::MAPPING|Y::SET)) {//var_dump("ICI2"); |
112 | 112 | $out = $parent ?? new \StdClass; |
113 | 113 | } elseif ($list->type & (Y::COMPACT_SEQUENCE|Y::SEQUENCE)) {//var_dump("ICI3"); |
114 | 114 | $out = $parent ?? []; |
115 | 115 | } else { |
116 | - $out = null;//var_dump("ICI"); |
|
117 | - $action = function ($child, &$parent, &$out) { |
|
116 | + $out = null; //var_dump("ICI"); |
|
117 | + $action = function($child, &$parent, &$out) { |
|
118 | 118 | if ($child->type & (Y::SCALAR|Y::QUOTED|Y::DOC_START)) { |
119 | 119 | $out .= Node2PHP::get($child); |
120 | 120 | } else { |
121 | - self::build($child);//var_dump("HERE"); |
|
121 | + self::build($child); //var_dump("HERE"); |
|
122 | 122 | } |
123 | 123 | // var_dump("out:".$out); |
124 | 124 | }; |
@@ -152,15 +152,15 @@ discard block |
||
152 | 152 | ]; |
153 | 153 | if (isset($actions[$type])) { |
154 | 154 | return TB::{$actions[$type]}($node, $parent); |
155 | - } elseif ($type & Y::COMMENT) { |
|
155 | + } elseif ($type&Y::COMMENT) { |
|
156 | 156 | self::$_root->addComment($line, $value); |
157 | 157 | // } elseif ($type & Y::DOC_START) { |
158 | 158 | // if (!is_null($value)) { |
159 | 159 | // return self::build($value->value, $self::$_root); |
160 | 160 | // } |
161 | - } elseif ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) { |
|
161 | + } elseif ($type&(Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) { |
|
162 | 162 | return self::buildNodeList($value, $parent); |
163 | - } elseif ($type & (Y::REF_DEF | Y::REF_CALL)) { |
|
163 | + } elseif ($type&(Y::REF_DEF|Y::REF_CALL)) { |
|
164 | 164 | return TB::buildReference($node, $parent); |
165 | 165 | } elseif ($value instanceof Node) { |
166 | 166 | return self::buildNode($value, $parent); |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | $result = ''; |
185 | 185 | $list->rewind(); |
186 | 186 | $refIndent = $list->count() > 0 ? $list->current()->indent : 0; |
187 | - if($list->count()) { |
|
187 | + if ($list->count()) { |
|
188 | 188 | //remove trailing blank |
189 | 189 | while ($list->top()->type & Y::BLANK) $list->pop(); |
190 | - $separator = [ Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type]; |
|
190 | + $separator = [Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type]; |
|
191 | 191 | foreach ($list as $child) { |
192 | 192 | if ($child->value instanceof NodeList) { |
193 | 193 | $result .= self::buildLitteral($child->value, $type).$separator; |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $val = substr($node->raw, $refIndent); |
215 | 215 | } |
216 | 216 | } |
217 | - if ($type & Y::LITT_FOLDED && ($node->indent > $refIndent || ($node->type & Y::BLANK))) { |
|
217 | + if ($type&Y::LITT_FOLDED && ($node->indent > $refIndent || ($node->type & Y::BLANK))) { |
|
218 | 218 | if ($result[-1] === $separator) |
219 | 219 | $result[-1] = "\n"; |
220 | 220 | if ($result[-1] === "\n") |
@@ -86,7 +86,9 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public static function build(object $node, &$parent = null) |
88 | 88 | { |
89 | - if ($node instanceof NodeList) return self::buildNodeList($node, $parent); |
|
89 | + if ($node instanceof NodeList) { |
|
90 | + return self::buildNodeList($node, $parent); |
|
91 | + } |
|
90 | 92 | return self::buildNode($node, $parent); |
91 | 93 | } |
92 | 94 | |
@@ -186,7 +188,9 @@ discard block |
||
186 | 188 | $refIndent = $list->count() > 0 ? $list->current()->indent : 0; |
187 | 189 | if($list->count()) { |
188 | 190 | //remove trailing blank |
189 | - while ($list->top()->type & Y::BLANK) $list->pop(); |
|
191 | + while ($list->top()->type & Y::BLANK) { |
|
192 | + $list->pop(); |
|
193 | + } |
|
190 | 194 | $separator = [ Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type]; |
191 | 195 | foreach ($list as $child) { |
192 | 196 | if ($child->value instanceof NodeList) { |
@@ -215,10 +219,12 @@ discard block |
||
215 | 219 | } |
216 | 220 | } |
217 | 221 | if ($type & Y::LITT_FOLDED && ($node->indent > $refIndent || ($node->type & Y::BLANK))) { |
218 | - if ($result[-1] === $separator) |
|
219 | - $result[-1] = "\n"; |
|
220 | - if ($result[-1] === "\n") |
|
221 | - $result .= $val; |
|
222 | + if ($result[-1] === $separator) { |
|
223 | + $result[-1] = "\n"; |
|
224 | + } |
|
225 | + if ($result[-1] === "\n") { |
|
226 | + $result .= $val; |
|
227 | + } |
|
222 | 228 | return; |
223 | 229 | } |
224 | 230 | $result .= $val.$separator; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } else { |
53 | 53 | self::dump($dataType, 0); |
54 | 54 | } |
55 | - $out = implode("\n", iterator_to_array(self::$result));//var_dump(iterator_to_array(self::$result)); |
|
55 | + $out = implode("\n", iterator_to_array(self::$result)); //var_dump(iterator_to_array(self::$result)); |
|
56 | 56 | self::$result = null; |
57 | 57 | return $out; |
58 | 58 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | foreach ($array as $key => $item) { |
120 | 120 | $lineStart = current($refKeys) === $key ? "- " : "- $key: "; |
121 | 121 | if (is_scalar($item)) { |
122 | - self::add($lineStart.self::dump($item,0), $indent); |
|
122 | + self::add($lineStart.self::dump($item, 0), $indent); |
|
123 | 123 | } else { |
124 | 124 | self::add(rtrim($lineStart), $indent); |
125 | 125 | self::dump($item, $indent + self::INDENT); |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | //TODO: consider dumping datetime as date strings according to a format provided by user or default |
150 | 150 | if ($obj instanceof \DateTime) return $obj->format(self::DATE_FORMAT); |
151 | 151 | // if ($obj instanceof \SplString) {var_dump('splstrin',$obj);return '"'.$obj.'"';} |
152 | - $propList = get_object_vars($obj);//var_dump($propList); |
|
152 | + $propList = get_object_vars($obj); //var_dump($propList); |
|
153 | 153 | foreach ($propList as $property => $value) { |
154 | 154 | if (is_scalar($value) || $value instanceof Compact || $value instanceof \DateTime) { |
155 | - self::add("$property: ".self::dump($value, $indent), $indent);//var_dump('IS SCALAR', $value); |
|
155 | + self::add("$property: ".self::dump($value, $indent), $indent); //var_dump('IS SCALAR', $value); |
|
156 | 156 | } else { |
157 | 157 | self::add("$property:", $indent); |
158 | 158 | // self::add(self::dump($value, $indent + self::INDENT), $indent + self::INDENT);var_dump('NOT SCALAR'); |
159 | - self::dump($value, $indent + self::INDENT);//var_dump('NOT SCALAR'); |
|
159 | + self::dump($value, $indent + self::INDENT); //var_dump('NOT SCALAR'); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | $pairs = []; |
167 | 167 | if (is_array($subject) || $subject instanceof \ArrayIterator) { |
168 | 168 | $max = count($subject); |
169 | - $objectAsArray = is_array($subject) ? $subject : $subject->getArrayCopy();//var_dump(array_keys($objectAsArray), range(0, $max)); |
|
170 | - if(array_keys($objectAsArray) !== range(0, $max-1)) { |
|
169 | + $objectAsArray = is_array($subject) ? $subject : $subject->getArrayCopy(); //var_dump(array_keys($objectAsArray), range(0, $max)); |
|
170 | + if (array_keys($objectAsArray) !== range(0, $max - 1)) { |
|
171 | 171 | $pairs = $objectAsArray; |
172 | 172 | } else { |
173 | 173 | $valuesList = []; |
@@ -42,7 +42,9 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public static function toString($dataType, int $options = null):string |
44 | 44 | { |
45 | - if (is_null($dataType)) throw new \Exception(self::class.": No content to convert to Yaml", 1); |
|
45 | + if (is_null($dataType)) { |
|
46 | + throw new \Exception(self::class.": No content to convert to Yaml", 1); |
|
47 | + } |
|
46 | 48 | self::$options = is_int($options) ? $options : self::OPTIONS; |
47 | 49 | self::$result = new DLL; |
48 | 50 | if ($dataType instanceof YamlObject) { |
@@ -76,8 +78,12 @@ discard block |
||
76 | 78 | private static function dump($dataType, int $indent) |
77 | 79 | { |
78 | 80 | if (is_scalar($dataType)) { |
79 | - if ($dataType === INF) return '.inf'; |
|
80 | - if ($dataType === -INF) return '-.inf'; |
|
81 | + if ($dataType === INF) { |
|
82 | + return '.inf'; |
|
83 | + } |
|
84 | + if ($dataType === -INF) { |
|
85 | + return '-.inf'; |
|
86 | + } |
|
81 | 87 | switch (gettype($dataType)) { |
82 | 88 | case 'boolean': return $dataType ? 'true' : 'false'; |
83 | 89 | case 'float': //fall through |
@@ -94,7 +100,9 @@ discard block |
||
94 | 100 | |
95 | 101 | private static function dumpYamlObject(YamlObject $obj) |
96 | 102 | { |
97 | - if ($obj->hasDocStart() && self::$result instanceof DLL) self::$result->push("---"); |
|
103 | + if ($obj->hasDocStart() && self::$result instanceof DLL) { |
|
104 | + self::$result->push("---"); |
|
105 | + } |
|
98 | 106 | // self::dump($obj, 0); |
99 | 107 | if (count($obj) > 0) { |
100 | 108 | self::dumpArray($obj->getArrayCopy(), 0); |
@@ -145,9 +153,13 @@ discard block |
||
145 | 153 | self::add(self::dump($obj->value, $indent + self::INDENT), $indent + self::INDENT); |
146 | 154 | } |
147 | 155 | } |
148 | - if ($obj instanceof Compact) return self::dumpCompact($obj, $indent); |
|
156 | + if ($obj instanceof Compact) { |
|
157 | + return self::dumpCompact($obj, $indent); |
|
158 | + } |
|
149 | 159 | //TODO: consider dumping datetime as date strings according to a format provided by user or default |
150 | - if ($obj instanceof \DateTime) return $obj->format(self::DATE_FORMAT); |
|
160 | + if ($obj instanceof \DateTime) { |
|
161 | + return $obj->format(self::DATE_FORMAT); |
|
162 | + } |
|
151 | 163 | // if ($obj instanceof \SplString) {var_dump('splstrin',$obj);return '"'.$obj.'"';} |
152 | 164 | $propList = get_object_vars($obj);//var_dump($propList); |
153 | 165 | foreach ($propList as $property => $value) { |
@@ -23,9 +23,15 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public static function get(Node $n) |
25 | 25 | { |
26 | - if (is_null($n->value)) return null; |
|
27 | - if ($n->type & (Y::REF_CALL|Y::SCALAR)) return self::getScalar((string) $n->value); |
|
28 | - if ($n->type & Y::JSON) return $n->value; |
|
26 | + if (is_null($n->value)) { |
|
27 | + return null; |
|
28 | + } |
|
29 | + if ($n->type & (Y::REF_CALL|Y::SCALAR)) { |
|
30 | + return self::getScalar((string) $n->value); |
|
31 | + } |
|
32 | + if ($n->type & Y::JSON) { |
|
33 | + return $n->value; |
|
34 | + } |
|
29 | 35 | $expected = [Y::QUOTED => trim((string) $n->value, "\"'"), |
30 | 36 | Y::RAW => strval((string) $n->value)]; |
31 | 37 | return $expected[$n->type] ?? null; |
@@ -41,8 +47,12 @@ discard block |
||
41 | 47 | */ |
42 | 48 | public static function getScalar(string $v) |
43 | 49 | { |
44 | - if (R::isDate($v)) return self::$dateAsString ? $v : date_create($v); |
|
45 | - if (R::isNumber($v)) return self::getNumber($v); |
|
50 | + if (R::isDate($v)) { |
|
51 | + return self::$dateAsString ? $v : date_create($v); |
|
52 | + } |
|
53 | + if (R::isNumber($v)) { |
|
54 | + return self::getNumber($v); |
|
55 | + } |
|
46 | 56 | $types = ['yes' => true, |
47 | 57 | 'no' => false, |
48 | 58 | 'true' => true, |
@@ -64,8 +74,12 @@ discard block |
||
64 | 74 | */ |
65 | 75 | private static function getNumber(string $v) |
66 | 76 | { |
67 | - if (preg_match(R::OCTAL_NUM, $v)) return intval(base_convert($v, 8, 10)); |
|
68 | - if (preg_match(R::HEX_NUM, $v)) return intval(base_convert($v, 16, 10)); |
|
77 | + if (preg_match(R::OCTAL_NUM, $v)) { |
|
78 | + return intval(base_convert($v, 8, 10)); |
|
79 | + } |
|
80 | + if (preg_match(R::HEX_NUM, $v)) { |
|
81 | + return intval(base_convert($v, 16, 10)); |
|
82 | + } |
|
69 | 83 | return is_bool(strpos($v, '.')) ? intval($v) : floatval($v); |
70 | 84 | } |
71 | 85 | } |
72 | 86 | \ No newline at end of file |
@@ -60,22 +60,22 @@ |
||
60 | 60 | { |
61 | 61 | if (is_null($this->type)) { |
62 | 62 | $childTypes = $this->getTypes(); |
63 | - if ($childTypes & (Y::KEY|Y::SET_KEY)) { |
|
64 | - if ($childTypes & Y::ITEM) { |
|
63 | + if ($childTypes&(Y::KEY|Y::SET_KEY)) { |
|
64 | + if ($childTypes&Y::ITEM) { |
|
65 | 65 | throw new \ParseError(self::class.": Error conflicting types found"); |
66 | 66 | } |
67 | 67 | $this->type = Y::MAPPING; |
68 | 68 | } else { |
69 | - if ($childTypes & Y::ITEM) { |
|
69 | + if ($childTypes&Y::ITEM) { |
|
70 | 70 | $this->type = Y::SEQUENCE; |
71 | - } elseif ($childTypes & Y::DOC_START && $this->count() === 1) {var_dump(__METHOD__.' theres a DOCSTART'); |
|
71 | + } elseif ($childTypes&Y::DOC_START && $this->count() === 1) {var_dump(__METHOD__.' theres a DOCSTART'); |
|
72 | 72 | if ($child->value instanceof Node) { |
73 | 73 | $this->type = $child->value->type; |
74 | 74 | } elseif ($child->value instanceof NodeList) { |
75 | 75 | $child->value->forceType(); |
76 | - $this->type = $child->value->type; |
|
76 | + $this->type = $child->value->type; |
|
77 | 77 | } |
78 | - } elseif (!($childTypes & Y::COMMENT)) { |
|
78 | + } elseif (!($childTypes&Y::COMMENT)) { |
|
79 | 79 | $this->type = Y::LITT_FOLDED; |
80 | 80 | } else { |
81 | 81 | $this->type = Y::SCALAR; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @throws \ParseError if Key has no name(identifier) Note: empty string is allowed |
33 | 33 | * @return null |
34 | 34 | */ |
35 | - public static function buildKey(Node $node, &$parent=null) |
|
35 | + public static function buildKey(Node $node, &$parent = null) |
|
36 | 36 | { |
37 | 37 | extract((array) $node, EXTR_REFS); |
38 | 38 | if (is_null($identifier)) { |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | public static function buildSetKey(Node $node, &$parent = null) |
100 | 100 | { |
101 | 101 | $built = is_object($node->value) ? Builder::build($node->value) : null; |
102 | - $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
|
102 | + $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built; |
|
103 | 103 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
104 | 104 | if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
105 | 105 | $parent->{trim($key, '\'" ')} = null; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | { |
116 | 116 | $prop = array_keys(get_object_vars($parent)); |
117 | 117 | $key = end($prop); |
118 | - if ($node->value->type & (Y::ITEM|Y::KEY )) { |
|
118 | + if ($node->value->type & (Y::ITEM|Y::KEY)) { |
|
119 | 119 | $node->value = new NodeList($node->value); |
120 | 120 | } |
121 | 121 | $parent->{$key} = Builder::build(/** @scrutinizer ignore-type */ $node->value); |