@@ -32,7 +32,9 @@ |
||
32 | 32 | $match => new Nodes\Key($nodeString, $line, $matches), |
33 | 33 | default => self::onCharacter($trimmed[0], $nodeString, $line) |
34 | 34 | }; |
35 | - if ($debug) echo $line . ":" . get_class($node) . "\n"; |
|
35 | + if ($debug) { |
|
36 | + echo $line . ":" . get_class($node) . "\n"; |
|
37 | + } |
|
36 | 38 | return $node; |
37 | 39 | } |
38 | 40 |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | if (is_null($strContent)) { |
103 | 103 | if(is_null($this->content)) { |
104 | 104 | throw new \Exception(self::EXCEPTION_LINE_SPLIT); |
105 | - }else { |
|
105 | + } else { |
|
106 | 106 | $source = $this->content; |
107 | 107 | } |
108 | 108 | } else { |
@@ -139,7 +139,9 @@ discard block |
||
139 | 139 | try { |
140 | 140 | foreach ($generator as $lineNB => $lineString) { |
141 | 141 | $node = NodeFactory::get($lineString, $lineNB, $debugNodeFactory); |
142 | - if ($this->needsSpecialProcess($node, $previous)) continue; |
|
142 | + if ($this->needsSpecialProcess($node, $previous)) { |
|
143 | + continue; |
|
144 | + } |
|
143 | 145 | $this->_attachBlankLines($previous); |
144 | 146 | $target = match ($node->indent <=> $previous->indent) { |
145 | 147 | -1 => $previous->getTargetOnLessIndent($node), |
@@ -35,7 +35,9 @@ |
||
35 | 35 | $built = is_null($this->value) ? null : $this->value->build(); |
36 | 36 | $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built; |
37 | 37 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES); |
38 | - if (empty($key)) throw new \Exception("Cant serialize complex key: " . var_export($this->value, true)); |
|
38 | + if (empty($key)) { |
|
39 | + throw new \Exception("Cant serialize complex key: " . var_export($this->value, true)); |
|
40 | + } |
|
39 | 41 | $parent->{trim($key, '\'" ')} = null; |
40 | 42 | return null; |
41 | 43 | } |
@@ -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 = [ |
103 | 107 | 'yes' => true, |
104 | 108 | 'no' => false, |
@@ -143,8 +147,12 @@ discard block |
||
143 | 147 | */ |
144 | 148 | private function getNumber(string $v) |
145 | 149 | { |
146 | - if ((bool) preg_match(Regex::OCTAL_NUM, $v)) return intval(base_convert($v, 8, 10)); |
|
147 | - if ((bool) preg_match(Regex::HEX_NUM, $v)) return intval(base_convert($v, 16, 10)); |
|
150 | + if ((bool) preg_match(Regex::OCTAL_NUM, $v)) { |
|
151 | + return intval(base_convert($v, 8, 10)); |
|
152 | + } |
|
153 | + if ((bool) preg_match(Regex::HEX_NUM, $v)) { |
|
154 | + return intval(base_convert($v, 16, 10)); |
|
155 | + } |
|
148 | 156 | return is_bool(strpos($v, '.')) || substr_count($v, '.') > 1 ? intval($v) : floatval($v); |
149 | 157 | } |
150 | 158 | } |
@@ -36,7 +36,9 @@ |
||
36 | 36 | |
37 | 37 | public function add(NodeGeneric $child): NodeGeneric |
38 | 38 | { |
39 | - if (is_null($this->value)) $this->value = new NodeList(); |
|
39 | + if (is_null($this->value)) { |
|
40 | + $this->value = new NodeList(); |
|
41 | + } |
|
40 | 42 | $candidate = $child; |
41 | 43 | if (!$child->isOneOf('Scalar', 'Blank', 'Comment', 'Quoted')) { |
42 | 44 | $candidate = new Scalar((string) $child->raw, $child->line); |
@@ -217,7 +217,9 @@ discard block |
||
217 | 217 | { |
218 | 218 | foreach ($classNameList as $className) { |
219 | 219 | $fqn = "Dallgoot\\Yaml\\Nodes\\$className"; |
220 | - if ($this instanceof $fqn) return true; |
|
220 | + if ($this instanceof $fqn) { |
|
221 | + return true; |
|
222 | + } |
|
221 | 223 | } |
222 | 224 | return false; |
223 | 225 | } |
@@ -231,13 +233,23 @@ discard block |
||
231 | 233 | { |
232 | 234 | $props = []; |
233 | 235 | $props['line->indent'] = "$this->line -> $this->indent"; |
234 | - if ($this->identifier) $props['identifier'] = "($this->identifier)"; |
|
235 | - if ($this->anchor) $props['anchor'] = "($this->anchor)"; |
|
236 | - if ($this->tag) $props['tag'] = "($this->tag)"; |
|
237 | - if ($this->value) $props['value'] = $this->value; |
|
236 | + if ($this->identifier) { |
|
237 | + $props['identifier'] = "($this->identifier)"; |
|
238 | + } |
|
239 | + if ($this->anchor) { |
|
240 | + $props['anchor'] = "($this->anchor)"; |
|
241 | + } |
|
242 | + if ($this->tag) { |
|
243 | + $props['tag'] = "($this->tag)"; |
|
244 | + } |
|
245 | + if ($this->value) { |
|
246 | + $props['value'] = $this->value; |
|
247 | + } |
|
238 | 248 | // $props['value'] = $this->value; |
239 | 249 | $props['raw'] = $this->raw; |
240 | - if (!$this->_parent) $props['parent'] = 'NO PARENT!!!'; |
|
250 | + if (!$this->_parent) { |
|
251 | + $props['parent'] = 'NO PARENT!!!'; |
|
252 | + } |
|
241 | 253 | return $props; |
242 | 254 | } |
243 | 255 | } |
@@ -48,7 +48,9 @@ discard block |
||
48 | 48 | $tmp->rewind(); |
49 | 49 | $fqn = __NAMESPACE__ . "\\Nodes\\$nodeType"; |
50 | 50 | foreach ($tmp as $child) { |
51 | - if ($child instanceof $fqn) return true; |
|
51 | + if ($child instanceof $fqn) { |
|
52 | + return true; |
|
53 | + } |
|
52 | 54 | } |
53 | 55 | return false; |
54 | 56 | } |
@@ -64,7 +66,9 @@ discard block |
||
64 | 66 | && !($child instanceof Blank) |
65 | 67 | && !($child instanceof Docstart |
66 | 68 | && is_null($child->value)) |
67 | - ) return true; |
|
69 | + ) { |
|
70 | + return true; |
|
71 | + } |
|
68 | 72 | } |
69 | 73 | return false; |
70 | 74 | } |
@@ -26,8 +26,12 @@ |
||
26 | 26 | |
27 | 27 | public function dumpScalar($dataType): string |
28 | 28 | { |
29 | - if ($dataType === \INF) return '.inf'; |
|
30 | - if ($dataType === -\INF) return '-.inf'; |
|
29 | + if ($dataType === \INF) { |
|
30 | + return '.inf'; |
|
31 | + } |
|
32 | + if ($dataType === -\INF) { |
|
33 | + return '-.inf'; |
|
34 | + } |
|
31 | 35 | $precision = "%." . $this->dumper->floatPrecision . "F"; |
32 | 36 | switch (gettype($dataType)) { |
33 | 37 | case 'boolean': |
@@ -51,7 +51,9 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function toString($dataType, ?int $options = null): string |
53 | 53 | { |
54 | - if (empty($dataType)) throw new \Exception(self::class . ": No content to convert to Yaml"); |
|
54 | + if (empty($dataType)) { |
|
55 | + throw new \Exception(self::class . ": No content to convert to Yaml"); |
|
56 | + } |
|
55 | 57 | if (is_scalar($dataType)) { |
56 | 58 | return "--- " . $this->handler->dumpScalar($dataType) . PHP_EOL; |
57 | 59 | } |
@@ -114,7 +116,7 @@ discard block |
||
114 | 116 | $pairs = []; |
115 | 117 | if (count($properties) === 0) { |
116 | 118 | return $this->handler->dumpArray($obj->getArrayCopy(), 0, false, true); |
117 | - }else { |
|
119 | + } else { |
|
118 | 120 | return $this->handler->dumpObject($obj, 0, false, true); |
119 | 121 | } |
120 | 122 | } |