@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | if ($_root->value instanceof NddeList) $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE); |
| 37 | 37 | foreach ($_root->value as $child) { |
| 38 | 38 | if ($child->type & Y::DOC_START) { |
| 39 | - if(++$totalDocStart > 1){ |
|
| 39 | + if (++$totalDocStart > 1) { |
|
| 40 | 40 | $documents[] = self::buildDocument($buffer, count($documents)); |
| 41 | 41 | $buffer = new NodeList($child); |
| 42 | 42 | } |
@@ -81,13 +81,13 @@ discard block |
||
| 81 | 81 | * |
| 82 | 82 | * @return mixed The parent (object|array) or a string representing the NodeList. |
| 83 | 83 | */ |
| 84 | - public static function buildNodeList(NodeList $node, &$parent=null) |
|
| 84 | + public static function buildNodeList(NodeList $node, &$parent = null) |
|
| 85 | 85 | { |
| 86 | 86 | $node->forceType(); |
| 87 | - if ($node->type & (Y::RAW | Y::LITTERALS)) { |
|
| 87 | + if ($node->type & (Y::RAW|Y::LITTERALS)) { |
|
| 88 | 88 | return self::buildLitteral($node, (int) $node->type); |
| 89 | 89 | } |
| 90 | - $action = function ($child, &$parent, &$out) { |
|
| 90 | + $action = function($child, &$parent, &$out) { |
|
| 91 | 91 | self::build($child, $out); |
| 92 | 92 | }; |
| 93 | 93 | if ($node->type & (Y::COMPACT_MAPPING|Y::MAPPING|Y::SET)) { |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $out = $parent ?? []; |
| 97 | 97 | } else { |
| 98 | 98 | $out = ''; |
| 99 | - $action = function ($child, &$parent, &$out) { |
|
| 99 | + $action = function($child, &$parent, &$out) { |
|
| 100 | 100 | if ($child->type & (Y::SCALAR|Y::QUOTED)) { |
| 101 | 101 | if ($parent) { |
| 102 | 102 | $parent->setText(self::build($child)); |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | ]; |
| 136 | 136 | if (isset($actions[$type])) { |
| 137 | 137 | return TB::{$actions[$type]}($node, $parent); |
| 138 | - } elseif ($type & Y::COMMENT) { |
|
| 138 | + } elseif ($type&Y::COMMENT) { |
|
| 139 | 139 | self::$_root->addComment($line, $value); |
| 140 | - } elseif ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) { |
|
| 140 | + } elseif ($type&(Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) { |
|
| 141 | 141 | return self::buildNodeList($value, $parent); |
| 142 | - } elseif ($type & (Y::REF_DEF | Y::REF_CALL)) { |
|
| 142 | + } elseif ($type&(Y::REF_DEF|Y::REF_CALL)) { |
|
| 143 | 143 | return TB::buildReference($node, $parent); |
| 144 | 144 | } elseif ($value instanceof Node) { |
| 145 | 145 | return self::buildNode($value, $parent); |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | //remove trailing blank |
| 166 | 166 | while ($list->top()->type & Y::BLANK) $list->pop(); |
| 167 | 167 | $result = ''; |
| 168 | - $separator = [ Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type]; |
|
| 168 | + $separator = [Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type]; |
|
| 169 | 169 | foreach ($list as $child) { |
| 170 | 170 | if ($child->value instanceof NodeList) { |
| 171 | 171 | $result .= self::buildLitteral($child->value, $type).$separator; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | private static function setLiteralValue(Node $child, string &$result, int $refIndent, string $separator, int $type) |
| 180 | 180 | { |
| 181 | 181 | $val = $child->type & (Y::SCALAR) ? $child->value : substr($child->raw, $refIndent); |
| 182 | - if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
| 182 | + if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
| 183 | 183 | if ($result[-1] === $separator) |
| 184 | 184 | $result[-1] = "\n"; |
| 185 | 185 | if ($result[-1] === "\n") |
@@ -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; |