@@ -74,8 +74,12 @@ |
||
| 74 | 74 | { |
| 75 | 75 | $prop = get_object_vars($this); |
| 76 | 76 | unset($prop["__yaml__object__api"]); |
| 77 | - if (count($prop) > 0) return $prop; |
|
| 78 | - if (count($this) > 0) return iterator_to_array($this); |
|
| 77 | + if (count($prop) > 0) { |
|
| 78 | + return $prop; |
|
| 79 | + } |
|
| 80 | + if (count($this) > 0) { |
|
| 81 | + return iterator_to_array($this); |
|
| 82 | + } |
|
| 79 | 83 | return $this->__yaml__object__api->value ?? "_Empty YamlObject_"; |
| 80 | 84 | } |
| 81 | 85 | } |
@@ -34,7 +34,9 @@ |
||
| 34 | 34 | $built = is_null($this->value) ? null : $this->value->build(); |
| 35 | 35 | $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
| 36 | 36 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
| 37 | - if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
|
| 37 | + if (empty($key)) { |
|
| 38 | + throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
|
| 39 | + } |
|
| 38 | 40 | $parent->{trim($key, '\'" ')} = null; |
| 39 | 41 | return null; |
| 40 | 42 | } |
@@ -226,7 +226,9 @@ discard block |
||
| 226 | 226 | { |
| 227 | 227 | foreach ($classNameList as $className) { |
| 228 | 228 | $fqn = __NAMESPACE__."\\$className"; |
| 229 | - if ($this instanceof $fqn) return true; |
|
| 229 | + if ($this instanceof $fqn) { |
|
| 230 | + return true; |
|
| 231 | + } |
|
| 230 | 232 | } |
| 231 | 233 | return false; |
| 232 | 234 | } |
@@ -240,13 +242,23 @@ discard block |
||
| 240 | 242 | { |
| 241 | 243 | $props = []; |
| 242 | 244 | $props['line->indent'] = "$this->line -> $this->indent"; |
| 243 | - if ($this->identifier) $props['identifier'] = "($this->identifier)"; |
|
| 244 | - if ($this->anchor) $props['anchor'] = "($this->anchor)"; |
|
| 245 | - if ($this->tag) $props['tag'] = "($this->tag)"; |
|
| 246 | - if ($this->value) $props['value'] = $this->value; |
|
| 245 | + if ($this->identifier) { |
|
| 246 | + $props['identifier'] = "($this->identifier)"; |
|
| 247 | + } |
|
| 248 | + if ($this->anchor) { |
|
| 249 | + $props['anchor'] = "($this->anchor)"; |
|
| 250 | + } |
|
| 251 | + if ($this->tag) { |
|
| 252 | + $props['tag'] = "($this->tag)"; |
|
| 253 | + } |
|
| 254 | + if ($this->value) { |
|
| 255 | + $props['value'] = $this->value; |
|
| 256 | + } |
|
| 247 | 257 | // $props['value'] = $this->value; |
| 248 | 258 | $props['raw'] = $this->raw; |
| 249 | - if (!$this->_parent) $props['parent'] = 'NO PARENT!!!'; |
|
| 259 | + if (!$this->_parent) { |
|
| 260 | + $props['parent'] = 'NO PARENT!!!'; |
|
| 261 | + } |
|
| 250 | 262 | return $props; |
| 251 | 263 | } |
| 252 | 264 | } |
@@ -32,7 +32,9 @@ |
||
| 32 | 32 | |
| 33 | 33 | public function add(NodeGeneric $child):NodeGeneric |
| 34 | 34 | { |
| 35 | - if (is_null($this->value)) $this->value = new NodeList(); |
|
| 35 | + if (is_null($this->value)) { |
|
| 36 | + $this->value = new NodeList(); |
|
| 37 | + } |
|
| 36 | 38 | $candidate = $child; |
| 37 | 39 | if (!$child->isOneOf('Scalar', 'Blank', 'Comment', 'Quoted')) { |
| 38 | 40 | $candidate = new Scalar((string) $child->raw, $child->line); |
@@ -22,8 +22,12 @@ |
||
| 22 | 22 | |
| 23 | 23 | public function dumpScalar($dataType):string |
| 24 | 24 | { |
| 25 | - if ($dataType === \INF) return '.inf'; |
|
| 26 | - if ($dataType === -\INF) return '-.inf'; |
|
| 25 | + if ($dataType === \INF) { |
|
| 26 | + return '.inf'; |
|
| 27 | + } |
|
| 28 | + if ($dataType === -\INF) { |
|
| 29 | + return '-.inf'; |
|
| 30 | + } |
|
| 27 | 31 | $precision = "%.".$this->dumper->floatPrecision."F"; |
| 28 | 32 | switch (gettype($dataType)) { |
| 29 | 33 | case 'boolean': return $dataType ? 'true' : 'false'; |
@@ -48,7 +48,9 @@ |
||
| 48 | 48 | */ |
| 49 | 49 | public function toString($dataType, int $options = null):string |
| 50 | 50 | { |
| 51 | - if (empty($dataType)) throw new \Exception(self::class.": No content to convert to Yaml"); |
|
| 51 | + if (empty($dataType)) { |
|
| 52 | + throw new \Exception(self::class.": No content to convert to Yaml"); |
|
| 53 | + } |
|
| 52 | 54 | if (is_scalar($dataType)) { |
| 53 | 55 | return "--- ".$this->handler->dumpScalar($dataType). self::LINEFEED ; |
| 54 | 56 | } |
@@ -97,8 +97,12 @@ discard block |
||
| 97 | 97 | \.nan | \.NaN | \.NAN tag:yaml.org,2002:float (Not a number) |
| 98 | 98 | * tag:yaml.org,2002:str (Default) |
| 99 | 99 | */ |
| 100 | - if (Regex::isDate($v)) return ($this->getRoot()->getYamlObject()->getOptions() & Loader::NO_OBJECT_FOR_DATE) && !$onlyScalar ? date_create($v) : $v; |
|
| 101 | - if (Regex::isNumber($v)) return $this->getNumber($v); |
|
| 100 | + if (Regex::isDate($v)) { |
|
| 101 | + return ($this->getRoot()->getYamlObject()->getOptions() & Loader::NO_OBJECT_FOR_DATE) && !$onlyScalar ? date_create($v) : $v; |
|
| 102 | + } |
|
| 103 | + if (Regex::isNumber($v)) { |
|
| 104 | + return $this->getNumber($v); |
|
| 105 | + } |
|
| 102 | 106 | $types = ['yes' => true, |
| 103 | 107 | 'no' => false, |
| 104 | 108 | 'true' => true, |
@@ -142,8 +146,12 @@ discard block |
||
| 142 | 146 | */ |
| 143 | 147 | private function getNumber(string $v) |
| 144 | 148 | { |
| 145 | - if ((bool) preg_match(Regex::OCTAL_NUM, $v)) return intval(base_convert($v, 8, 10)); |
|
| 146 | - if ((bool) preg_match(Regex::HEX_NUM, $v)) return intval(base_convert($v, 16, 10)); |
|
| 149 | + if ((bool) preg_match(Regex::OCTAL_NUM, $v)) { |
|
| 150 | + return intval(base_convert($v, 8, 10)); |
|
| 151 | + } |
|
| 152 | + if ((bool) preg_match(Regex::HEX_NUM, $v)) { |
|
| 153 | + return intval(base_convert($v, 16, 10)); |
|
| 154 | + } |
|
| 147 | 155 | return is_bool(strpos($v, '.')) || substr_count($v, '.') > 1 ? intval($v) : floatval($v); |
| 148 | 156 | } |
| 149 | 157 | |
@@ -23,10 +23,13 @@ discard block |
||
| 23 | 23 | final public static function get($nodeString = null, $line = 0):NodeGeneric |
| 24 | 24 | { |
| 25 | 25 | $trimmed = ltrim($nodeString); |
| 26 | - if ($trimmed === '') return new Nodes\Blank($nodeString, $line); |
|
| 27 | - elseif (substr($trimmed, 0, 3) === '...') return new Nodes\DocEnd($nodeString, $line); |
|
| 28 | - elseif ((bool) preg_match(Regex::KEY, $trimmed, $matches)) return new Nodes\Key($nodeString, $line, $matches); |
|
| 29 | - else { |
|
| 26 | + if ($trimmed === '') { |
|
| 27 | + return new Nodes\Blank($nodeString, $line); |
|
| 28 | + } elseif (substr($trimmed, 0, 3) === '...') { |
|
| 29 | + return new Nodes\DocEnd($nodeString, $line); |
|
| 30 | + } elseif ((bool) preg_match(Regex::KEY, $trimmed, $matches)) { |
|
| 31 | + return new Nodes\Key($nodeString, $line, $matches); |
|
| 32 | + } else { |
|
| 30 | 33 | $first = $trimmed[0]; |
| 31 | 34 | $stringGroups = ['-', '>|' , '"\'', "#%" , "{[" , ":?" , '*&!']; |
| 32 | 35 | $methodGroups = ['Hyphen','Literal','Quoted','Special','Compact','SetElement','NodeAction']; |
@@ -137,9 +140,11 @@ discard block |
||
| 137 | 140 | */ |
| 138 | 141 | final private static function onHyphen(string $first, string $nodeString, int $line):NodeGeneric |
| 139 | 142 | { |
| 140 | - if (substr($nodeString, 0, 3) === '---') return new Nodes\DocStart($nodeString, $line); |
|
| 141 | - elseif ((bool) preg_match(Regex::ITEM, ltrim($nodeString))) return new Nodes\Item($nodeString, $line); |
|
| 142 | - else { |
|
| 143 | + if (substr($nodeString, 0, 3) === '---') { |
|
| 144 | + return new Nodes\DocStart($nodeString, $line); |
|
| 145 | + } elseif ((bool) preg_match(Regex::ITEM, ltrim($nodeString))) { |
|
| 146 | + return new Nodes\Item($nodeString, $line); |
|
| 147 | + } else { |
|
| 143 | 148 | return new Nodes\Scalar($nodeString, $line); |
| 144 | 149 | } |
| 145 | 150 | } |
@@ -129,8 +129,12 @@ |
||
| 129 | 129 | try { |
| 130 | 130 | foreach ($generator as $lineNB => $lineString) { |
| 131 | 131 | $node = NodeFactory::get($lineString, $lineNB); |
| 132 | - if ($this->_debug === 1) echo $lineNB.":".get_class($node)."\n"; |
|
| 133 | - if ($this->needsSpecialProcess($node, $previous)) continue; |
|
| 132 | + if ($this->_debug === 1) { |
|
| 133 | + echo $lineNB.":".get_class($node)."\n"; |
|
| 134 | + } |
|
| 135 | + if ($this->needsSpecialProcess($node, $previous)) { |
|
| 136 | + continue; |
|
| 137 | + } |
|
| 134 | 138 | $this->_attachBlankLines($previous); |
| 135 | 139 | switch ($node->indent <=> $previous->indent) { |
| 136 | 140 | case -1: $target = $previous->getTargetOnLessIndent($node); |