@@ -43,7 +43,7 @@ |
||
43 | 43 | |
44 | 44 | public function getTargetOnLessIndent(Node &$node):Node |
45 | 45 | { |
46 | - if ($node instanceof NodeScalar || $node instanceof NodeBlank ) { |
|
46 | + if ($node instanceof NodeScalar || $node instanceof NodeBlank) { |
|
47 | 47 | return $this->getParent(); |
48 | 48 | } else { |
49 | 49 | return $this->getParent($node->indent); |
@@ -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 |
@@ -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 { |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | if ($this->tag) $props['tag'] = "($this->tag)"; |
216 | 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 | } |
@@ -69,7 +69,7 @@ |
||
69 | 69 | return $this->_anchors[$name]; |
70 | 70 | } |
71 | 71 | throw new \UnexpectedValueException(sprintf(self::UNKNOWN_REFERENCE, |
72 | - $name, implode(',',array_keys($this->_anchors))) |
|
72 | + $name, implode(',', array_keys($this->_anchors))) |
|
73 | 73 | ); |
74 | 74 | } |
75 | 75 |
@@ -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, ltrim($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: |
@@ -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 | } |
@@ -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 | } |
@@ -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); |
@@ -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 |
@@ -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 (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, '.')) ? intval($v) : floatval($v); |
119 | 127 | } |
120 | 128 |
@@ -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 | } |
@@ -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 { |