@@ -74,7 +74,7 @@ |
||
74 | 74 | switch (gettype($dataType)) { |
75 | 75 | case 'boolean': return $dataType ? 'true' : 'false'; |
76 | 76 | case 'float': if (is_infinite($dataType)) return $dataType > 0 ? '.inf' : '-.inf'; |
77 | - return sprintf('%.2F', $dataType); |
|
77 | + return sprintf('%.2F', $dataType); |
|
78 | 78 | case 'double': if (is_nan((float) $dataType)) return '.nan'; |
79 | 79 | default: |
80 | 80 | return $dataType; |
@@ -159,10 +159,10 @@ |
||
159 | 159 | if (is_array($subject) || $subject instanceof \Countable) { |
160 | 160 | $max = count($subject); |
161 | 161 | $objectAsArray = is_array($subject) ? $subject : $subject->getArrayCopy(); |
162 | - if(array_keys($objectAsArray) !== range(0, $max)) { |
|
162 | + if (array_keys($objectAsArray) !== range(0, $max)) { |
|
163 | 163 | $pairs = $objectAsArray; |
164 | 164 | } else { |
165 | - $valuesList = array_map([self, 'dump'], $objectAsArray, array_fill( 0 , $max , $indent )); |
|
165 | + $valuesList = array_map([self, 'dump'], $objectAsArray, array_fill(0, $max, $indent)); |
|
166 | 166 | return '['.implode(', ', $valuesList).']'; |
167 | 167 | } |
168 | 168 | } else { |
@@ -24,7 +24,9 @@ discard block |
||
24 | 24 | |
25 | 25 | public function __construct(int $options = null) |
26 | 26 | { |
27 | - if (is_int($options)) self::$options = $options; |
|
27 | + if (is_int($options)) { |
|
28 | + self::$options = $options; |
|
29 | + } |
|
28 | 30 | } |
29 | 31 | |
30 | 32 | /** |
@@ -39,7 +41,9 @@ discard block |
||
39 | 41 | */ |
40 | 42 | public static function toString($dataType, int $options = null):string |
41 | 43 | { |
42 | - if (is_null($dataType)) throw new \Exception(self::class.": No content to convert to Yaml", 1); |
|
44 | + if (is_null($dataType)) { |
|
45 | + throw new \Exception(self::class.": No content to convert to Yaml", 1); |
|
46 | + } |
|
43 | 47 | self::$options = is_int($options) ? $options : self::OPTIONS; |
44 | 48 | self::$result = new DLL; |
45 | 49 | if ($dataType instanceof YamlObject) { |
@@ -73,9 +77,13 @@ discard block |
||
73 | 77 | if (is_scalar($dataType)) { |
74 | 78 | switch (gettype($dataType)) { |
75 | 79 | case 'boolean': return $dataType ? 'true' : 'false'; |
76 | - case 'float': if (is_infinite($dataType)) return $dataType > 0 ? '.inf' : '-.inf'; |
|
80 | + case 'float': if (is_infinite($dataType)) { |
|
81 | + return $dataType > 0 ? '.inf' : '-.inf'; |
|
82 | + } |
|
77 | 83 | return sprintf('%.2F', $dataType); |
78 | - case 'double': if (is_nan((float) $dataType)) return '.nan'; |
|
84 | + case 'double': if (is_nan((float) $dataType)) { |
|
85 | + return '.nan'; |
|
86 | + } |
|
79 | 87 | default: |
80 | 88 | return $dataType; |
81 | 89 | } |
@@ -139,9 +147,13 @@ discard block |
||
139 | 147 | self::add(self::dump($obj->value, $indent + self::INDENT), $indent + self::INDENT); |
140 | 148 | } |
141 | 149 | } |
142 | - if ($obj instanceof Compact) return self::dumpCompact($obj, $indent); |
|
150 | + if ($obj instanceof Compact) { |
|
151 | + return self::dumpCompact($obj, $indent); |
|
152 | + } |
|
143 | 153 | //TODO: consider dumping datetime as date strings according to a format provided by user or default |
144 | - if ($obj instanceof \DateTime) return $obj->format('Y-m-d'); |
|
154 | + if ($obj instanceof \DateTime) { |
|
155 | + return $obj->format('Y-m-d'); |
|
156 | + } |
|
145 | 157 | $propList = get_object_vars($obj); |
146 | 158 | foreach ($propList as $property => $value) { |
147 | 159 | if (is_scalar($value)) { |
@@ -29,7 +29,9 @@ discard block |
||
29 | 29 | */ |
30 | 30 | private static function build(object $node, &$parent = null) |
31 | 31 | { |
32 | - if ($node instanceof NodeList) return self::buildNodeList($node, $parent); |
|
32 | + if ($node instanceof NodeList) { |
|
33 | + return self::buildNodeList($node, $parent); |
|
34 | + } |
|
33 | 35 | return self::buildNode($node, $parent); |
34 | 36 | } |
35 | 37 | |
@@ -84,7 +86,9 @@ discard block |
||
84 | 86 | } else { |
85 | 87 | $tmp = $node->getPhpValue(); |
86 | 88 | } |
87 | - if ($type === Y::REF_DEF) self::$_root->addReference($identifier, $tmp); |
|
89 | + if ($type === Y::REF_DEF) { |
|
90 | + self::$_root->addReference($identifier, $tmp); |
|
91 | + } |
|
88 | 92 | return self::$_root->getReference($identifier); |
89 | 93 | } |
90 | 94 | $typesActions = [Y::COMMENT => 'buildComment', |
@@ -170,10 +174,14 @@ discard block |
||
170 | 174 | } |
171 | 175 | $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE); |
172 | 176 | foreach ($_root->value as $child) { |
173 | - if ($child->type & Y::DOC_START) $totalDocStart++; |
|
177 | + if ($child->type & Y::DOC_START) { |
|
178 | + $totalDocStart++; |
|
179 | + } |
|
174 | 180 | //if 0 or 1 DOC_START = we are still in first document |
175 | 181 | $currentDoc = $totalDocStart > 1 ? $totalDocStart - 1 : 0; |
176 | - if (!isset($documents[$currentDoc])) $documents[$currentDoc] = new NodeList(); |
|
182 | + if (!isset($documents[$currentDoc])) { |
|
183 | + $documents[$currentDoc] = new NodeList(); |
|
184 | + } |
|
177 | 185 | $documents[$currentDoc]->push($child); |
178 | 186 | } |
179 | 187 | $content = array_map([self::class, 'buildDocument'], $documents, array_keys($documents)); |
@@ -243,9 +251,15 @@ discard block |
||
243 | 251 | $lines[] = $prefix.$child->value; |
244 | 252 | } |
245 | 253 | } |
246 | - if ($type & Y::RAW) return implode('', $lines); |
|
247 | - if ($type & Y::LITT) return implode("\n", $lines); |
|
248 | - if ($type & Y::LITT_FOLDED) return implode(' ', $lines); |
|
254 | + if ($type & Y::RAW) { |
|
255 | + return implode('', $lines); |
|
256 | + } |
|
257 | + if ($type & Y::LITT) { |
|
258 | + return implode("\n", $lines); |
|
259 | + } |
|
260 | + if ($type & Y::LITT_FOLDED) { |
|
261 | + return implode(' ', $lines); |
|
262 | + } |
|
249 | 263 | return ''; |
250 | 264 | } |
251 | 265 | |
@@ -260,8 +274,9 @@ discard block |
||
260 | 274 | private function buildSetKey(Node $node, $parent) |
261 | 275 | { |
262 | 276 | $key = json_encode(self::build($node->value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
263 | - if (empty($key)) |
|
264 | - throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
|
277 | + if (empty($key)) { |
|
278 | + throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
|
279 | + } |
|
265 | 280 | $parent->{$key} = null; |
266 | 281 | } |
267 | 282 | |
@@ -300,8 +315,11 @@ discard block |
||
300 | 315 | } |
301 | 316 | //TODO: have somewhere a list of common tags and their treatment |
302 | 317 | if (in_array($node->identifier, ['!binary', '!str'])) { |
303 | - if ($node->value->value instanceof NodeList) $node->value->value->type = Y::RAW; |
|
304 | - else $node->value->type = Y::RAW; |
|
318 | + if ($node->value->value instanceof NodeList) { |
|
319 | + $node->value->value->type = Y::RAW; |
|
320 | + } else { |
|
321 | + $node->value->type = Y::RAW; |
|
322 | + } |
|
305 | 323 | } |
306 | 324 | $val = is_null($node->value) ? null : self::build(/** @scrutinizer ignore-type */ $node->value, $node); |
307 | 325 | return new Tag($node->identifier, $val); |