@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | if ($this->_parent instanceof NodeGeneric) { |
| 80 | 80 | return $this->_parent; |
| 81 | 81 | } else { |
| 82 | - throw new \Exception("Cannnot find a parent for " . get_class($this), 1); |
|
| 82 | + throw new \Exception("Cannnot find a parent for ".get_class($this), 1); |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | $cursor = $this->getParent(); |
@@ -105,14 +105,14 @@ discard block |
||
| 105 | 105 | protected function getRoot(): Root |
| 106 | 106 | { |
| 107 | 107 | if (is_null($this->_parent)) { |
| 108 | - throw new \Exception(__METHOD__ . ": can only be used when Node has a parent set", 1); |
|
| 108 | + throw new \Exception(__METHOD__.": can only be used when Node has a parent set", 1); |
|
| 109 | 109 | } |
| 110 | 110 | $pointer = $this; |
| 111 | 111 | do { |
| 112 | 112 | if ($pointer->_parent instanceof NodeGeneric) { |
| 113 | 113 | $pointer = $pointer->_parent; |
| 114 | 114 | } else { |
| 115 | - throw new \Exception("Node has no _parent set : " . get_class($pointer), 1); |
|
| 115 | + throw new \Exception("Node has no _parent set : ".get_class($pointer), 1); |
|
| 116 | 116 | } |
| 117 | 117 | } while (!($pointer instanceof Root)); |
| 118 | 118 | return $pointer; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | public function specialProcess( |
| 155 | 155 | /** @scrutinizer ignore-unused */ |
| 156 | - NodeGeneric &$previous, |
|
| 156 | + NodeGeneric&$previous, |
|
| 157 | 157 | /** @scrutinizer ignore-unused */ |
| 158 | 158 | array &$emptyLines |
| 159 | 159 | ): bool { |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * Find parent target when current Node indentation is lesser than previous node indentation |
| 165 | 165 | * |
| 166 | 166 | */ |
| 167 | - public function getTargetOnLessIndent(NodeGeneric &$node): ?NodeGeneric |
|
| 167 | + public function getTargetOnLessIndent(NodeGeneric&$node): ?NodeGeneric |
|
| 168 | 168 | { |
| 169 | 169 | $supposedParent = $this->getParent($node->indent); |
| 170 | 170 | if ($node instanceof Item && $supposedParent instanceof Root) { |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | * Find parent target when current Node indentation is equal to previous node indentation |
| 187 | 187 | * |
| 188 | 188 | */ |
| 189 | - public function getTargetOnEqualIndent(NodeGeneric &$node): ?NodeGeneric |
|
| 189 | + public function getTargetOnEqualIndent(NodeGeneric&$node): ?NodeGeneric |
|
| 190 | 190 | { |
| 191 | 191 | return $this->getParent(); |
| 192 | 192 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * Find parent target when current Node indentation is superior than previous node indentation |
| 196 | 196 | * |
| 197 | 197 | */ |
| 198 | - public function getTargetOnMoreIndent(NodeGeneric &$node): ?NodeGeneric |
|
| 198 | + public function getTargetOnMoreIndent(NodeGeneric&$node): ?NodeGeneric |
|
| 199 | 199 | { |
| 200 | 200 | return $this->isAwaitingChild($node) ? $this : $this->getParent(); |
| 201 | 201 | } |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | public function isOneOf(...$classNameList): bool |
| 217 | 217 | { |
| 218 | 218 | foreach ($classNameList as $className) { |
| 219 | - $fqn = "Dallgoot\\Yaml\\Nodes\\$className"; |
|
| 219 | + $fqn = "Dallgoot\\Yaml\\Nodes\\$className"; |
|
| 220 | 220 | if ($this instanceof $fqn) return true; |
| 221 | 221 | } |
| 222 | 222 | return false; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | if ($this->tag) $props['tag'] = "($this->tag)"; |
| 237 | 237 | if ($this->value) $props['value'] = $this->value; |
| 238 | 238 | // $props['value'] = $this->value; |
| 239 | - $props['raw'] = $this->raw; |
|
| 239 | + $props['raw'] = $this->raw; |
|
| 240 | 240 | if (!$this->_parent) $props['parent'] = 'NO PARENT!!!'; |
| 241 | 241 | return $props; |
| 242 | 242 | } |
@@ -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 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | public function getParent(?int $indent = null, $type = 0): NodeGeneric |
| 27 | 27 | { |
| 28 | 28 | if ($this->_parent !== null) { |
| 29 | - throw new \ParseError(__CLASS__ . " can NOT have a parent, something's wrong", 1); |
|
| 29 | + throw new \ParseError(__CLASS__." can NOT have a parent, something's wrong", 1); |
|
| 30 | 30 | } |
| 31 | 31 | return $this; |
| 32 | 32 | } |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class JSON extends NodeGeneric |
| 14 | 14 | { |
| 15 | - private const JSON_OPTIONS = \JSON_PARTIAL_OUTPUT_ON_ERROR | \JSON_UNESCAPED_SLASHES; |
|
| 15 | + private const JSON_OPTIONS = \JSON_PARTIAL_OUTPUT_ON_ERROR|\JSON_UNESCAPED_SLASHES; |
|
| 16 | 16 | |
| 17 | 17 | public function build(&$parent = null) |
| 18 | 18 | { |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | { |
| 47 | 47 | $tmp = clone $this; |
| 48 | 48 | $tmp->rewind(); |
| 49 | - $fqn = __NAMESPACE__ . "\\Nodes\\$nodeType"; |
|
| 49 | + $fqn = __NAMESPACE__."\\Nodes\\$nodeType"; |
|
| 50 | 50 | foreach ($tmp as $child) { |
| 51 | 51 | if ($child instanceof $fqn) return true; |
| 52 | 52 | } |
@@ -141,8 +141,8 @@ discard block |
||
| 141 | 141 | $output = trim($first->raw); |
| 142 | 142 | foreach ($list as $child) { |
| 143 | 143 | if ($child instanceof Scalar) { |
| 144 | - $separator = isset($output[-1]) && $output[-1] === "\n" ? '' : ' '; |
|
| 145 | - $output .= $separator . trim($child->raw); |
|
| 144 | + $separator = isset($output[-1]) && $output[-1] === "\n" ? '' : ' '; |
|
| 145 | + $output .= $separator.trim($child->raw); |
|
| 146 | 146 | } elseif ($child instanceof Blank) { |
| 147 | 147 | $output .= "\n"; |
| 148 | 148 | } else { |
@@ -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 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | if ($dataType === \INF) return '.inf'; |
| 30 | 30 | if ($dataType === -\INF) return '-.inf'; |
| 31 | - $precision = "%." . $this->dumper->floatPrecision . "F"; |
|
| 31 | + $precision = "%.".$this->dumper->floatPrecision."F"; |
|
| 32 | 32 | switch (gettype($dataType)) { |
| 33 | 33 | case 'boolean': |
| 34 | 34 | return $dataType ? 'true' : 'false'; |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | { |
| 95 | 95 | $pairs = ['']; |
| 96 | 96 | $realIndent = $indent + Dumper::INDENT; |
| 97 | - if($isRoot) { |
|
| 97 | + if ($isRoot) { |
|
| 98 | 98 | $pairs = []; |
| 99 | 99 | $realIndent = 0; |
| 100 | 100 | } |
@@ -110,15 +110,15 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | $pairs = []; |
| 112 | 112 | foreach ($o as $key => $value) { |
| 113 | - $pairs[] = "$key: " . $this->dumper->dump($value, 0, true, false); |
|
| 113 | + $pairs[] = "$key: ".$this->dumper->dump($value, 0, true, false); |
|
| 114 | 114 | } |
| 115 | - return '{'. implode(', ', $pairs) . '}'; |
|
| 115 | + return '{'.implode(', ', $pairs).'}'; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
| 119 | 119 | public function dumpArray(array $a, int $indent, bool $isCompact = false, $isRoot = false): string |
| 120 | 120 | { |
| 121 | - if(isset($a[0]) && $a[0] instanceof YamlObject) { |
|
| 121 | + if (isset($a[0]) && $a[0] instanceof YamlObject) { |
|
| 122 | 122 | return $this->dumper->dumpMultiDoc($a); |
| 123 | 123 | } |
| 124 | 124 | if (array_keys($a) !== range(0, count($a) - 1)) { |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | { |
| 134 | 134 | $pairs = ['']; |
| 135 | 135 | $realIndent = $indent + Dumper::INDENT; |
| 136 | - if($isRoot) { |
|
| 136 | + if ($isRoot) { |
|
| 137 | 137 | $pairs = []; |
| 138 | 138 | $realIndent = 0; |
| 139 | 139 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | foreach ($a as $value) { |
| 152 | 152 | $pairs[] = $this->dumper->dump($value, $indent, true); |
| 153 | 153 | } |
| 154 | - return '[' . implode(', ', $pairs) . ']'; |
|
| 154 | + return '['.implode(', ', $pairs).']'; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | $separator = "\n"; |
| 187 | 187 | $isCompact = $obj->value instanceof Compact; |
| 188 | 188 | if (is_scalar($obj->value) || $isCompact) { |
| 189 | - $separator = ' '; |
|
| 189 | + $separator = ' '; |
|
| 190 | 190 | } |
| 191 | - return ($obj->tagName) . $separator . $this->dumper->dump($obj->value, $indent, $isCompact); |
|
| 191 | + return ($obj->tagName).$separator.$this->dumper->dump($obj->value, $indent, $isCompact); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -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,9 +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)) throw new \Exception(self::class.": No content to convert to Yaml"); |
|
| 55 | 55 | if (is_scalar($dataType)) { |
| 56 | - return "--- " . $this->handler->dumpScalar($dataType) . PHP_EOL; |
|
| 56 | + return "--- ".$this->handler->dumpScalar($dataType).PHP_EOL; |
|
| 57 | 57 | } |
| 58 | 58 | return $this->dump($dataType, 0, false, true); |
| 59 | 59 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | foreach ($arrayOfYamlObject as $yamlObject) { |
| 96 | 96 | $docs[] = $this->dumpYamlObject($yamlObject); |
| 97 | 97 | } |
| 98 | - return "---\n" . implode("\n---\n", $docs); |
|
| 98 | + return "---\n".implode("\n---\n", $docs); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | $pairs = []; |
| 115 | 115 | if (count($properties) === 0) { |
| 116 | 116 | return $this->handler->dumpArray($obj->getArrayCopy(), 0, false, true); |
| 117 | - }else { |
|
| 117 | + } else { |
|
| 118 | 118 | return $this->handler->dumpObject($obj, 0, false, true); |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -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 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | try { |
| 48 | 48 | return (new Loader(null, $options, $debug))->parse($someYaml); |
| 49 | 49 | } catch (\Throwable $e) { |
| 50 | - throw new \Exception(__CLASS__ . " Error while parsing YAML string", 1, $e); |
|
| 50 | + throw new \Exception(__CLASS__." Error while parsing YAML string", 1, $e); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | try { |
| 75 | 75 | return (new Loader($fileName, $options, (int) $debug))->parse(); |
| 76 | 76 | } catch (\Throwable $e) { |
| 77 | - throw new \Exception(__CLASS__ . " Error during parsing '$fileName'", 1, $e); |
|
| 77 | + throw new \Exception(__CLASS__." Error during parsing '$fileName'", 1, $e); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | try { |
| 94 | 94 | return (new Dumper($options))->toString($somePhpVar); |
| 95 | 95 | } catch (\Throwable $e) { |
| 96 | - throw new \Exception(__CLASS__ . " Error dumping", 1, $e); |
|
| 96 | + throw new \Exception(__CLASS__." Error dumping", 1, $e); |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | try { |
| 116 | 116 | return (new Dumper($options))->toFile($fileName, $somePhpVar); |
| 117 | 117 | } catch (\Throwable $e) { |
| 118 | - throw new \Exception(__CLASS__ . " Error during dumping '$fileName'", 1, $e); |
|
| 118 | + throw new \Exception(__CLASS__." Error during dumping '$fileName'", 1, $e); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | { |
| 16 | 16 | private YamlProperties $__yaml__object__api; |
| 17 | 17 | |
| 18 | - const UNDEFINED_METHOD = self::class . ": undefined method '%s', valid methods are (addReference,getReference,getAllReferences,addComment,getComment,setText,addTag,hasDocStart,isTagged)"; |
|
| 18 | + const UNDEFINED_METHOD = self::class.": undefined method '%s', valid methods are (addReference,getReference,getAllReferences,addComment,getComment,setText,addTag,hasDocStart,isTagged)"; |
|
| 19 | 19 | const UNKNOWN_REFERENCE = "no reference named: '%s', known are : (%s)"; |
| 20 | 20 | const UNAMED_REFERENCE = "reference MUST have a name"; |
| 21 | 21 | const TAGHANDLE_DUPLICATE = "Tag handle '%s' already declared before, handle must be unique"; |
@@ -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 | } |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | //ArrayIterator options --> Array indices can be accessed as properties in read/write. |
| 23 | 23 | parent::__construct( |
| 24 | 24 | /** @scrutinizer ignore-type */ |
| 25 | - $candidate, \ArrayIterator::STD_PROP_LIST | \ArrayIterator::ARRAY_AS_PROPS); |
|
| 25 | + $candidate, \ArrayIterator::STD_PROP_LIST|\ArrayIterator::ARRAY_AS_PROPS); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |