@@ -2,7 +2,7 @@ |
||
| 2 | 2 | namespace Dallgoot\Yaml; |
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | - * The returned object representing a YAML file content |
|
| 5 | + * The returned object representing a YAML file content |
|
| 6 | 6 | * @category tag in class comment |
| 7 | 7 | * @package tag in class comment |
| 8 | 8 | * @author tag in class comment |
@@ -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 | |
@@ -64,12 +66,15 @@ discard block |
||
| 64 | 66 | case Y\REF_DEF: //fall through |
| 65 | 67 | case Y\REF_CALL://TODO: self::build returns what ? |
| 66 | 68 | $tmp = is_object($value) ? self::build($value, $parent) : $node->getPhpValue(); |
| 67 | - if ($type === Y\REF_DEF) self::$_root->addReference($identifier, $tmp); |
|
| 69 | + if ($type === Y\REF_DEF) { |
|
| 70 | + self::$_root->addReference($identifier, $tmp); |
|
| 71 | + } |
|
| 68 | 72 | return self::$_root->getReference($identifier); |
| 69 | 73 | case Y\SET_KEY: |
| 70 | 74 | $key = json_encode(self::build($value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
| 71 | - if (empty($key)) |
|
| 72 | - throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1); |
|
| 75 | + if (empty($key)) { |
|
| 76 | + throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1); |
|
| 77 | + } |
|
| 73 | 78 | $parent->{$key} = null; |
| 74 | 79 | return; |
| 75 | 80 | case Y\SET_VALUE: |
@@ -88,8 +93,11 @@ discard block |
||
| 88 | 93 | $parent->addTag($identifier); return; |
| 89 | 94 | } else {//TODO: have somewhere a list of common tags and their treatment |
| 90 | 95 | if (in_array($identifier, ['!binary', '!str'])) { |
| 91 | - if ($value->value instanceof NodeList) $value->value->type = Y\RAW; |
|
| 92 | - else $value->type = Y\RAW; |
|
| 96 | + if ($value->value instanceof NodeList) { |
|
| 97 | + $value->value->type = Y\RAW; |
|
| 98 | + } else { |
|
| 99 | + $value->type = Y\RAW; |
|
| 100 | + } |
|
| 93 | 101 | } |
| 94 | 102 | $val = is_null($value) ? null : self::build(/** @scrutinizer ignore-type */ $value, $node); |
| 95 | 103 | return new Tag($identifier, $val); |
@@ -158,10 +166,14 @@ discard block |
||
| 158 | 166 | } |
| 159 | 167 | $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE); |
| 160 | 168 | foreach ($_root->value as $child) { |
| 161 | - if ($child->type & Y\DOC_START) $totalDocStart++; |
|
| 169 | + if ($child->type & Y\DOC_START) { |
|
| 170 | + $totalDocStart++; |
|
| 171 | + } |
|
| 162 | 172 | //if 0 or 1 DOC_START = we are still in first document |
| 163 | 173 | $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0; |
| 164 | - if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList(); |
|
| 174 | + if (!isset($documents[$currentDoc])) { |
|
| 175 | + $documents[$currentDoc] = new NodeList(); |
|
| 176 | + } |
|
| 165 | 177 | $documents[$currentDoc]->push($child); |
| 166 | 178 | } |
| 167 | 179 | // $_debug >= 2 && var_dump($documents);//var_dump($documents);die("documents"); |
@@ -17,17 +17,17 @@ discard block |
||
| 17 | 17 | //public |
| 18 | 18 | public $errors = []; |
| 19 | 19 | |
| 20 | - public const EXCLUDE_DIRECTIVES = 1;//DONT include_directive |
|
| 21 | - public const IGNORE_COMMENTS = 2;//DONT include_comments |
|
| 22 | - public const NO_PARSING_EXCEPTIONS = 4;//THROW Exception on parsing Errors |
|
| 23 | - public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object |
|
| 20 | + public const EXCLUDE_DIRECTIVES = 1; //DONT include_directive |
|
| 21 | + public const IGNORE_COMMENTS = 2; //DONT include_comments |
|
| 22 | + public const NO_PARSING_EXCEPTIONS = 4; //THROW Exception on parsing Errors |
|
| 23 | + public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object |
|
| 24 | 24 | //privates |
| 25 | 25 | /* @var null|string */ |
| 26 | 26 | private $content; |
| 27 | 27 | /* @var null|string */ |
| 28 | 28 | private $filePath; |
| 29 | 29 | /* @var integer */ |
| 30 | - private $debug = 0;///TODO: determine levels |
|
| 30 | + private $debug = 0; ///TODO: determine levels |
|
| 31 | 31 | /* @var integer */ |
| 32 | 32 | private $options = 0; |
| 33 | 33 | //Exceptions messages |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | $emptyLines = []; |
| 114 | 114 | switch ($n->indent <=> $previous->indent) { |
| 115 | - case -1: $previous->getParent($n->indent)->add($n);break; |
|
| 116 | - case 0: $previous->getParent()->add($n);break; |
|
| 115 | + case -1: $previous->getParent($n->indent)->add($n); break; |
|
| 116 | + case 0: $previous->getParent()->add($n); break; |
|
| 117 | 117 | default: |
| 118 | 118 | if ($this->onDeepestType($n, $previous, $lineString)) continue 2; |
| 119 | 119 | $previous->add($n); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | // // if ($previous->type & Y\ITEM && $n->type & Y\KEY) { |
| 177 | 177 | // // $previous |
| 178 | 178 | // // } |
| 179 | - if ($deepest->type & (Y\BLANK | Y\SCALAR)) {//|| ($previous->type & (Y\ITEM | Y\SET_KEY))) { |
|
| 179 | + if ($deepest->type & (Y\BLANK|Y\SCALAR)) {//|| ($previous->type & (Y\ITEM | Y\SET_KEY))) { |
|
| 180 | 180 | $previous = $deepest->getParent(); |
| 181 | 181 | // // if ($n->type === Y\SCALAR && ($deepest->getParent()->type & Y\LITTERALS)) { |
| 182 | 182 | // // // $deepest->type = Y\SCALAR; |