@@ -13,7 +13,7 @@ |
||
| 13 | 13 | public function __construct(string $nodeString, int $line) |
| 14 | 14 | { |
| 15 | 15 | parent::__construct($nodeString, $line); |
| 16 | - preg_match_all(Regex::MAPPING_VALUES, trim(substr(trim($nodeString), 1,-1)), $matches); |
|
| 16 | + preg_match_all(Regex::MAPPING_VALUES, trim(substr(trim($nodeString), 1, -1)), $matches); |
|
| 17 | 17 | foreach ($matches['k'] as $index => $property) { |
| 18 | 18 | $pair = $property.': '.trim($matches['v'][$index]); |
| 19 | 19 | $child = NodeFactory::get($pair, $line); |
@@ -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) { |
@@ -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 (!Yaml::isOneOf($child, ['NodeScalar', 'NodeBlank', 'NodeComment', 'NodeQuoted'])) { |
| 31 | 33 | $candidate = new NodeScalar((string) $child->raw, $child->line); |
@@ -107,7 +107,9 @@ |
||
| 107 | 107 | { |
| 108 | 108 | foreach ($comparison as $className) { |
| 109 | 109 | $fqn = __NAMESPACE__."\\Yaml\\$className"; |
| 110 | - if ($subject instanceof $fqn) return true; |
|
| 110 | + if ($subject instanceof $fqn) { |
|
| 111 | + return true; |
|
| 112 | + } |
|
| 111 | 113 | } |
| 112 | 114 | return false; |
| 113 | 115 | } |
@@ -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: |
@@ -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 ){ |
@@ -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 | |