@@ -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(ltrim($nodeString), 1,-1)), $matches); |
|
16 | + preg_match_all(Regex::MAPPING_VALUES, trim(substr(ltrim($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); |
@@ -27,7 +27,7 @@ |
||
27 | 27 | public function setIdentifier(string $keyString) |
28 | 28 | { |
29 | 29 | if ($keyString === '') { |
30 | - throw new \ParseError(sprintf(self::ERROR_NO_KEYNAME, $this->line)); |
|
30 | + throw new \ParseError(sprintf(self::ERROR_NO_KEYNAME, $this->line)); |
|
31 | 31 | } else { |
32 | 32 | $keyNode = NodeFactory::get($keyString); |
33 | 33 | if (!is_null($keyNode->_anchor)) { |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | public function add(Node $child):Node |
46 | 46 | { |
47 | - if ($this->value instanceof Node && isOneOf($this->value, ['NodeLit','NodeLitFolded', 'NodeAnchor'])) { |
|
47 | + if ($this->value instanceof Node && isOneOf($this->value, ['NodeLit', 'NodeLitFolded', 'NodeAnchor'])) { |
|
48 | 48 | return $this->value->add($child); |
49 | 49 | } else { |
50 | 50 | return parent::add($child); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | if ($current instanceof NodeComment) { |
80 | 80 | return true; |
81 | 81 | } |
82 | - if($current instanceof NodeScalar) { |
|
82 | + if ($current instanceof NodeScalar) { |
|
83 | 83 | return isOneOf($node, ['NodeScalar', 'NodeBlank']); |
84 | 84 | } |
85 | 85 | if ($current instanceof NodeItem) { |
@@ -23,7 +23,7 @@ |
||
23 | 23 | $list = $value->filterComment(); |
24 | 24 | if (!is_null($list) && $list->count()) { |
25 | 25 | if ($this->identifier !== '+') { |
26 | - self::litteralStripTrailing($list); |
|
26 | + self::litteralStripTrailing($list); |
|
27 | 27 | } |
28 | 28 | $list->setIteratorMode(NodeList::IT_MODE_DELETE); |
29 | 29 | $first = $list->shift(); |
@@ -12,6 +12,6 @@ |
||
12 | 12 | { |
13 | 13 | public function build(&$parent = null) |
14 | 14 | { |
15 | - return substr(trim($this->raw), 1,-1); |
|
15 | + return substr(trim($this->raw), 1, -1); |
|
16 | 16 | } |
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -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; |
@@ -31,7 +31,9 @@ |
||
31 | 31 | $built = is_null($this->value) ? null : $this->value->build(); |
32 | 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 | - if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
|
34 | + if (empty($key)) { |
|
35 | + throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
|
36 | + } |
|
35 | 37 | $parent->{trim($key, '\'" ')} = null; |
36 | 38 | } |
37 | 39 |
@@ -43,7 +43,7 @@ |
||
43 | 43 | |
44 | 44 | public function getTargetOnLessIndent(Node &$node):Node |
45 | 45 | { |
46 | - if ($node instanceof NodeScalar || $node instanceof NodeBlank ) { |
|
46 | + if ($node instanceof NodeScalar || $node instanceof NodeBlank) { |
|
47 | 47 | return $this->getParent(); |
48 | 48 | } else { |
49 | 49 | return $this->getParent($node->indent); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | return false; |
131 | 131 | } |
132 | 132 | |
133 | - /** |
|
133 | + /** |
|
134 | 134 | * Find parent target when current Node indentation is lesser than previous node indentation |
135 | 135 | * |
136 | 136 | * @param Node $previous The previous |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | return $this->getParent(); |
167 | 167 | } |
168 | 168 | |
169 | - /** |
|
169 | + /** |
|
170 | 170 | * Find parent target when current Node indentation is superior than previous node indentation |
171 | 171 | * |
172 | 172 | * @param Node $previous The previous |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function getParent(int $indent = null):Node |
67 | 67 | { |
68 | - if (!is_int($indent)){ |
|
68 | + if (!is_int($indent)) { |
|
69 | 69 | if ($this->_parent instanceof Node) { |
70 | 70 | return $this->_parent; |
71 | 71 | } else { |
@@ -213,9 +213,9 @@ discard block |
||
213 | 213 | if ($this->identifier) $props['identifier'] = "($this->identifier)"; |
214 | 214 | if ($this->_anchor) $props['_anchor'] = "($this->_anchor)"; |
215 | 215 | if ($this->_tag) $props['_tag'] = "($this->_tag)"; |
216 | - if ($this->value) $props['value'] = $this->value; |
|
216 | + if ($this->value) $props['value'] = $this->value; |
|
217 | 217 | // $props['value'] = $this->value; |
218 | - $props['raw'] = $this->raw; |
|
218 | + $props['raw'] = $this->raw; |
|
219 | 219 | if (!$this->_parent) $props['parent'] = 'NO PARENT!!!'; |
220 | 220 | return $props; |
221 | 221 | } |
@@ -210,13 +210,23 @@ |
||
210 | 210 | { |
211 | 211 | $props = []; |
212 | 212 | $props['line->indent'] = "$this->line -> $this->indent"; |
213 | - if ($this->identifier) $props['identifier'] = "($this->identifier)"; |
|
214 | - if ($this->_anchor) $props['_anchor'] = "($this->_anchor)"; |
|
215 | - if ($this->_tag) $props['_tag'] = "($this->_tag)"; |
|
216 | - if ($this->value) $props['value'] = $this->value; |
|
213 | + if ($this->identifier) { |
|
214 | + $props['identifier'] = "($this->identifier)"; |
|
215 | + } |
|
216 | + if ($this->_anchor) { |
|
217 | + $props['_anchor'] = "($this->_anchor)"; |
|
218 | + } |
|
219 | + if ($this->_tag) { |
|
220 | + $props['_tag'] = "($this->_tag)"; |
|
221 | + } |
|
222 | + if ($this->value) { |
|
223 | + $props['value'] = $this->value; |
|
224 | + } |
|
217 | 225 | // $props['value'] = $this->value; |
218 | 226 | $props['raw'] = $this->raw; |
219 | - if (!$this->_parent) $props['parent'] = 'NO PARENT!!!'; |
|
227 | + if (!$this->_parent) { |
|
228 | + $props['parent'] = 'NO PARENT!!!'; |
|
229 | + } |
|
220 | 230 | return $props; |
221 | 231 | } |
222 | 232 | } |
@@ -69,7 +69,7 @@ |
||
69 | 69 | return $this->_anchors[$name]; |
70 | 70 | } |
71 | 71 | throw new \UnexpectedValueException(sprintf(self::UNKNOWN_REFERENCE, |
72 | - $name, implode(',',array_keys($this->_anchors))) |
|
72 | + $name, implode(',', array_keys($this->_anchors))) |
|
73 | 73 | ); |
74 | 74 | } |
75 | 75 |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | elseif (preg_match(Regex::KEY, $trimmed, $matches)) return new NodeKey($nodeString, $line, $matches); |
22 | 22 | else { |
23 | 23 | $first = $trimmed[0]; |
24 | - $stringGroups = ["-" ,'>|' ,'"\'',"#%" ,"{[" ,":?" ,'*&!']; |
|
25 | - $methodGroups = ['Hyphen','Literal','Quoted','Special','Compact','SetElement','NodeAction']; |
|
24 | + $stringGroups = ["-", '>|', '"\'', "#%", "{[", ":?", '*&!']; |
|
25 | + $methodGroups = ['Hyphen', 'Literal', 'Quoted', 'Special', 'Compact', 'SetElement', 'NodeAction']; |
|
26 | 26 | foreach ($stringGroups as $groupIndex => $stringRef) { |
27 | 27 | if (is_int(strpos($stringRef, $first))) { |
28 | 28 | $methodName = 'on'.$methodGroups[$groupIndex]; |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | if (!preg_match(Regex::NODE_ACTIONS, ltrim($nodeString), $matches)) { |
128 | 128 | return new NodeScalar($nodeString, $line); |
129 | 129 | } |
130 | - $action = trim($matches['action']);//var_dump($matches); |
|
130 | + $action = trim($matches['action']); //var_dump($matches); |
|
131 | 131 | switch ($action[0]) { |
132 | - case '!': return new NodeTag ($nodeString, $line); |
|
132 | + case '!': return new NodeTag($nodeString, $line); |
|
133 | 133 | case '&': return new NodeAnchor($nodeString, $line); |
134 | 134 | case '*': return new NodeAnchor($nodeString, $line); |
135 | 135 | default: |
@@ -16,10 +16,13 @@ discard block |
||
16 | 16 | final public static function get($nodeString = null, $line = 0):Node |
17 | 17 | { |
18 | 18 | $trimmed = ltrim($nodeString); |
19 | - if ($trimmed === '') return new NodeBlank($nodeString, $line); |
|
20 | - elseif (substr($trimmed, 0, 3) === '...') return new NodeDocEnd($nodeString, $line); |
|
21 | - elseif (preg_match(Regex::KEY, $trimmed, $matches)) return new NodeKey($nodeString, $line, $matches); |
|
22 | - else { |
|
19 | + if ($trimmed === '') { |
|
20 | + return new NodeBlank($nodeString, $line); |
|
21 | + } elseif (substr($trimmed, 0, 3) === '...') { |
|
22 | + return new NodeDocEnd($nodeString, $line); |
|
23 | + } elseif (preg_match(Regex::KEY, $trimmed, $matches)) { |
|
24 | + return new NodeKey($nodeString, $line, $matches); |
|
25 | + } else { |
|
23 | 26 | $first = $trimmed[0]; |
24 | 27 | $stringGroups = ["-" ,'>|' ,'"\'',"#%" ,"{[" ,":?" ,'*&!']; |
25 | 28 | $methodGroups = ['Hyphen','Literal','Quoted','Special','Compact','SetElement','NodeAction']; |
@@ -90,10 +93,13 @@ discard block |
||
90 | 93 | final private static function onCompact(string $first, string $nodeString, int $line):Node |
91 | 94 | { |
92 | 95 | json_decode($nodeString, false, 512, self::JSON_OPTIONS); |
93 | - if (json_last_error() === \JSON_ERROR_NONE) return new NodeJSON($nodeString, $line); |
|
94 | - elseif (preg_match(Regex::MAPPING, trim($nodeString))) return new NodeCompactMapping($nodeString, $line); |
|
95 | - elseif (preg_match(Regex::SEQUENCE, trim($nodeString))) return new NodeCompactSequence($nodeString, $line); |
|
96 | - else { |
|
96 | + if (json_last_error() === \JSON_ERROR_NONE) { |
|
97 | + return new NodeJSON($nodeString, $line); |
|
98 | + } elseif (preg_match(Regex::MAPPING, trim($nodeString))) { |
|
99 | + return new NodeCompactMapping($nodeString, $line); |
|
100 | + } elseif (preg_match(Regex::SEQUENCE, trim($nodeString))) { |
|
101 | + return new NodeCompactSequence($nodeString, $line); |
|
102 | + } else { |
|
97 | 103 | return new NodePartial($nodeString, $line); |
98 | 104 | } |
99 | 105 | } |
@@ -108,9 +114,11 @@ discard block |
||
108 | 114 | */ |
109 | 115 | final private static function onHyphen(string $first, string $nodeString, int $line):Node |
110 | 116 | { |
111 | - if (substr($nodeString, 0, 3) === '---') return new NodeDocStart($nodeString, $line); |
|
112 | - elseif (preg_match(Regex::ITEM, ltrim($nodeString))) return new NodeItem($nodeString, $line); |
|
113 | - else { |
|
117 | + if (substr($nodeString, 0, 3) === '---') { |
|
118 | + return new NodeDocStart($nodeString, $line); |
|
119 | + } elseif (preg_match(Regex::ITEM, ltrim($nodeString))) { |
|
120 | + return new NodeItem($nodeString, $line); |
|
121 | + } else { |
|
114 | 122 | return new NodeScalar($nodeString, $line); |
115 | 123 | } |
116 | 124 | } |