@@ -74,8 +74,12 @@ |
||
74 | 74 | { |
75 | 75 | $prop = get_object_vars($this); |
76 | 76 | unset($prop["__yaml__object__api"]); |
77 | - if (count($prop) > 0) return $prop; |
|
78 | - if (count($this) > 0) return iterator_to_array($this); |
|
77 | + if (count($prop) > 0) { |
|
78 | + return $prop; |
|
79 | + } |
|
80 | + if (count($this) > 0) { |
|
81 | + return iterator_to_array($this); |
|
82 | + } |
|
79 | 83 | return $this->__yaml__object__api->value ?? "_Empty YamlObject_"; |
80 | 84 | } |
81 | 85 | } |
@@ -77,7 +77,7 @@ |
||
77 | 77 | return $this->__yaml__object__api->_anchors[$name]; |
78 | 78 | } |
79 | 79 | throw new \UnexpectedValueException(sprintf(self::UNKNOWN_REFERENCE, |
80 | - $name, implode(',',array_keys($this->__yaml__object__api->_anchors))) |
|
80 | + $name, implode(',', array_keys($this->__yaml__object__api->_anchors))) |
|
81 | 81 | ); |
82 | 82 | } |
83 | 83 |
@@ -79,12 +79,12 @@ |
||
79 | 79 | */ |
80 | 80 | public function checkTypeCoherence($estimatedType):bool |
81 | 81 | { |
82 | - // if ($this->type === self::MAPPING) { |
|
83 | - // if ($estimatedType === self::SEQUENCE) { |
|
84 | - // throw new \ParseError("Error : no coherence in types", 1); |
|
85 | - // } |
|
86 | - // } |
|
87 | - return (bool) $estimatedType; |
|
82 | + // if ($this->type === self::MAPPING) { |
|
83 | + // if ($estimatedType === self::SEQUENCE) { |
|
84 | + // throw new \ParseError("Error : no coherence in types", 1); |
|
85 | + // } |
|
86 | + // } |
|
87 | + return (bool) $estimatedType; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | public function build(&$parent = null) |
@@ -50,7 +50,9 @@ discard block |
||
50 | 50 | $tmp->rewind(); |
51 | 51 | $fqn = __NAMESPACE__."\\Nodes\\$nodeType"; |
52 | 52 | foreach ($tmp as $child) { |
53 | - if ($child instanceof $fqn) return true; |
|
53 | + if ($child instanceof $fqn) { |
|
54 | + return true; |
|
55 | + } |
|
54 | 56 | } |
55 | 57 | return false; |
56 | 58 | } |
@@ -64,7 +66,9 @@ discard block |
||
64 | 66 | && !($child instanceof Directive) |
65 | 67 | && !($child instanceof Blank) |
66 | 68 | && !($child instanceof Docstart |
67 | - && is_null($child->value)) ) return true; |
|
69 | + && is_null($child->value)) ) { |
|
70 | + return true; |
|
71 | + } |
|
68 | 72 | } |
69 | 73 | return false; |
70 | 74 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | && !($child instanceof Directive) |
65 | 65 | && !($child instanceof Blank) |
66 | 66 | && !($child instanceof Docstart |
67 | - && is_null($child->value)) ) return true; |
|
67 | + && is_null($child->value))) return true; |
|
68 | 68 | } |
69 | 69 | return false; |
70 | 70 | } |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | public function push($node): void |
73 | 73 | { |
74 | 74 | $type = null; |
75 | - if ($node instanceof Item ) { |
|
75 | + if ($node instanceof Item) { |
|
76 | 76 | $type = self::SEQUENCE; |
77 | 77 | } elseif ($node instanceof Key) { |
78 | 78 | $type = self::MAPPING; |
79 | - } elseif ($node->isOneOf('SetKey','SetValue')) { |
|
79 | + } elseif ($node->isOneOf('SetKey', 'SetValue')) { |
|
80 | 80 | $type = self::SET; |
81 | - } elseif ($node instanceof Scalar){ |
|
81 | + } elseif ($node instanceof Scalar) { |
|
82 | 82 | $type = self::MULTILINE; |
83 | 83 | } |
84 | 84 | if (!is_null($type) && $this->checkTypeCoherence($type)) { |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $output = trim($first->raw); |
142 | 142 | foreach ($list as $child) { |
143 | 143 | if ($child instanceof Scalar) { |
144 | - $separator = isset($output[-1]) && $output[-1] === "\n" ? '' : ' '; |
|
144 | + $separator = isset($output[-1]) && $output[-1] === "\n" ? '' : ' '; |
|
145 | 145 | $output .= $separator.trim($child->raw); |
146 | 146 | } elseif ($child instanceof Blank) { |
147 | 147 | $output .= "\n"; |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | if ($child instanceof Comment) { |
168 | 168 | // $child->build(); |
169 | 169 | } else { |
170 | - if($child->value instanceof Comment) { |
|
170 | + if ($child->value instanceof Comment) { |
|
171 | 171 | // $child->value->build(); |
172 | 172 | // $child->value = null; |
173 | - } elseif($child->value instanceof NodeList) { |
|
173 | + } elseif ($child->value instanceof NodeList) { |
|
174 | 174 | $child->value = $child->value->filterComment(); |
175 | 175 | } |
176 | 176 | $out->push($child); |
@@ -13,7 +13,7 @@ |
||
13 | 13 | public function __construct(string $nodeString, int $line) |
14 | 14 | { |
15 | 15 | parent::__construct($nodeString, $line); |
16 | - preg_match_all(Regex::MAPPING_VALUES, trim(substr(trim($nodeString), 1,-1)), $matches); |
|
16 | + preg_match_all(Regex::MAPPING_VALUES, trim(substr(trim($nodeString), 1, -1)), $matches); |
|
17 | 17 | foreach ($matches['k'] as $index => $property) { |
18 | 18 | $pair = $property.': '.trim($matches['v'][$index]); |
19 | 19 | $child = NodeFactory::get($pair, $line); |
@@ -10,17 +10,17 @@ |
||
10 | 10 | */ |
11 | 11 | class Comment extends NodeGeneric |
12 | 12 | { |
13 | - public function specialProcess(NodeGeneric &$previous, array &$emptyLines):bool |
|
14 | - { |
|
13 | + public function specialProcess(NodeGeneric &$previous, array &$emptyLines):bool |
|
14 | + { |
|
15 | 15 | $previous->getRoot()->add($this); |
16 | 16 | return true; |
17 | - } |
|
17 | + } |
|
18 | 18 | |
19 | - public function build(&$parent = null) |
|
20 | - { |
|
19 | + public function build(&$parent = null) |
|
20 | + { |
|
21 | 21 | $root = $this->getRoot(); |
22 | 22 | $yamlObject = $root->getYamlObject(); |
23 | 23 | $yamlObject->addComment($this->line, $this->raw); |
24 | 24 | return null; |
25 | - } |
|
25 | + } |
|
26 | 26 | } |
27 | 27 | \ No newline at end of file |
@@ -10,7 +10,7 @@ |
||
10 | 10 | */ |
11 | 11 | class Comment extends NodeGeneric |
12 | 12 | { |
13 | - public function specialProcess(NodeGeneric &$previous, array &$emptyLines):bool |
|
13 | + public function specialProcess(NodeGeneric&$previous, array &$emptyLines):bool |
|
14 | 14 | { |
15 | 15 | $previous->getRoot()->add($this); |
16 | 16 | return true; |
@@ -18,7 +18,7 @@ |
||
18 | 18 | public function __construct(string $nodeString, int $line) |
19 | 19 | { |
20 | 20 | parent::__construct($nodeString, $line); |
21 | - preg_match_all(Regex::SEQUENCE_VALUES, trim(substr(trim($nodeString), 1,-1)), $matches); |
|
21 | + preg_match_all(Regex::SEQUENCE_VALUES, trim(substr(trim($nodeString), 1, -1)), $matches); |
|
22 | 22 | foreach ($matches['item'] as $key => $item) { |
23 | 23 | $i = new Item('', $line); |
24 | 24 | $i->indent = null; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | |
156 | - /** |
|
156 | + /** |
|
157 | 157 | * Find parent target when current Node indentation is lesser than previous node indentation |
158 | 158 | * |
159 | 159 | * @param NodeGeneric $node |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | return $this->getParent(); |
190 | 190 | } |
191 | 191 | |
192 | - /** |
|
192 | + /** |
|
193 | 193 | * Find parent target when current Node indentation is superior than previous node indentation |
194 | 194 | * |
195 | 195 | * @param NodeGeneric $node |
@@ -226,7 +226,9 @@ discard block |
||
226 | 226 | { |
227 | 227 | foreach ($classNameList as $className) { |
228 | 228 | $fqn = __NAMESPACE__."\\$className"; |
229 | - if ($this instanceof $fqn) return true; |
|
229 | + if ($this instanceof $fqn) { |
|
230 | + return true; |
|
231 | + } |
|
230 | 232 | } |
231 | 233 | return false; |
232 | 234 | } |
@@ -240,13 +242,23 @@ discard block |
||
240 | 242 | { |
241 | 243 | $props = []; |
242 | 244 | $props['line->indent'] = "$this->line -> $this->indent"; |
243 | - if ($this->identifier) $props['identifier'] = "($this->identifier)"; |
|
244 | - if ($this->anchor) $props['anchor'] = "($this->anchor)"; |
|
245 | - if ($this->tag) $props['tag'] = "($this->tag)"; |
|
246 | - if ($this->value) $props['value'] = $this->value; |
|
245 | + if ($this->identifier) { |
|
246 | + $props['identifier'] = "($this->identifier)"; |
|
247 | + } |
|
248 | + if ($this->anchor) { |
|
249 | + $props['anchor'] = "($this->anchor)"; |
|
250 | + } |
|
251 | + if ($this->tag) { |
|
252 | + $props['tag'] = "($this->tag)"; |
|
253 | + } |
|
254 | + if ($this->value) { |
|
255 | + $props['value'] = $this->value; |
|
256 | + } |
|
247 | 257 | // $props['value'] = $this->value; |
248 | 258 | $props['raw'] = $this->raw; |
249 | - if (!$this->_parent) $props['parent'] = 'NO PARENT!!!'; |
|
259 | + if (!$this->_parent) { |
|
260 | + $props['parent'] = 'NO PARENT!!!'; |
|
261 | + } |
|
250 | 262 | return $props; |
251 | 263 | } |
252 | 264 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function getParent(int $indent = null):NodeGeneric |
73 | 73 | { |
74 | - if (!is_int($indent)){ |
|
74 | + if (!is_int($indent)) { |
|
75 | 75 | if ($this->_parent instanceof NodeGeneric) { |
76 | 76 | return $this->_parent; |
77 | 77 | } else { |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | return $cursor; |
153 | 153 | } |
154 | 154 | |
155 | - public function specialProcess(/** @scrutinizer ignore-unused */ NodeGeneric &$previous, /** @scrutinizer ignore-unused */ array &$emptyLines):bool |
|
155 | + public function specialProcess(/** @scrutinizer ignore-unused */ NodeGeneric&$previous, /** @scrutinizer ignore-unused */ array &$emptyLines):bool |
|
156 | 156 | { |
157 | 157 | return false; |
158 | 158 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @return NodeGeneric|Key |
166 | 166 | */ |
167 | - public function getTargetOnLessIndent(NodeGeneric &$node):NodeGeneric |
|
167 | + public function getTargetOnLessIndent(NodeGeneric&$node):NodeGeneric |
|
168 | 168 | { |
169 | 169 | $supposedParent = $this->getParent($node->indent); |
170 | 170 | if ($node instanceof Item && $supposedParent instanceof Root) { |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * |
190 | 190 | * @return NodeGeneric |
191 | 191 | */ |
192 | - public function getTargetOnEqualIndent(NodeGeneric &$node):NodeGeneric |
|
192 | + public function getTargetOnEqualIndent(NodeGeneric&$node):NodeGeneric |
|
193 | 193 | { |
194 | 194 | return $this->getParent(); |
195 | 195 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @return NodeGeneric |
203 | 203 | */ |
204 | - public function getTargetOnMoreIndent(NodeGeneric &$node):NodeGeneric |
|
204 | + public function getTargetOnMoreIndent(NodeGeneric&$node):NodeGeneric |
|
205 | 205 | { |
206 | 206 | return $this->isAwaitingChild($node) ? $this : $this->getParent(); |
207 | 207 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | if ($this->tag) $props['tag'] = "($this->tag)"; |
251 | 251 | if ($this->value) $props['value'] = $this->value; |
252 | 252 | // $props['value'] = $this->value; |
253 | - $props['raw'] = $this->raw; |
|
253 | + $props['raw'] = $this->raw; |
|
254 | 254 | if (!$this->_parent) $props['parent'] = 'NO PARENT!!!'; |
255 | 255 | return $props; |
256 | 256 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | $result = ''; |
18 | 18 | $list = $list->filterComment(); |
19 | 19 | if ($this->identifier !== '+') { |
20 | - self::litteralStripTrailing($list); |
|
20 | + self::litteralStripTrailing($list); |
|
21 | 21 | } |
22 | 22 | if ($list->count()) { |
23 | 23 | $list->setIteratorMode(NodeList::IT_MODE_DELETE); |
@@ -29,7 +29,7 @@ |
||
29 | 29 | public function build(&$parent = null) |
30 | 30 | { |
31 | 31 | $built = is_null($this->value) ? null : $this->value->build(); |
32 | - $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
|
32 | + $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built; |
|
33 | 33 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
34 | 34 | if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
35 | 35 | $parent->{trim($key, '\'" ')} = null; |
@@ -34,7 +34,9 @@ |
||
34 | 34 | $built = is_null($this->value) ? null : $this->value->build(); |
35 | 35 | $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
36 | 36 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
37 | - if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
|
37 | + if (empty($key)) { |
|
38 | + throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
|
39 | + } |
|
38 | 40 | $parent->{trim($key, '\'" ')} = null; |
39 | 41 | return null; |
40 | 42 | } |
@@ -21,8 +21,8 @@ |
||
21 | 21 | $result = ''; |
22 | 22 | $list = $value->filterComment(); |
23 | 23 | if ($this->identifier !== '+') { |
24 | - self::litteralStripLeading($list); |
|
25 | - self::litteralStripTrailing($list); |
|
24 | + self::litteralStripLeading($list); |
|
25 | + self::litteralStripTrailing($list); |
|
26 | 26 | } |
27 | 27 | if ($list->count()) { |
28 | 28 | $refSeparator = ' '; |
@@ -31,10 +31,10 @@ |
||
31 | 31 | $result = $this->getChildValue($first, $indent); |
32 | 32 | foreach ($list as $child) { |
33 | 33 | $separator = ($result && $result[-1] === "\n") ? '' : $refSeparator; |
34 | - if($child->indent > $indent || $child instanceof Blank) { |
|
34 | + if ($child->indent > $indent || $child instanceof Blank) { |
|
35 | 35 | $separator = "\n"; |
36 | 36 | } |
37 | - $result .= $separator .$this->getChildValue($child, $indent); |
|
37 | + $result .= $separator.$this->getChildValue($child, $indent); |
|
38 | 38 | } |
39 | 39 | } |
40 | 40 | return $result; |