@@ -25,7 +25,9 @@ |
||
| 25 | 25 | |
| 26 | 26 | public function add(Node $child):Node |
| 27 | 27 | { |
| 28 | - if (is_null($this->value)) $this->value = new NodeList(); |
|
| 28 | + if (is_null($this->value)) { |
|
| 29 | + $this->value = new NodeList(); |
|
| 30 | + } |
|
| 29 | 31 | $candidate = $child; |
| 30 | 32 | if (!isOneOf($child, ['NodeScalar', 'NodeBlank', 'NodeComment', 'NodeQuoted'])) { |
| 31 | 33 | $candidate = new NodeScalar((string) $child->raw, $child->line); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | { |
| 34 | 34 | $reflectAPI = new \ReflectionClass(self::class); |
| 35 | 35 | $methodsList = []; |
| 36 | - $list = $reflectAPI->getMethods(RM::IS_FINAL | RM::IS_STATIC & RM::IS_PRIVATE); |
|
| 36 | + $list = $reflectAPI->getMethods(RM::IS_FINAL|RM::IS_STATIC & RM::IS_PRIVATE); |
|
| 37 | 37 | foreach ($list as $method) { |
| 38 | 38 | $methodsList[$method->name] = $method->getClosure(); |
| 39 | 39 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | foreach ($node as $key => $child) { |
| 104 | 104 | $list[] = self::strHandler($child)->raw; |
| 105 | 105 | } |
| 106 | - return new NodeScalar(implode('',$list), 0); |
|
| 106 | + return new NodeScalar(implode('', $list), 0); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | public static function transform(string $identifier, $value) |
| 171 | 171 | { |
| 172 | 172 | if (self::isKnown($identifier)) { |
| 173 | - if (!($value instanceof Node) && !($value instanceof NodeList) ) { |
|
| 173 | + if (!($value instanceof Node) && !($value instanceof NodeList)) { |
|
| 174 | 174 | throw new \Exception(sprintf(self::WRONG_VALUE, $identifier, gettype($value))); |
| 175 | 175 | } |
| 176 | 176 | return self::$registeredHandlers[$identifier]($value); |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function getParent(int $indent = null):Node |
| 67 | 67 | { |
| 68 | - if (!is_int($indent)){ |
|
| 68 | + if (!is_int($indent)) { |
|
| 69 | 69 | if ($this->_parent instanceof Node) { |
| 70 | 70 | return $this->_parent; |
| 71 | 71 | } else { |
@@ -213,9 +213,9 @@ discard block |
||
| 213 | 213 | if ($this->identifier) $props['identifier'] = "($this->identifier)"; |
| 214 | 214 | if ($this->_anchor) $props['_anchor'] = "($this->_anchor)"; |
| 215 | 215 | if ($this->_tag) $props['_tag'] = "($this->_tag)"; |
| 216 | - if ($this->value) $props['value'] = $this->value; |
|
| 216 | + if ($this->value) $props['value'] = $this->value; |
|
| 217 | 217 | // $props['value'] = $this->value; |
| 218 | - $props['raw'] = $this->raw; |
|
| 218 | + $props['raw'] = $this->raw; |
|
| 219 | 219 | if (!$this->_parent) $props['parent'] = 'NO PARENT!!!'; |
| 220 | 220 | return $props; |
| 221 | 221 | } |
@@ -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 | } |
@@ -108,7 +108,9 @@ |
||
| 108 | 108 | { |
| 109 | 109 | foreach ($comparison as $className) { |
| 110 | 110 | $fqn = __NAMESPACE__."\\$className"; |
| 111 | - if ($subject instanceof $fqn) return true; |
|
| 111 | + if ($subject instanceof $fqn) { |
|
| 112 | + return true; |
|
| 113 | + } |
|
| 112 | 114 | } |
| 113 | 115 | return false; |
| 114 | 116 | } |
| 115 | 117 | \ No newline at end of file |
@@ -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 | } |
@@ -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) |