@@ -84,9 +84,13 @@ discard block |
||
| 84 | 84 | public function parse($strContent = null) |
| 85 | 85 | { |
| 86 | 86 | $source = $this->content; |
| 87 | - if (is_null($source)) $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE); |
|
| 87 | + if (is_null($source)) { |
|
| 88 | + $source = preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE); |
|
| 89 | + } |
|
| 88 | 90 | //TODO : be more permissive on $strContent values |
| 89 | - if (!is_array($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT); |
|
| 91 | + if (!is_array($source)) { |
|
| 92 | + throw new \Exception(self::EXCEPTION_LINE_SPLIT); |
|
| 93 | + } |
|
| 90 | 94 | $previous = $root = new Node(); |
| 91 | 95 | $emptyLines = []; |
| 92 | 96 | $specialTypes = Y\LITTERALS|Y\BLANK; |
@@ -115,7 +119,9 @@ discard block |
||
| 115 | 119 | case -1: $previous->getParent($n->indent)->add($n);break; |
| 116 | 120 | case 0: $previous->getParent()->add($n);break; |
| 117 | 121 | default: |
| 118 | - if ($this->onDeepestType($n, $previous, $lineString)) continue 2; |
|
| 122 | + if ($this->onDeepestType($n, $previous, $lineString)) { |
|
| 123 | + continue 2; |
|
| 124 | + } |
|
| 119 | 125 | $previous->add($n); |
| 120 | 126 | } |
| 121 | 127 | $previous = $n; |
@@ -155,8 +161,12 @@ discard block |
||
| 155 | 161 | } |
| 156 | 162 | } |
| 157 | 163 | if ($n->type & Y\BLANK) { |
| 158 | - if ($previous->type & Y\SCALAR) $emptyLines[] = $n->setParent($previous->getParent()); |
|
| 159 | - if ($deepest->type & Y\LITTERALS) $emptyLines[] = $n->setParent($deepest); |
|
| 164 | + if ($previous->type & Y\SCALAR) { |
|
| 165 | + $emptyLines[] = $n->setParent($previous->getParent()); |
|
| 166 | + } |
|
| 167 | + if ($deepest->type & Y\LITTERALS) { |
|
| 168 | + $emptyLines[] = $n->setParent($deepest); |
|
| 169 | + } |
|
| 160 | 170 | return true; |
| 161 | 171 | } |
| 162 | 172 | return false; |
@@ -22,7 +22,9 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | private static function build(object $node, &$parent = null) |
| 24 | 24 | { |
| 25 | - if ($node instanceof NodeList) return self::buildNodeList($node, $parent); |
|
| 25 | + if ($node instanceof NodeList) { |
|
| 26 | + return self::buildNodeList($node, $parent); |
|
| 27 | + } |
|
| 26 | 28 | return self::buildNode($node, $parent); |
| 27 | 29 | } |
| 28 | 30 | |
@@ -74,12 +76,15 @@ discard block |
||
| 74 | 76 | $tmp = $node->getPhpValue(); |
| 75 | 77 | } |
| 76 | 78 | // $tmp = is_object($value) ? self::build($value, $parent) : $node->getPhpValue(); |
| 77 | - if ($type === Y\REF_DEF) self::$_root->addReference($identifier, $tmp); |
|
| 79 | + if ($type === Y\REF_DEF) { |
|
| 80 | + self::$_root->addReference($identifier, $tmp); |
|
| 81 | + } |
|
| 78 | 82 | return self::$_root->getReference($identifier); |
| 79 | 83 | case Y\SET_KEY: |
| 80 | 84 | $key = json_encode(self::build($value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
| 81 | - if (empty($key)) |
|
| 82 | - throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1); |
|
| 85 | + if (empty($key)) { |
|
| 86 | + throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1); |
|
| 87 | + } |
|
| 83 | 88 | $parent->{$key} = null; |
| 84 | 89 | return; |
| 85 | 90 | case Y\SET_VALUE: |
@@ -98,8 +103,11 @@ discard block |
||
| 98 | 103 | $parent->addTag($identifier); return; |
| 99 | 104 | } else {//TODO: have somewhere a list of common tags and their treatment |
| 100 | 105 | if (in_array($identifier, ['!binary', '!str'])) { |
| 101 | - if ($value->value instanceof NodeList) $value->value->type = Y\RAW; |
|
| 102 | - else $value->type = Y\RAW; |
|
| 106 | + if ($value->value instanceof NodeList) { |
|
| 107 | + $value->value->type = Y\RAW; |
|
| 108 | + } else { |
|
| 109 | + $value->type = Y\RAW; |
|
| 110 | + } |
|
| 103 | 111 | } |
| 104 | 112 | $val = is_null($value) ? null : self::build(/** @scrutinizer ignore-type */ $value, $node); |
| 105 | 113 | return new Tag($identifier, $val); |
@@ -168,10 +176,14 @@ discard block |
||
| 168 | 176 | } |
| 169 | 177 | $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE); |
| 170 | 178 | foreach ($_root->value as $child) { |
| 171 | - if ($child->type & Y\DOC_START) $totalDocStart++; |
|
| 179 | + if ($child->type & Y\DOC_START) { |
|
| 180 | + $totalDocStart++; |
|
| 181 | + } |
|
| 172 | 182 | //if 0 or 1 DOC_START = we are still in first document |
| 173 | 183 | $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0; |
| 174 | - if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList(); |
|
| 184 | + if (!isset($documents[$currentDoc])) { |
|
| 185 | + $documents[$currentDoc] = new NodeList(); |
|
| 186 | + } |
|
| 175 | 187 | $documents[$currentDoc]->push($child); |
| 176 | 188 | } |
| 177 | 189 | $content = array_map([self::class, 'buildDocument'], $documents, array_keys($documents)); |