@@ -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 | } |
@@ -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) |
@@ -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 ){ |
@@ -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 | } |
@@ -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 | } |
@@ -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 | |
@@ -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 { |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | $result = ''; |
| 23 | 23 | $list = $value->filterComment(); |
| 24 | 24 | if ($this->identifier !== '+') { |
| 25 | - self::litteralStripTrailing($list); |
|
| 25 | + self::litteralStripTrailing($list); |
|
| 26 | 26 | } |
| 27 | 27 | if ($list->count()) { |
| 28 | 28 | $list->setIteratorMode(NodeList::IT_MODE_DELETE); |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | if ($value instanceof NodeKey && $child instanceof NodeKey) { |
| 29 | 29 | if ($value->indent === $child->indent) { |
| 30 | 30 | return parent::add($child); |
| 31 | - } elseif ($value->isAwaitingChild($child)){ |
|
| 31 | + } elseif ($value->isAwaitingChild($child)) { |
|
| 32 | 32 | return $value->add($child); |
| 33 | 33 | } else { |
| 34 | 34 | // throw new \ParseError('key ('.$value->identifier.')@'.$value->line.' has already a value', 1); |
@@ -21,8 +21,8 @@ |
||
| 21 | 21 | $result = ''; |
| 22 | 22 | $list = $value->filterComment(); |
| 23 | 23 | if ($this->identifier !== '+') { |
| 24 | - self::litteralStripLeading($list); |
|
| 25 | - self::litteralStripTrailing($list); |
|
| 24 | + self::litteralStripLeading($list); |
|
| 25 | + self::litteralStripTrailing($list); |
|
| 26 | 26 | } |
| 27 | 27 | if ($list->count()) { |
| 28 | 28 | $refSeparator = ' '; |
@@ -32,10 +32,10 @@ |
||
| 32 | 32 | $result = $this->getChildValue($first, $indent); |
| 33 | 33 | foreach ($list as $child) { |
| 34 | 34 | $separator = ($result && $result[-1] === "\n") ? '' : $refSeparator; |
| 35 | - if($child->indent > $indent || $child instanceof NodeBlank) { |
|
| 35 | + if ($child->indent > $indent || $child instanceof NodeBlank) { |
|
| 36 | 36 | $separator = "\n"; |
| 37 | 37 | } |
| 38 | - $result .= $separator .$this->getChildValue($child, $indent); |
|
| 38 | + $result .= $separator.$this->getChildValue($child, $indent); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | return $result; |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | //public |
| 16 | 16 | /* @var null|string */ |
| 17 | 17 | public static $error; |
| 18 | - public const IGNORE_DIRECTIVES = 1;//DONT include_directive |
|
| 19 | - public const IGNORE_COMMENTS = 2;//DONT include_comments |
|
| 20 | - public const NO_PARSING_EXCEPTIONS = 4;//DONT throw Exception on parsing errors |
|
| 21 | - public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object |
|
| 18 | + public const IGNORE_DIRECTIVES = 1; //DONT include_directive |
|
| 19 | + public const IGNORE_COMMENTS = 2; //DONT include_comments |
|
| 20 | + public const NO_PARSING_EXCEPTIONS = 4; //DONT throw Exception on parsing errors |
|
| 21 | + public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object |
|
| 22 | 22 | |
| 23 | 23 | //private |
| 24 | 24 | /* @var null|false|array */ |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | $previous = $target->add($node); |
| 130 | 130 | } |
| 131 | 131 | $this->attachBlankLines($previous); |
| 132 | - if ($this->_debug === 1){ |
|
| 132 | + if ($this->_debug === 1) { |
|
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | return Builder::buildContent($root, $this->_debug); |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | { |
| 171 | 171 | $deepest = $previous->getDeepestNode(); |
| 172 | 172 | if ($deepest instanceof NodePartial) { |
| 173 | - return $deepest->specialProcess($current, $this->_blankBuffer); |
|
| 174 | - } elseif(!($current instanceof NodePartial)) { |
|
| 173 | + return $deepest->specialProcess($current, $this->_blankBuffer); |
|
| 174 | + } elseif (!($current instanceof NodePartial)) { |
|
| 175 | 175 | return $current->specialProcess($previous, $this->_blankBuffer); |
| 176 | 176 | } |
| 177 | 177 | return false; |
@@ -125,8 +125,12 @@ |
||
| 125 | 125 | try { |
| 126 | 126 | foreach ($generator as $lineNb => $lineString) { |
| 127 | 127 | $node = NodeFactory::get($lineString, $lineNb); |
| 128 | - if ($this->_debug === 1) echo get_class($node)."\n"; |
|
| 129 | - if ($this->needsSpecialProcess($node, $previous)) continue; |
|
| 128 | + if ($this->_debug === 1) { |
|
| 129 | + echo get_class($node)."\n"; |
|
| 130 | + } |
|
| 131 | + if ($this->needsSpecialProcess($node, $previous)) { |
|
| 132 | + continue; |
|
| 133 | + } |
|
| 130 | 134 | $this->attachBlankLines($previous); |
| 131 | 135 | switch ($node->indent <=> $previous->indent) { |
| 132 | 136 | case -1: $target = $previous->getTargetOnLessIndent($node); |
@@ -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); |