@@ -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 ((bool) 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 ((bool) 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 ((bool) preg_match(Regex::MAPPING, trim($nodeString))) return new NodeCompactMapping($nodeString, $line); |
|
| 95 | - elseif ((bool) 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 ((bool) preg_match(Regex::MAPPING, trim($nodeString))) { |
|
| 99 | + return new NodeCompactMapping($nodeString, $line); |
|
| 100 | + } elseif ((bool) 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 ((bool) 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 ((bool) 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 | } |
@@ -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 | |