@@ -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::SEQUENCE_VALUES, trim(substr(trim($nodeString), 1,-1)), $matches); |
|
| 16 | + preg_match_all(Regex::SEQUENCE_VALUES, trim(substr(trim($nodeString), 1, -1)), $matches); |
|
| 17 | 17 | foreach ($matches['item'] as $key => $item) { |
| 18 | 18 | $i = new NodeItem('', $line); |
| 19 | 19 | $i->indent = null; |
@@ -21,8 +21,8 @@ |
||
| 21 | 21 | $result = ''; |
| 22 | 22 | if ($list->count()) { |
| 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 | $first = $list->shift(); |
| 28 | 28 | $refIndent = $first->indent ?? 0; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $refSeparator = ' '; |
| 30 | 30 | $result = substr($first->raw, $first->indent); |
| 31 | 31 | foreach ($list as $child) { |
| 32 | - if($child->indent > $refIndent || ($child instanceof NodeBlank)) { |
|
| 32 | + if ($child->indent > $refIndent || ($child instanceof NodeBlank)) { |
|
| 33 | 33 | $separator = "\n"; |
| 34 | 34 | } else { |
| 35 | 35 | $separator = !empty($result) && $result[-1] === "\n" ? '' : $refSeparator; |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | $val = $child->build(); |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | - $result .= $separator .$val; |
|
| 45 | + $result .= $separator.$val; |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | return $result; |
@@ -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 | } |