@@ -46,9 +46,9 @@ |
||
| 46 | 46 | public function __call($funcName, $arguments) |
| 47 | 47 | { |
| 48 | 48 | $reflectAPI = new \ReflectionClass(get_class($this->__yaml__object__api)); |
| 49 | - $getName = function ($o) { return $o->name; }; |
|
| 49 | + $getName = function($o) { return $o->name; }; |
|
| 50 | 50 | $publicApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PUBLIC)); |
| 51 | - if (!in_array($funcName, $publicApi) ) { |
|
| 51 | + if (!in_array($funcName, $publicApi)) { |
|
| 52 | 52 | throw new \BadMethodCallException(sprintf(self::UNDEFINED_METHOD, $funcName, implode(",", $publicApi))); |
| 53 | 53 | } |
| 54 | 54 | return call_user_func_array([$this->__yaml__object__api, $funcName], $arguments); |
@@ -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 | } |
@@ -16,10 +16,13 @@ discard block |
||
| 16 | 16 | final public static function get($nodeString = null, $line = 0):Node |
| 17 | 17 | { |
| 18 | 18 | $trimmed = ltrim($nodeString); |
| 19 | - if ($trimmed === '') return new NodeBlank($nodeString, $line); |
|
| 20 | - elseif (substr($trimmed, 0, 3) === '...') return new NodeDocEnd($nodeString, $line); |
|
| 21 | - elseif (preg_match(Regex::KEY, $trimmed, $matches)) return new NodeKey($nodeString, $line, $matches); |
|
| 22 | - else { |
|
| 19 | + if ($trimmed === '') { |
|
| 20 | + return new NodeBlank($nodeString, $line); |
|
| 21 | + } elseif (substr($trimmed, 0, 3) === '...') { |
|
| 22 | + return new NodeDocEnd($nodeString, $line); |
|
| 23 | + } elseif (preg_match(Regex::KEY, $trimmed, $matches)) { |
|
| 24 | + return new NodeKey($nodeString, $line, $matches); |
|
| 25 | + } else { |
|
| 23 | 26 | $first = $trimmed[0]; |
| 24 | 27 | $stringGroups = ["-" ,'>|' ,'"\'',"#%" ,"{[" ,":?" ,'*&!']; |
| 25 | 28 | $methodGroups = ['Hyphen','Literal','Quoted','Special','Compact','SetElement','NodeAction']; |
@@ -90,10 +93,13 @@ discard block |
||
| 90 | 93 | final private static function onCompact(string $first, string $nodeString, int $line):Node |
| 91 | 94 | { |
| 92 | 95 | json_decode($nodeString, false, 512, self::JSON_OPTIONS); |
| 93 | - if (json_last_error() === \JSON_ERROR_NONE) return new NodeJSON($nodeString, $line); |
|
| 94 | - elseif (preg_match(Regex::MAPPING, trim($nodeString))) return new NodeCompactMapping($nodeString, $line); |
|
| 95 | - elseif (preg_match(Regex::SEQUENCE, trim($nodeString))) return new NodeCompactSequence($nodeString, $line); |
|
| 96 | - else { |
|
| 96 | + if (json_last_error() === \JSON_ERROR_NONE) { |
|
| 97 | + return new NodeJSON($nodeString, $line); |
|
| 98 | + } elseif (preg_match(Regex::MAPPING, trim($nodeString))) { |
|
| 99 | + return new NodeCompactMapping($nodeString, $line); |
|
| 100 | + } elseif (preg_match(Regex::SEQUENCE, trim($nodeString))) { |
|
| 101 | + return new NodeCompactSequence($nodeString, $line); |
|
| 102 | + } else { |
|
| 97 | 103 | return new NodePartial($nodeString, $line); |
| 98 | 104 | } |
| 99 | 105 | } |
@@ -108,9 +114,11 @@ discard block |
||
| 108 | 114 | */ |
| 109 | 115 | final private static function onHyphen(string $first, string $nodeString, int $line):Node |
| 110 | 116 | { |
| 111 | - if (substr($nodeString, 0, 3) === '---') return new NodeDocStart($nodeString, $line); |
|
| 112 | - elseif (preg_match(Regex::ITEM, ltrim($nodeString))) return new NodeItem($nodeString, $line); |
|
| 113 | - else { |
|
| 117 | + if (substr($nodeString, 0, 3) === '---') { |
|
| 118 | + return new NodeDocStart($nodeString, $line); |
|
| 119 | + } elseif (preg_match(Regex::ITEM, ltrim($nodeString))) { |
|
| 120 | + return new NodeItem($nodeString, $line); |
|
| 121 | + } else { |
|
| 114 | 122 | return new NodeScalar($nodeString, $line); |
| 115 | 123 | } |
| 116 | 124 | } |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | elseif (preg_match(Regex::KEY, $trimmed, $matches)) return new NodeKey($nodeString, $line, $matches); |
| 22 | 22 | else { |
| 23 | 23 | $first = $trimmed[0]; |
| 24 | - $stringGroups = ["-" ,'>|' ,'"\'',"#%" ,"{[" ,":?" ,'*&!']; |
|
| 25 | - $methodGroups = ['Hyphen','Literal','Quoted','Special','Compact','SetElement','NodeAction']; |
|
| 24 | + $stringGroups = ["-", '>|', '"\'', "#%", "{[", ":?", '*&!']; |
|
| 25 | + $methodGroups = ['Hyphen', 'Literal', 'Quoted', 'Special', 'Compact', 'SetElement', 'NodeAction']; |
|
| 26 | 26 | foreach ($stringGroups as $groupIndex => $stringRef) { |
| 27 | 27 | if (is_int(strpos($stringRef, $first))) { |
| 28 | 28 | $methodName = 'on'.$methodGroups[$groupIndex]; |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | if (!preg_match(Regex::NODE_ACTIONS, trim($nodeString), $matches)) { |
| 128 | 128 | return new NodeScalar($nodeString, $line); |
| 129 | 129 | } |
| 130 | - $action = trim($matches['action']);//var_dump($matches); |
|
| 130 | + $action = trim($matches['action']); //var_dump($matches); |
|
| 131 | 131 | switch ($action[0]) { |
| 132 | - case '!': return new NodeTag ($nodeString, $line); |
|
| 132 | + case '!': return new NodeTag($nodeString, $line); |
|
| 133 | 133 | case '&': return new NodeAnchor($nodeString, $line); |
| 134 | 134 | case '*': return new NodeAnchor($nodeString, $line); |
| 135 | 135 | default: |
@@ -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) |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | && !($child instanceof NodeDirective) |
| 52 | 52 | && !($child instanceof NodeBlank) |
| 53 | 53 | && !($child instanceof NodeDocstart |
| 54 | - && is_null($child->value)) ) return true; |
|
| 54 | + && is_null($child->value))) return true; |
|
| 55 | 55 | } |
| 56 | 56 | return false; |
| 57 | 57 | } |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | public function push($node) |
| 60 | 60 | { |
| 61 | 61 | $type = null; |
| 62 | - if ($node instanceof NodeItem ) $type = self::SEQUENCE; |
|
| 62 | + if ($node instanceof NodeItem) $type = self::SEQUENCE; |
|
| 63 | 63 | elseif ($node instanceof NodeKey) $type = self::MAPPING; |
| 64 | 64 | elseif ($node instanceof NodeSetKey |
| 65 | 65 | || $node instanceof NodeSetValue) { |
| 66 | 66 | $type = self::SET; |
| 67 | - } elseif ($node instanceof NodeScalar ){ |
|
| 67 | + } elseif ($node instanceof NodeScalar) { |
|
| 68 | 68 | $type = self::MULTILINE; |
| 69 | 69 | } |
| 70 | 70 | if (!is_null($type) && $this->checkTypeCoherence($type)) { |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $output = trim($first->raw); |
| 127 | 127 | foreach ($list as $child) { |
| 128 | 128 | if ($child instanceof NodeScalar) { |
| 129 | - $separator = isset($output[-1]) && $output[-1] === "\n" ? '' : ' '; |
|
| 129 | + $separator = isset($output[-1]) && $output[-1] === "\n" ? '' : ' '; |
|
| 130 | 130 | $output .= $separator.trim($child->raw); |
| 131 | 131 | } elseif ($child instanceof NodeBlank) { |
| 132 | 132 | $output .= "\n"; |
@@ -146,10 +146,10 @@ discard block |
||
| 146 | 146 | if ($child instanceof NodeComment) { |
| 147 | 147 | // $child->build(); |
| 148 | 148 | } else { |
| 149 | - if($child->value instanceof NodeComment) { |
|
| 149 | + if ($child->value instanceof NodeComment) { |
|
| 150 | 150 | // $child->value->build(); |
| 151 | 151 | // $child->value = null; |
| 152 | - } elseif($child->value instanceof NodeList) { |
|
| 152 | + } elseif ($child->value instanceof NodeList) { |
|
| 153 | 153 | $child->value = $child->value->filterComment(); |
| 154 | 154 | } |
| 155 | 155 | $out->push($child); |
@@ -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 ){ |
@@ -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 | } |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | $buffer->push($child); |
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | - $documents[] = self::buildDocument($buffer, count($documents) +1); |
|
| 48 | + $documents[] = self::buildDocument($buffer, count($documents) + 1); |
|
| 49 | 49 | } catch (\Exception|\Error|\ParseError $e) { |
| 50 | 50 | throw new \Exception($e->getMessage(), 1, $e); |
| 51 | 51 | } |
@@ -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 (preg_match(Regex::OCTAL_NUM, $v)) return intval(base_convert($v, 8, 10)); |
|
| 117 | - if (preg_match(Regex::HEX_NUM, $v)) return intval(base_convert($v, 16, 10)); |
|
| 120 | + if (preg_match(Regex::OCTAL_NUM, $v)) { |
|
| 121 | + return intval(base_convert($v, 8, 10)); |
|
| 122 | + } |
|
| 123 | + if (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 | |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | if (is_null($this->value)) { |
| 39 | 39 | return null; |
| 40 | 40 | } else { |
| 41 | - if ($this->value instanceof NodeTag){ |
|
| 41 | + if ($this->value instanceof NodeTag) { |
|
| 42 | 42 | $parent->addTag($this->value->tag); |
| 43 | 43 | $this->value->build($parent); |
| 44 | 44 | } else { |
@@ -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); |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | if ($value instanceof NodeKey && $child instanceof NodeKey) { |
| 29 | 29 | if ($value->indent === $child->indent) { |
| 30 | 30 | return parent::add($child); |
| 31 | - } elseif ($value->isAwaitingChild($child)){ |
|
| 31 | + } elseif ($value->isAwaitingChild($child)) { |
|
| 32 | 32 | return $value->add($child); |
| 33 | 33 | } else { |
| 34 | 34 | // throw new \ParseError('key ('.$value->identifier.')@'.$value->line.' has already a value', 1); |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | public function setIdentifier(string $keyString) |
| 28 | 28 | { |
| 29 | 29 | if ($keyString === '') { |
| 30 | - throw new \ParseError(sprintf(self::ERROR_NO_KEYNAME, $this->line)); |
|
| 30 | + throw new \ParseError(sprintf(self::ERROR_NO_KEYNAME, $this->line)); |
|
| 31 | 31 | } else { |
| 32 | 32 | $keyNode = NodeFactory::get($keyString); |
| 33 | 33 | if (!is_null($keyNode->anchor)) { |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | public function add(Node $child):Node |
| 54 | 54 | { |
| 55 | - if ($this->value instanceof Node && Yaml::isOneOf($this->value, ['NodeLit','NodeLitFolded', 'NodeAnchor'])) { |
|
| 55 | + if ($this->value instanceof Node && Yaml::isOneOf($this->value, ['NodeLit', 'NodeLitFolded', 'NodeAnchor'])) { |
|
| 56 | 56 | return $this->value->add($child); |
| 57 | 57 | } else { |
| 58 | 58 | return parent::add($child); |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | if ($current instanceof NodeComment) { |
| 88 | 88 | return true; |
| 89 | 89 | } |
| 90 | - if($current instanceof NodeScalar) { |
|
| 90 | + if ($current instanceof NodeScalar) { |
|
| 91 | 91 | return Yaml::isOneOf($node, ['NodeScalar', 'NodeBlank']); |
| 92 | 92 | } |
| 93 | 93 | if ($current instanceof NodeItem) { |
@@ -21,8 +21,8 @@ |
||
| 21 | 21 | $result = ''; |
| 22 | 22 | $list = $value->filterComment(); |
| 23 | 23 | if ($this->identifier !== '+') { |
| 24 | - self::litteralStripLeading($list); |
|
| 25 | - self::litteralStripTrailing($list); |
|
| 24 | + self::litteralStripLeading($list); |
|
| 25 | + self::litteralStripTrailing($list); |
|
| 26 | 26 | } |
| 27 | 27 | if ($list->count()) { |
| 28 | 28 | $refSeparator = ' '; |
@@ -31,14 +31,14 @@ |
||
| 31 | 31 | $result = $this->getChildValue($first, $indent); |
| 32 | 32 | foreach ($list as $child) { |
| 33 | 33 | $separator = ($result && $result[-1] === "\n") ? '' : $refSeparator; |
| 34 | - if($child->indent > $indent || $child instanceof NodeBlank) { |
|
| 34 | + if ($child->indent > $indent || $child instanceof NodeBlank) { |
|
| 35 | 35 | $separator = "\n"; |
| 36 | 36 | } |
| 37 | 37 | $val = $this->getChildValue($child, $indent); |
| 38 | 38 | if ($child->value instanceof NodeList) { |
| 39 | 39 | $val = "\n".$this->getFinalString($child->value, $indent); |
| 40 | 40 | } |
| 41 | - $result .= $separator .$val; |
|
| 41 | + $result .= $separator.$val; |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | return $result; |