@@ -15,12 +15,12 @@ |
||
| 15 | 15 | private const NO_NAME = '%s Error: a tag MUST have a name'; |
| 16 | 16 | private const WRONG_VALUE = "Error : cannot transform tag '%s' for type '%s'"; |
| 17 | 17 | private const LEGACY_TAGS_HANDLERS = ['!!str' => 'strHandler', |
| 18 | - '!!binary' => 'binaryHandler', |
|
| 19 | - '!set' => 'setHandler', |
|
| 20 | - '!!omap' => 'omapHandler', |
|
| 21 | - '!php/object' => 'symfonyPHPobjectHandler', |
|
| 22 | - '!inline' => 'inlineHandler', |
|
| 23 | - ]; |
|
| 18 | + '!!binary' => 'binaryHandler', |
|
| 19 | + '!set' => 'setHandler', |
|
| 20 | + '!!omap' => 'omapHandler', |
|
| 21 | + '!php/object' => 'symfonyPHPobjectHandler', |
|
| 22 | + '!inline' => 'inlineHandler', |
|
| 23 | + ]; |
|
| 24 | 24 | |
| 25 | 25 | public static $registeredHandlers = []; |
| 26 | 26 | |
@@ -10,16 +10,16 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class NodeComment extends Node |
| 12 | 12 | { |
| 13 | - public function specialProcess(Node &$previous, array &$emptyLines):bool |
|
| 14 | - { |
|
| 13 | + public function specialProcess(Node &$previous, array &$emptyLines):bool |
|
| 14 | + { |
|
| 15 | 15 | $previous->getRoot()->add($this); |
| 16 | 16 | return true; |
| 17 | - } |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function build(&$parent = null) |
|
| 20 | - { |
|
| 19 | + public function build(&$parent = null) |
|
| 20 | + { |
|
| 21 | 21 | $root = $this->getRoot(); |
| 22 | 22 | $yamlObject = $root->getYamlObject(); |
| 23 | 23 | $yamlObject->addComment($this->line, $this->raw); |
| 24 | - } |
|
| 24 | + } |
|
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -31,7 +31,9 @@ |
||
| 31 | 31 | $built = is_null($this->value) ? null : $this->value->build(); |
| 32 | 32 | $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
| 33 | 33 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
| 34 | - if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
|
| 34 | + if (empty($key)) { |
|
| 35 | + throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
|
| 36 | + } |
|
| 35 | 37 | $parent->{trim($key, '\'" ')} = null; |
| 36 | 38 | } |
| 37 | 39 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | return false; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - /** |
|
| 133 | + /** |
|
| 134 | 134 | * Find parent target when current Node indentation is lesser than previous node indentation |
| 135 | 135 | * |
| 136 | 136 | * @param Node $previous The previous |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | return $this->getParent(); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - /** |
|
| 169 | + /** |
|
| 170 | 170 | * Find parent target when current Node indentation is superior than previous node indentation |
| 171 | 171 | * |
| 172 | 172 | * @param Node $previous The previous |
@@ -210,13 +210,23 @@ |
||
| 210 | 210 | { |
| 211 | 211 | $props = []; |
| 212 | 212 | $props['line->indent'] = "$this->line -> $this->indent"; |
| 213 | - if ($this->identifier) $props['identifier'] = "($this->identifier)"; |
|
| 214 | - if ($this->anchor) $props['anchor'] = "($this->anchor)"; |
|
| 215 | - if ($this->tag) $props['tag'] = "($this->tag)"; |
|
| 216 | - if ($this->value) $props['value'] = $this->value; |
|
| 213 | + if ($this->identifier) { |
|
| 214 | + $props['identifier'] = "($this->identifier)"; |
|
| 215 | + } |
|
| 216 | + if ($this->anchor) { |
|
| 217 | + $props['anchor'] = "($this->anchor)"; |
|
| 218 | + } |
|
| 219 | + if ($this->tag) { |
|
| 220 | + $props['tag'] = "($this->tag)"; |
|
| 221 | + } |
|
| 222 | + if ($this->value) { |
|
| 223 | + $props['value'] = $this->value; |
|
| 224 | + } |
|
| 217 | 225 | // $props['value'] = $this->value; |
| 218 | 226 | $props['raw'] = $this->raw; |
| 219 | - if (!$this->_parent) $props['parent'] = 'NO PARENT!!!'; |
|
| 227 | + if (!$this->_parent) { |
|
| 228 | + $props['parent'] = 'NO PARENT!!!'; |
|
| 229 | + } |
|
| 220 | 230 | return $props; |
| 221 | 231 | } |
| 222 | 232 | } |
@@ -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 | } |
@@ -79,12 +79,12 @@ |
||
| 79 | 79 | */ |
| 80 | 80 | public function checkTypeCoherence($estimatedType):bool |
| 81 | 81 | { |
| 82 | - // if ($this->type === self::MAPPING) { |
|
| 83 | - // if ($estimatedType === self::SEQUENCE) { |
|
| 84 | - // throw new \ParseError("Error : no coherence in types", 1); |
|
| 85 | - // } |
|
| 86 | - // } |
|
| 87 | - return (bool) $estimatedType; |
|
| 82 | + // if ($this->type === self::MAPPING) { |
|
| 83 | + // if ($estimatedType === self::SEQUENCE) { |
|
| 84 | + // throw new \ParseError("Error : no coherence in types", 1); |
|
| 85 | + // } |
|
| 86 | + // } |
|
| 87 | + return (bool) $estimatedType; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | public function build(&$parent = null) |
@@ -37,7 +37,9 @@ discard block |
||
| 37 | 37 | $tmp->rewind(); |
| 38 | 38 | $fqn = __NAMESPACE__."\\$nodeType"; |
| 39 | 39 | foreach ($tmp as $child) { |
| 40 | - if ($child instanceof $fqn) return true; |
|
| 40 | + if ($child instanceof $fqn) { |
|
| 41 | + return true; |
|
| 42 | + } |
|
| 41 | 43 | } |
| 42 | 44 | return false; |
| 43 | 45 | } |
@@ -51,7 +53,9 @@ discard block |
||
| 51 | 53 | && !($child instanceof NodeDirective) |
| 52 | 54 | && !($child instanceof NodeBlank) |
| 53 | 55 | && !($child instanceof NodeDocstart |
| 54 | - && is_null($child->value)) ) return true; |
|
| 56 | + && is_null($child->value)) ) { |
|
| 57 | + return true; |
|
| 58 | + } |
|
| 55 | 59 | } |
| 56 | 60 | return false; |
| 57 | 61 | } |
@@ -59,9 +63,11 @@ discard block |
||
| 59 | 63 | public function push($node) |
| 60 | 64 | { |
| 61 | 65 | $type = null; |
| 62 | - if ($node instanceof NodeItem ) $type = self::SEQUENCE; |
|
| 63 | - elseif ($node instanceof NodeKey) $type = self::MAPPING; |
|
| 64 | - elseif ($node instanceof NodeSetKey |
|
| 66 | + if ($node instanceof NodeItem ) { |
|
| 67 | + $type = self::SEQUENCE; |
|
| 68 | + } elseif ($node instanceof NodeKey) { |
|
| 69 | + $type = self::MAPPING; |
|
| 70 | + } elseif ($node instanceof NodeSetKey |
|
| 65 | 71 | || $node instanceof NodeSetValue) { |
| 66 | 72 | $type = self::SET; |
| 67 | 73 | } elseif ($node instanceof NodeScalar ){ |
@@ -41,7 +41,9 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public static function toString($dataType, int $options = null):string |
| 43 | 43 | { |
| 44 | - if (is_null($dataType)) throw new \Exception(self::class.": No content to convert to Yaml"); |
|
| 44 | + if (is_null($dataType)) { |
|
| 45 | + throw new \Exception(self::class.": No content to convert to Yaml"); |
|
| 46 | + } |
|
| 45 | 47 | self::$options = is_int($options) ? $options : self::OPTIONS; |
| 46 | 48 | self::$result = new DLL; |
| 47 | 49 | if ($dataType instanceof YamlObject) { |
@@ -83,8 +85,12 @@ discard block |
||
| 83 | 85 | private static function dump($dataType, int $indent) |
| 84 | 86 | { |
| 85 | 87 | if (is_scalar($dataType)) { |
| 86 | - if ($dataType === \INF) return '.inf'; |
|
| 87 | - if ($dataType === -\INF) return '-.inf'; |
|
| 88 | + if ($dataType === \INF) { |
|
| 89 | + return '.inf'; |
|
| 90 | + } |
|
| 91 | + if ($dataType === -\INF) { |
|
| 92 | + return '-.inf'; |
|
| 93 | + } |
|
| 88 | 94 | switch (gettype($dataType)) { |
| 89 | 95 | case 'boolean': return $dataType ? 'true' : 'false'; |
| 90 | 96 | case 'float': //fall through |
@@ -106,7 +112,9 @@ discard block |
||
| 106 | 112 | */ |
| 107 | 113 | private static function dumpYamlObject(YamlObject $obj) |
| 108 | 114 | { |
| 109 | - if ($obj->hasDocStart() && self::$result instanceof DLL) self::$result->push("---"); |
|
| 115 | + if ($obj->hasDocStart() && self::$result instanceof DLL) { |
|
| 116 | + self::$result->push("---"); |
|
| 117 | + } |
|
| 110 | 118 | // self::dump($obj, 0); |
| 111 | 119 | if (count($obj) > 0) { |
| 112 | 120 | self::dumpArray($obj->getArrayCopy(), 0); |
@@ -181,9 +189,13 @@ discard block |
||
| 181 | 189 | self::add(self::dump($obj->value, $indent + self::INDENT), $indent + self::INDENT); |
| 182 | 190 | } |
| 183 | 191 | } |
| 184 | - if ($obj instanceof Compact) return self::dumpCompact($obj, $indent); |
|
| 192 | + if ($obj instanceof Compact) { |
|
| 193 | + return self::dumpCompact($obj, $indent); |
|
| 194 | + } |
|
| 185 | 195 | //TODO: consider dumping datetime as date strings according to a format provided by user or default |
| 186 | - if ($obj instanceof \DateTime) return $obj->format(self::DATE_FORMAT); |
|
| 196 | + if ($obj instanceof \DateTime) { |
|
| 197 | + return $obj->format(self::DATE_FORMAT); |
|
| 198 | + } |
|
| 187 | 199 | $propList = get_object_vars($obj); |
| 188 | 200 | foreach ($propList as $property => $value) { |
| 189 | 201 | if (is_scalar($value) || $value instanceof Compact || $value instanceof \DateTime) { |
@@ -92,13 +92,13 @@ |
||
| 92 | 92 | if (Regex::isDate($v)) return self::$dateAsObject && !$onlyScalar ? date_create($v) : $v; |
| 93 | 93 | if (Regex::isNumber($v)) return self::getNumber($v); |
| 94 | 94 | $types = ['yes' => true, |
| 95 | - 'no' => false, |
|
| 96 | - 'true' => true, |
|
| 97 | - 'false' => false, |
|
| 98 | - 'null' => null, |
|
| 99 | - '.inf' => \INF, |
|
| 100 | - '-.inf' => -\INF, |
|
| 101 | - '.nan' => \NAN |
|
| 95 | + 'no' => false, |
|
| 96 | + 'true' => true, |
|
| 97 | + 'false' => false, |
|
| 98 | + 'null' => null, |
|
| 99 | + '.inf' => \INF, |
|
| 100 | + '-.inf' => -\INF, |
|
| 101 | + '.nan' => \NAN |
|
| 102 | 102 | ]; |
| 103 | 103 | return array_key_exists(strtolower($v), $types) ? $types[strtolower($v)] : $v; |
| 104 | 104 | } |
@@ -89,8 +89,12 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | public static function getScalar(string $v, bool $onlyScalar = false) |
| 91 | 91 | { |
| 92 | - if (Regex::isDate($v)) return self::$dateAsObject && !$onlyScalar ? date_create($v) : $v; |
|
| 93 | - if (Regex::isNumber($v)) return self::getNumber($v); |
|
| 92 | + if (Regex::isDate($v)) { |
|
| 93 | + return self::$dateAsObject && !$onlyScalar ? date_create($v) : $v; |
|
| 94 | + } |
|
| 95 | + if (Regex::isNumber($v)) { |
|
| 96 | + return self::getNumber($v); |
|
| 97 | + } |
|
| 94 | 98 | $types = ['yes' => true, |
| 95 | 99 | 'no' => false, |
| 96 | 100 | 'true' => true, |
@@ -113,8 +117,12 @@ discard block |
||
| 113 | 117 | */ |
| 114 | 118 | private static function getNumber(string $v) |
| 115 | 119 | { |
| 116 | - if ((bool) preg_match(Regex::OCTAL_NUM, $v)) return intval(base_convert($v, 8, 10)); |
|
| 117 | - if ((bool) preg_match(Regex::HEX_NUM, $v)) return intval(base_convert($v, 16, 10)); |
|
| 120 | + if ((bool) preg_match(Regex::OCTAL_NUM, $v)) { |
|
| 121 | + return intval(base_convert($v, 8, 10)); |
|
| 122 | + } |
|
| 123 | + if ((bool) preg_match(Regex::HEX_NUM, $v)) { |
|
| 124 | + return intval(base_convert($v, 16, 10)); |
|
| 125 | + } |
|
| 118 | 126 | return is_bool(strpos($v, '.')) || substr_count($v, '.') > 1 ? intval($v) : floatval($v); |
| 119 | 127 | } |
| 120 | 128 | |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | $result = ''; |
| 23 | 23 | $list = $value->filterComment(); |
| 24 | 24 | if ($this->identifier !== '+') { |
| 25 | - self::litteralStripTrailing($list); |
|
| 25 | + self::litteralStripTrailing($list); |
|
| 26 | 26 | } |
| 27 | 27 | if ($list->count()) { |
| 28 | 28 | $list->setIteratorMode(NodeList::IT_MODE_DELETE); |