@@ -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 |
@@ -203,9 +203,9 @@ |
||
| 203 | 203 | if ($this->identifier) $props['identifier'] = "($this->identifier)"; |
| 204 | 204 | if ($this->_anchor) $props['_anchor'] = "($this->_anchor)"; |
| 205 | 205 | if ($this->_tag) $props['_tag'] = "($this->_tag)"; |
| 206 | - if ($this->value) $props['value'] = $this->value; |
|
| 206 | + if ($this->value) $props['value'] = $this->value; |
|
| 207 | 207 | // $props['value'] = $this->value; |
| 208 | - $props['raw'] = $this->raw; |
|
| 208 | + $props['raw'] = $this->raw; |
|
| 209 | 209 | if (!$this->_parent) $props['parent'] = 'NO PARENT!!!'; |
| 210 | 210 | return $props; |
| 211 | 211 | } |
@@ -65,7 +65,9 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function getParent(int $indent = null):Node |
| 67 | 67 | { |
| 68 | - if (!is_int($indent)) return $this->_parent; |
|
| 68 | + if (!is_int($indent)) { |
|
| 69 | + return $this->_parent; |
|
| 70 | + } |
|
| 69 | 71 | $cursor = $this->getParent(); |
| 70 | 72 | while (!($cursor instanceof NodeRoot) |
| 71 | 73 | && (is_null($cursor->indent) |
@@ -200,13 +202,23 @@ discard block |
||
| 200 | 202 | { |
| 201 | 203 | $props = []; |
| 202 | 204 | $props['line->indent'] = "$this->line -> $this->indent"; |
| 203 | - if ($this->identifier) $props['identifier'] = "($this->identifier)"; |
|
| 204 | - if ($this->_anchor) $props['_anchor'] = "($this->_anchor)"; |
|
| 205 | - if ($this->_tag) $props['_tag'] = "($this->_tag)"; |
|
| 206 | - if ($this->value) $props['value'] = $this->value; |
|
| 205 | + if ($this->identifier) { |
|
| 206 | + $props['identifier'] = "($this->identifier)"; |
|
| 207 | + } |
|
| 208 | + if ($this->_anchor) { |
|
| 209 | + $props['_anchor'] = "($this->_anchor)"; |
|
| 210 | + } |
|
| 211 | + if ($this->_tag) { |
|
| 212 | + $props['_tag'] = "($this->_tag)"; |
|
| 213 | + } |
|
| 214 | + if ($this->value) { |
|
| 215 | + $props['value'] = $this->value; |
|
| 216 | + } |
|
| 207 | 217 | // $props['value'] = $this->value; |
| 208 | 218 | $props['raw'] = $this->raw; |
| 209 | - if (!$this->_parent) $props['parent'] = 'NO PARENT!!!'; |
|
| 219 | + if (!$this->_parent) { |
|
| 220 | + $props['parent'] = 'NO PARENT!!!'; |
|
| 221 | + } |
|
| 210 | 222 | return $props; |
| 211 | 223 | } |
| 212 | 224 | } |
@@ -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 = 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 | } |