@@ -25,8 +25,12 @@ |
||
| 25 | 25 | public function jsonSerialize():array |
| 26 | 26 | { |
| 27 | 27 | $prop = get_object_vars($this); |
| 28 | - if (count($prop) > 0) return $prop; |
|
| 29 | - if (count($this) > 0) return iterator_to_array($this); |
|
| 28 | + if (count($prop) > 0) { |
|
| 29 | + return $prop; |
|
| 30 | + } |
|
| 31 | + if (count($this) > 0) { |
|
| 32 | + return iterator_to_array($this); |
|
| 33 | + } |
|
| 30 | 34 | } |
| 31 | 35 | |
| 32 | 36 | /** |
@@ -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) { |
@@ -100,7 +104,7 @@ discard block |
||
| 100 | 104 | if (is_null($this->value)) { |
| 101 | 105 | $this->value = $child; |
| 102 | 106 | return; |
| 103 | - }elseif ($this->value instanceof Node) { |
|
| 107 | + } elseif ($this->value instanceof Node) { |
|
| 104 | 108 | if ($this->value->type & Y::LITTERALS) { |
| 105 | 109 | $type = $this->value->type; |
| 106 | 110 | $this->value = new NodeList(); |
@@ -168,12 +172,17 @@ discard block |
||
| 168 | 172 | { |
| 169 | 173 | $v = ltrim(substr($nodeValue, 1)); |
| 170 | 174 | $first = $nodeValue[0]; |
| 171 | - if ($first === "-") NodeHandlers::onHyphen($nodeValue, $this); |
|
| 172 | - elseif (in_array($first, ['"', "'"])) NodeHandlers::onQuoted($nodeValue, $this); |
|
| 173 | - elseif (in_array($first, ['{', '['])) NodeHandlers::onCompact($nodeValue, $this); |
|
| 174 | - elseif (in_array($first, ['?', ':'])) NodeHandlers::onSetElement($nodeValue, $this); |
|
| 175 | - elseif (in_array($first, ['!', '&', '*'])) NodeHandlers::onNodeAction($nodeValue, $this); |
|
| 176 | - else { |
|
| 175 | + if ($first === "-") { |
|
| 176 | + NodeHandlers::onHyphen($nodeValue, $this); |
|
| 177 | + } elseif (in_array($first, ['"', "'"])) { |
|
| 178 | + NodeHandlers::onQuoted($nodeValue, $this); |
|
| 179 | + } elseif (in_array($first, ['{', '['])) { |
|
| 180 | + NodeHandlers::onCompact($nodeValue, $this); |
|
| 181 | + } elseif (in_array($first, ['?', ':'])) { |
|
| 182 | + NodeHandlers::onSetElement($nodeValue, $this); |
|
| 183 | + } elseif (in_array($first, ['!', '&', '*'])) { |
|
| 184 | + NodeHandlers::onNodeAction($nodeValue, $this); |
|
| 185 | + } else { |
|
| 177 | 186 | $characters = [ '#' => [Y::COMMENT, $v], |
| 178 | 187 | '%' => [Y::DIRECTIVE, $v], |
| 179 | 188 | '>' => [Y::LITT_FOLDED, null], |
@@ -33,7 +33,9 @@ discard block |
||
| 33 | 33 | $totalDocStart = 0; |
| 34 | 34 | $documents = []; |
| 35 | 35 | $buffer = new NodeList(); |
| 36 | - if ($_root->value instanceof NddeList) $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE); |
|
| 36 | + if ($_root->value instanceof NddeList) { |
|
| 37 | + $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE); |
|
| 38 | + } |
|
| 37 | 39 | foreach ($_root->value as $child) { |
| 38 | 40 | if ($child->type & Y::DOC_START) { |
| 39 | 41 | if(++$totalDocStart > 1){ |
@@ -69,7 +71,9 @@ discard block |
||
| 69 | 71 | */ |
| 70 | 72 | public static function build(object $node, &$parent = null) |
| 71 | 73 | { |
| 72 | - if ($node instanceof NodeList) return self::buildNodeList($node, $parent); |
|
| 74 | + if ($node instanceof NodeList) { |
|
| 75 | + return self::buildNodeList($node, $parent); |
|
| 76 | + } |
|
| 73 | 77 | return self::buildNode($node, $parent); |
| 74 | 78 | } |
| 75 | 79 | |
@@ -163,7 +167,9 @@ discard block |
||
| 163 | 167 | $list->rewind(); |
| 164 | 168 | $refIndent = $list->current()->indent; |
| 165 | 169 | //remove trailing blank |
| 166 | - while ($list->top()->type & Y::BLANK) $list->pop(); |
|
| 170 | + while ($list->top()->type & Y::BLANK) { |
|
| 171 | + $list->pop(); |
|
| 172 | + } |
|
| 167 | 173 | $result = ''; |
| 168 | 174 | $separator = [ Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type]; |
| 169 | 175 | foreach ($list as $child) { |
@@ -180,10 +186,12 @@ discard block |
||
| 180 | 186 | { |
| 181 | 187 | $val = $child->type & (Y::SCALAR) ? $child->value : substr($child->raw, $refIndent); |
| 182 | 188 | if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
| 183 | - if ($result[-1] === $separator) |
|
| 184 | - $result[-1] = "\n"; |
|
| 185 | - if ($result[-1] === "\n") |
|
| 186 | - $result .= $val; |
|
| 189 | + if ($result[-1] === $separator) { |
|
| 190 | + $result[-1] = "\n"; |
|
| 191 | + } |
|
| 192 | + if ($result[-1] === "\n") { |
|
| 193 | + $result .= $val; |
|
| 194 | + } |
|
| 187 | 195 | return; |
| 188 | 196 | } |
| 189 | 197 | $result .= $val.$separator; |