@@ -92,10 +92,13 @@ discard block |
||
| 92 | 92 | final private static function onCompact(string $nodeString, int $line):Node |
| 93 | 93 | { |
| 94 | 94 | $json = json_decode($nodeString, false, 512, self::JSON_OPTIONS); |
| 95 | - if (json_last_error() === \JSON_ERROR_NONE) return new NodeJSON($nodeString, $line, $json); |
|
| 96 | - elseif (preg_match(Regex::MAPPING, $nodeString)) return new NodeCompactMapping($nodeString, $line); |
|
| 97 | - elseif (preg_match(Regex::SEQUENCE, $nodeString)) return new NodeCompactSequence($nodeString, $line); |
|
| 98 | - else { |
|
| 95 | + if (json_last_error() === \JSON_ERROR_NONE) { |
|
| 96 | + return new NodeJSON($nodeString, $line, $json); |
|
| 97 | + } elseif (preg_match(Regex::MAPPING, $nodeString)) { |
|
| 98 | + return new NodeCompactMapping($nodeString, $line); |
|
| 99 | + } elseif (preg_match(Regex::SEQUENCE, $nodeString)) { |
|
| 100 | + return new NodeCompactSequence($nodeString, $line); |
|
| 101 | + } else { |
|
| 99 | 102 | return new NodePartial($nodeString, $line); |
| 100 | 103 | } |
| 101 | 104 | } |
@@ -110,9 +113,11 @@ discard block |
||
| 110 | 113 | */ |
| 111 | 114 | final private static function onHyphen(string $nodeString, int $line):Node |
| 112 | 115 | { |
| 113 | - if (substr($nodeString, 0, 3) === '---') return new NodeDocStart($nodeString, $line); |
|
| 114 | - elseif (preg_match(Regex::ITEM, $nodeString)) return new NodeItem($nodeString, $line); |
|
| 115 | - else { |
|
| 116 | + if (substr($nodeString, 0, 3) === '---') { |
|
| 117 | + return new NodeDocStart($nodeString, $line); |
|
| 118 | + } elseif (preg_match(Regex::ITEM, $nodeString)) { |
|
| 119 | + return new NodeItem($nodeString, $line); |
|
| 120 | + } else { |
|
| 116 | 121 | return new NodeScalar($nodeString, $line); |
| 117 | 122 | } |
| 118 | 123 | } |
@@ -126,10 +131,13 @@ discard block |
||
| 126 | 131 | */ |
| 127 | 132 | final private static function onNodeAction(string $nodeString, int $line):Node |
| 128 | 133 | { |
| 129 | - if ($nodeString[0] === '!') return new NodeTag($nodeString, $line); |
|
| 130 | - elseif ($nodeString[0] === '&') return new NodeRefDef($nodeString, $line); |
|
| 131 | - elseif ($nodeString[0] === '*') return new NodeRefCall($nodeString, $line); |
|
| 132 | - else { |
|
| 134 | + if ($nodeString[0] === '!') { |
|
| 135 | + return new NodeTag($nodeString, $line); |
|
| 136 | + } elseif ($nodeString[0] === '&') { |
|
| 137 | + return new NodeRefDef($nodeString, $line); |
|
| 138 | + } elseif ($nodeString[0] === '*') { |
|
| 139 | + return new NodeRefCall($nodeString, $line); |
|
| 140 | + } else { |
|
| 133 | 141 | throw new \ParseError("Not a action node !! $nodeString[0]"); |
| 134 | 142 | } |
| 135 | 143 | } |
@@ -137,9 +145,11 @@ discard block |
||
| 137 | 145 | |
| 138 | 146 | final private static function onLiteral(string $nodeString, int $line):Node |
| 139 | 147 | { |
| 140 | - if ($nodeString[0] === '>') return new NodeLitFolded($nodeString, $line); |
|
| 141 | - elseif ($nodeString[0] === '|') return new NodeLit($nodeString, $line); |
|
| 142 | - else { |
|
| 148 | + if ($nodeString[0] === '>') { |
|
| 149 | + return new NodeLitFolded($nodeString, $line); |
|
| 150 | + } elseif ($nodeString[0] === '|') { |
|
| 151 | + return new NodeLit($nodeString, $line); |
|
| 152 | + } else { |
|
| 143 | 153 | throw new \ParseError("Not a literal node !! $nodeString[0]"); |
| 144 | 154 | } |
| 145 | 155 | } |
@@ -21,12 +21,12 @@ |
||
| 21 | 21 | private const NO_NAME = '%s Error: a tag MUST have a name'; |
| 22 | 22 | private const WRONG_VALUE = "Error : cannot transform tag '%s' for type '%s'"; |
| 23 | 23 | private const LEGACY_TAGS_HANDLERS = ['!str' => 'strHandler', |
| 24 | - '!binary' => 'binaryHandler', |
|
| 25 | - '!set' => 'setHandler', |
|
| 26 | - '!omap' => 'mapHandler', |
|
| 27 | - 'php/object' => 'symfonyPHPobjectHandler', |
|
| 28 | - '!inline' => 'inlineHandler', |
|
| 29 | - '!long' => 'longHandler']; |
|
| 24 | + '!binary' => 'binaryHandler', |
|
| 25 | + '!set' => 'setHandler', |
|
| 26 | + '!omap' => 'mapHandler', |
|
| 27 | + 'php/object' => 'symfonyPHPobjectHandler', |
|
| 28 | + '!inline' => 'inlineHandler', |
|
| 29 | + '!long' => 'longHandler']; |
|
| 30 | 30 | |
| 31 | 31 | public static $registeredHandlers = []; |
| 32 | 32 | |
@@ -45,7 +45,9 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | $this->tagName = $tagName; |
| 47 | 47 | $this->raw = $raw; |
| 48 | - if (empty(self::$registeredHandlers)) $this->registerLegacyTags(); |
|
| 48 | + if (empty(self::$registeredHandlers)) { |
|
| 49 | + $this->registerLegacyTags(); |
|
| 50 | + } |
|
| 49 | 51 | } |
| 50 | 52 | |
| 51 | 53 | /** |
@@ -143,7 +145,9 @@ discard block |
||
| 143 | 145 | private final static function strHandler(object $node, object &$parent = null) |
| 144 | 146 | { |
| 145 | 147 | if ($node instanceof Node) { |
| 146 | - if ($node instanceof NodeKey) $node->build($parent); |
|
| 148 | + if ($node instanceof NodeKey) { |
|
| 149 | + $node->build($parent); |
|
| 150 | + } |
|
| 147 | 151 | return ltrim($node->raw); |
| 148 | 152 | // } elseif ($node instanceof NodeList) { |
| 149 | 153 | // return Builder::buildLitteral($node); |
@@ -41,7 +41,9 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public static function toString($dataType, int $options = null):string |
| 43 | 43 | { |
| 44 | - if (is_null($dataType)) throw new \Exception(self::class.": No content to convert to Yaml"); |
|
| 44 | + if (is_null($dataType)) { |
|
| 45 | + throw new \Exception(self::class.": No content to convert to Yaml"); |
|
| 46 | + } |
|
| 45 | 47 | self::$options = is_int($options) ? $options : self::OPTIONS; |
| 46 | 48 | self::$result = new DLL; |
| 47 | 49 | if ($dataType instanceof YamlObject) { |
@@ -83,8 +85,12 @@ discard block |
||
| 83 | 85 | private static function dump($dataType, int $indent) |
| 84 | 86 | { |
| 85 | 87 | if (is_scalar($dataType)) { |
| 86 | - if ($dataType === INF) return '.inf'; |
|
| 87 | - if ($dataType === -INF) return '-.inf'; |
|
| 88 | + if ($dataType === INF) { |
|
| 89 | + return '.inf'; |
|
| 90 | + } |
|
| 91 | + if ($dataType === -INF) { |
|
| 92 | + return '-.inf'; |
|
| 93 | + } |
|
| 88 | 94 | switch (gettype($dataType)) { |
| 89 | 95 | case 'boolean': return $dataType ? 'true' : 'false'; |
| 90 | 96 | case 'float': //fall through |
@@ -106,7 +112,9 @@ discard block |
||
| 106 | 112 | */ |
| 107 | 113 | private static function dumpYamlObject(YamlObject $obj) |
| 108 | 114 | { |
| 109 | - if ($obj->hasDocStart() && self::$result instanceof DLL) self::$result->push("---"); |
|
| 115 | + if ($obj->hasDocStart() && self::$result instanceof DLL) { |
|
| 116 | + self::$result->push("---"); |
|
| 117 | + } |
|
| 110 | 118 | // self::dump($obj, 0); |
| 111 | 119 | if (count($obj) > 0) { |
| 112 | 120 | self::dumpArray($obj->getArrayCopy(), 0); |
@@ -182,9 +190,13 @@ discard block |
||
| 182 | 190 | self::add(self::dump($obj->value, $indent + self::INDENT), $indent + self::INDENT); |
| 183 | 191 | } |
| 184 | 192 | } |
| 185 | - if ($obj instanceof Compact) return self::dumpCompact($obj, $indent); |
|
| 193 | + if ($obj instanceof Compact) { |
|
| 194 | + return self::dumpCompact($obj, $indent); |
|
| 195 | + } |
|
| 186 | 196 | //TODO: consider dumping datetime as date strings according to a format provided by user or default |
| 187 | - if ($obj instanceof \DateTime) return $obj->format(self::DATE_FORMAT); |
|
| 197 | + if ($obj instanceof \DateTime) { |
|
| 198 | + return $obj->format(self::DATE_FORMAT); |
|
| 199 | + } |
|
| 188 | 200 | $propList = get_object_vars($obj); |
| 189 | 201 | foreach ($propList as $property => $value) { |
| 190 | 202 | if (is_scalar($value) || $value instanceof Compact || $value instanceof \DateTime) { |
@@ -31,7 +31,9 @@ |
||
| 31 | 31 | $built = is_object($this->value) ? $this->value->build($parent) : null; |
| 32 | 32 | $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
| 33 | 33 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
| 34 | - if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
|
| 34 | + if (empty($key)) { |
|
| 35 | + throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
|
| 36 | + } |
|
| 35 | 37 | $parent->{trim($key, '\'" ')} = null; |
| 36 | 38 | } |
| 37 | 39 | |
@@ -10,15 +10,15 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | class NodeComment extends Node |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * According to the current Node type and deepest value |
|
| 15 | - * this indicates if self::parse skips (or not) the parent and previous assignment |
|
| 16 | - * |
|
| 17 | - * @param Node $target The parent target Node |
|
| 18 | - * |
|
| 19 | - * @return boolean True if context, False otherwiser |
|
| 20 | - * @todo is this really necessary according ot other checkings out there ? |
|
| 21 | - */ |
|
| 13 | + /** |
|
| 14 | + * According to the current Node type and deepest value |
|
| 15 | + * this indicates if self::parse skips (or not) the parent and previous assignment |
|
| 16 | + * |
|
| 17 | + * @param Node $target The parent target Node |
|
| 18 | + * |
|
| 19 | + * @return boolean True if context, False otherwiser |
|
| 20 | + * @todo is this really necessary according ot other checkings out there ? |
|
| 21 | + */ |
|
| 22 | 22 | public function skipOnContext(Node &$target):bool |
| 23 | 23 | { |
| 24 | 24 | if (!$this->identifier) { |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | return false; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function needsSpecialProcess(Node &$previous, array &$emptyLines):bool |
|
| 32 | - { |
|
| 31 | + public function needsSpecialProcess(Node &$previous, array &$emptyLines):bool |
|
| 32 | + { |
|
| 33 | 33 | $deepest = $previous->getDeepestNode(); |
| 34 | 34 | if (!($previous->getParent() instanceof NodeLiterals) |
| 35 | 35 | && !($deepest instanceof NodeLiterals)) { |
@@ -37,5 +37,5 @@ discard block |
||
| 37 | 37 | return true; |
| 38 | 38 | } |
| 39 | 39 | return false; |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | } |
| 42 | 42 | \ No newline at end of file |
@@ -76,8 +76,8 @@ |
||
| 76 | 76 | } |
| 77 | 77 | if ($list->count()) { |
| 78 | 78 | if ($this->modifier !== '+') { |
| 79 | - self::litteralStripLeading($list); |
|
| 80 | - self::litteralStripTrailing($list); |
|
| 79 | + self::litteralStripLeading($list); |
|
| 80 | + self::litteralStripTrailing($list); |
|
| 81 | 81 | } |
| 82 | 82 | $first = $list->shift(); |
| 83 | 83 | $refIndent = $first->indent ?? 0; |
@@ -16,8 +16,8 @@ |
||
| 16 | 16 | $result = ''; |
| 17 | 17 | if ($list->count()) { |
| 18 | 18 | if ($modifier !== '+') { |
| 19 | - self::litteralStripLeading($list); |
|
| 20 | - self::litteralStripTrailing($list); |
|
| 19 | + self::litteralStripLeading($list); |
|
| 20 | + self::litteralStripTrailing($list); |
|
| 21 | 21 | } |
| 22 | 22 | $first = $list->shift(); |
| 23 | 23 | $refIndent = $first->indent ?? 0; |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | // } else { |
| 22 | 22 | // $this->specialProcess($previous, $emptyLines); |
| 23 | 23 | // } |
| 24 | - if ($previous instanceof NodeScalar) $emptyLines[] = $this->setParent($previous->getParent()); |
|
| 24 | + if ($previous instanceof NodeScalar) $emptyLines[] = $this->setParent($previous->getParent()); |
|
| 25 | 25 | if ($deepest instanceof NodeLiterals) $emptyLines[] = $this->setParent($deepest); |
| 26 | 26 | return true; |
| 27 | 27 | } |
@@ -21,8 +21,12 @@ |
||
| 21 | 21 | // } else { |
| 22 | 22 | // $this->specialProcess($previous, $emptyLines); |
| 23 | 23 | // } |
| 24 | - if ($previous instanceof NodeScalar) $emptyLines[] = $this->setParent($previous->getParent()); |
|
| 25 | - if ($deepest instanceof NodeLiterals) $emptyLines[] = $this->setParent($deepest); |
|
| 24 | + if ($previous instanceof NodeScalar) { |
|
| 25 | + $emptyLines[] = $this->setParent($previous->getParent()); |
|
| 26 | + } |
|
| 27 | + if ($deepest instanceof NodeLiterals) { |
|
| 28 | + $emptyLines[] = $this->setParent($deepest); |
|
| 29 | + } |
|
| 26 | 30 | return true; |
| 27 | 31 | } |
| 28 | 32 | |
@@ -28,7 +28,9 @@ |
||
| 28 | 28 | public static function buildReference($node, $parent) |
| 29 | 29 | { |
| 30 | 30 | $tmp = is_null($node->value) ? null : $node->value->build($parent); |
| 31 | - if ($node instanceof NodeRefDef) Builder::$_root->addReference($node->identifier, $tmp); |
|
| 31 | + if ($node instanceof NodeRefDef) { |
|
| 32 | + Builder::$_root->addReference($node->identifier, $tmp); |
|
| 33 | + } |
|
| 32 | 34 | return Builder::$_root->getReference($node->identifier); |
| 33 | 35 | } |
| 34 | 36 | } |
| 35 | 37 | \ No newline at end of file |