@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | foreach ($array as $key => $item) { |
| 117 | 117 | $lineStart = current($refKeys) === $key ? "- " : "- $key: "; |
| 118 | 118 | if (is_scalar($item)) { |
| 119 | - self::add($lineStart.self::dump($item,0), $indent); |
|
| 119 | + self::add($lineStart.self::dump($item, 0), $indent); |
|
| 120 | 120 | } else { |
| 121 | 121 | self::add($lineStart, $indent); |
| 122 | 122 | self::dump($item, $indent + self::INDENT); |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | if (is_array($subject) || $subject instanceof \ArrayIterator) { |
| 164 | 164 | $max = count($subject); |
| 165 | 165 | $objectAsArray = is_array($subject) ? $subject : $subject->getArrayCopy(); |
| 166 | - if(array_keys($objectAsArray) !== range(0, $max)) { |
|
| 166 | + if (array_keys($objectAsArray) !== range(0, $max)) { |
|
| 167 | 167 | $pairs = $objectAsArray; |
| 168 | 168 | } else { |
| 169 | - $valuesList = array_map(self::dump, $objectAsArray, array_fill( 0 , $max , $indent )); |
|
| 169 | + $valuesList = array_map(self::dump, $objectAsArray, array_fill(0, $max, $indent)); |
|
| 170 | 170 | return '['.implode(', ', $valuesList).']'; |
| 171 | 171 | } |
| 172 | 172 | } else { |
@@ -45,16 +45,16 @@ |
||
| 45 | 45 | public function forceType() |
| 46 | 46 | { |
| 47 | 47 | if (is_null($this->type)) { |
| 48 | - $childTypes = $this->getTypes(); |
|
| 49 | - if ($childTypes & (Y::KEY|Y::SET_KEY)) { |
|
| 50 | - if ($childTypes & Y::ITEM) { |
|
| 48 | + $childTypes = $this->getTypes(); |
|
| 49 | + if ($childTypes&(Y::KEY|Y::SET_KEY)) { |
|
| 50 | + if ($childTypes&Y::ITEM) { |
|
| 51 | 51 | throw new \ParseError(self::class.": Error conflicting types found"); |
| 52 | 52 | } |
| 53 | 53 | $this->type = Y::MAPPING; |
| 54 | 54 | } else { |
| 55 | - if ($childTypes & Y::ITEM) { |
|
| 55 | + if ($childTypes&Y::ITEM) { |
|
| 56 | 56 | $this->type = Y::SEQUENCE; |
| 57 | - } elseif (!($childTypes & Y::COMMENT)) { |
|
| 57 | + } elseif (!($childTypes&Y::COMMENT)) { |
|
| 58 | 58 | $this->type = Y::LITT_FOLDED; |
| 59 | 59 | } |
| 60 | 60 | } |
@@ -43,9 +43,9 @@ |
||
| 43 | 43 | public function __call($funcName, $arguments) |
| 44 | 44 | { |
| 45 | 45 | $reflectAPI = new \ReflectionClass(get_class($this->__yaml__object__api)); |
| 46 | - $getName = function ($o) { return $o->name; }; |
|
| 46 | + $getName = function($o) { return $o->name; }; |
|
| 47 | 47 | $publicApi = array_map($getName, $reflectAPI->getMethods(\ReflectionMethod::IS_PUBLIC)); |
| 48 | - if (!in_array($funcName, $publicApi) ) { |
|
| 48 | + if (!in_array($funcName, $publicApi)) { |
|
| 49 | 49 | throw new \BadMethodCallException(sprintf(self::UNDEFINED_METHOD, $funcName, implode(",", $publicApi)), 1); |
| 50 | 50 | } |
| 51 | 51 | return call_user_func_array([$this->__yaml__object__api, $funcName], $arguments); |
@@ -6,13 +6,13 @@ |
||
| 6 | 6 | /** |
| 7 | 7 | * Display some use cases for Yaml library |
| 8 | 8 | */ |
| 9 | -const JSON_OPTIONS = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_LINE_TERMINATORS | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_PARTIAL_OUTPUT_ON_ERROR; |
|
| 9 | +const JSON_OPTIONS = JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_LINE_TERMINATORS|JSON_UNESCAPED_UNICODE|JSON_PRESERVE_ZERO_FRACTION|JSON_PARTIAL_OUTPUT_ON_ERROR; |
|
| 10 | 10 | |
| 11 | 11 | /* USE CASE 1 |
| 12 | 12 | * load and parse if file exists |
| 13 | 13 | */ |
| 14 | 14 | ini_set("auto_detect_line_endings", 1); |
| 15 | -$content = file_get_contents('./tests/cases/parsing/multidoc_sequence.yml');//var_dump($content); |
|
| 15 | +$content = file_get_contents('./tests/cases/parsing/multidoc_sequence.yml'); //var_dump($content); |
|
| 16 | 16 | // $content = file_get_contents('./tests/cases/examples/Example_2_17.yml');//var_dump($content); |
| 17 | 17 | $yaml = Y::parse($content, null, 3); |
| 18 | 18 | // $yaml = Y::parseFile('./references/Example 2.27.yml', null, 1); |
@@ -174,7 +174,7 @@ |
||
| 174 | 174 | elseif (in_array($first, ['?', ':'])) NodeHandlers::onSetElement($nodeValue, $this); |
| 175 | 175 | elseif (in_array($first, ['!', '&', '*'])) NodeHandlers::onNodeAction($nodeValue, $this); |
| 176 | 176 | else { |
| 177 | - $characters = [ '#' => [Y::COMMENT, $v], |
|
| 177 | + $characters = ['#' => [Y::COMMENT, $v], |
|
| 178 | 178 | '%' => [Y::DIRECTIVE, $v], |
| 179 | 179 | '>' => [Y::LITT_FOLDED, null], |
| 180 | 180 | '|' => [Y::LITT, null] |
@@ -66,28 +66,28 @@ |
||
| 66 | 66 | public static function onCompact($value, Node $node) |
| 67 | 67 | { |
| 68 | 68 | $node->value = json_decode($value, false, 512, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
| 69 | - if (json_last_error() === JSON_ERROR_NONE){ |
|
| 69 | + if (json_last_error() === JSON_ERROR_NONE) { |
|
| 70 | 70 | $node->type = Y::JSON; |
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | $node->value = new NodeList(); |
| 74 | - if (preg_match(R::MAPPING, $value)){ |
|
| 74 | + if (preg_match(R::MAPPING, $value)) { |
|
| 75 | 75 | $node->type = Y::COMPACT_MAPPING; |
| 76 | 76 | $node->value->type = Y::COMPACT_MAPPING; |
| 77 | - preg_match_all(R::MAPPING_VALUES, trim(substr($value, 1,-1)), $matches); |
|
| 77 | + preg_match_all(R::MAPPING_VALUES, trim(substr($value, 1, -1)), $matches); |
|
| 78 | 78 | foreach ($matches['k'] as $index => $property) { |
| 79 | 79 | $n = new Node('', $node->line); |
| 80 | 80 | $n->type = Y::KEY; |
| 81 | - $n->identifier = trim($property, '"\' ');//TODO : maybe check for proper quoting first ? |
|
| 81 | + $n->identifier = trim($property, '"\' '); //TODO : maybe check for proper quoting first ? |
|
| 82 | 82 | $n->value = new Node($matches['v'][$index], $node->line); |
| 83 | 83 | $node->value->push($n); |
| 84 | 84 | } |
| 85 | 85 | return; |
| 86 | 86 | } |
| 87 | - if (preg_match(R::SEQUENCE, $value)){ |
|
| 87 | + if (preg_match(R::SEQUENCE, $value)) { |
|
| 88 | 88 | $node->type = Y::COMPACT_SEQUENCE; |
| 89 | 89 | $node->value->type = Y::COMPACT_SEQUENCE; |
| 90 | - preg_match_all(R::SEQUENCE_VALUES, trim(substr($value, 1,-1)), $matches); |
|
| 90 | + preg_match_all(R::SEQUENCE_VALUES, trim(substr($value, 1, -1)), $matches); |
|
| 91 | 91 | foreach ($matches['item'] as $key => $item) { |
| 92 | 92 | $i = new Node('', $node->line); |
| 93 | 93 | $i->type = Y::ITEM; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | if ($_root->value instanceof NddeList) $_root->value->setIteratorMode(NodeList::IT_MODE_DELETE); |
| 37 | 37 | foreach ($_root->value as $child) { |
| 38 | 38 | if ($child->type & Y::DOC_START) { |
| 39 | - if(++$totalDocStart > 1){ |
|
| 39 | + if (++$totalDocStart > 1) { |
|
| 40 | 40 | $documents[] = self::buildDocument($buffer, count($documents)); |
| 41 | 41 | $buffer = new NodeList($child); |
| 42 | 42 | } |
@@ -81,13 +81,13 @@ discard block |
||
| 81 | 81 | * |
| 82 | 82 | * @return mixed The parent (object|array) or a string representing the NodeList. |
| 83 | 83 | */ |
| 84 | - public static function buildNodeList(NodeList $node, &$parent=null) |
|
| 84 | + public static function buildNodeList(NodeList $node, &$parent = null) |
|
| 85 | 85 | { |
| 86 | 86 | $node->forceType(); |
| 87 | - if ($node->type & (Y::RAW | Y::LITTERALS)) { |
|
| 87 | + if ($node->type & (Y::RAW|Y::LITTERALS)) { |
|
| 88 | 88 | return self::buildLitteral($node, (int) $node->type); |
| 89 | 89 | } |
| 90 | - $action = function ($child, &$parent, &$out) { |
|
| 90 | + $action = function($child, &$parent, &$out) { |
|
| 91 | 91 | self::build($child, $out); |
| 92 | 92 | }; |
| 93 | 93 | if ($node->type & (Y::COMPACT_MAPPING|Y::MAPPING|Y::SET)) { |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $out = $parent ?? []; |
| 97 | 97 | } else { |
| 98 | 98 | $out = ''; |
| 99 | - $action = function ($child, &$parent, &$out) { |
|
| 99 | + $action = function($child, &$parent, &$out) { |
|
| 100 | 100 | if ($child->type & (Y::SCALAR|Y::QUOTED)) { |
| 101 | 101 | if ($parent) { |
| 102 | 102 | $parent->setText(self::build($child)); |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | ]; |
| 136 | 136 | if (isset($actions[$type])) { |
| 137 | 137 | return TB::{$actions[$type]}($node, $parent); |
| 138 | - } elseif ($type & Y::COMMENT) { |
|
| 138 | + } elseif ($type&Y::COMMENT) { |
|
| 139 | 139 | self::$_root->addComment($line, $value); |
| 140 | - } elseif ($type & (Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) { |
|
| 140 | + } elseif ($type&(Y::COMPACT_MAPPING|Y::COMPACT_SEQUENCE)) { |
|
| 141 | 141 | return self::buildNodeList($value, $parent); |
| 142 | - } elseif ($type & (Y::REF_DEF | Y::REF_CALL)) { |
|
| 142 | + } elseif ($type&(Y::REF_DEF|Y::REF_CALL)) { |
|
| 143 | 143 | return TB::buildReference($node, $parent); |
| 144 | 144 | } elseif ($value instanceof Node) { |
| 145 | 145 | return self::buildNode($value, $parent); |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | //remove trailing blank |
| 166 | 166 | while ($list->top()->type & Y::BLANK) $list->pop(); |
| 167 | 167 | $result = ''; |
| 168 | - $separator = [ Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type]; |
|
| 168 | + $separator = [Y::RAW => '', Y::LITT => "\n", Y::LITT_FOLDED => ' '][$type]; |
|
| 169 | 169 | foreach ($list as $child) { |
| 170 | 170 | if ($child->value instanceof NodeList) { |
| 171 | 171 | $result .= self::buildLitteral($child->value, $type).$separator; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | private static function setLiteralValue(Node $child, string &$result, int $refIndent, string $separator, int $type) |
| 180 | 180 | { |
| 181 | 181 | $val = $child->type & (Y::SCALAR) ? $child->value : substr($child->raw, $refIndent); |
| 182 | - if ($type & Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
| 182 | + if ($type&Y::LITT_FOLDED && ($child->indent > $refIndent || ($child->type & Y::BLANK))) { |
|
| 183 | 183 | if ($result[-1] === $separator) |
| 184 | 184 | $result[-1] = "\n"; |
| 185 | 185 | if ($result[-1] === "\n") |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @throws \ParseError if Key has no name(identifier) Note: empty string is allowed |
| 33 | 33 | * @return null |
| 34 | 34 | */ |
| 35 | - public static function buildKey(Node $node, &$parent=null) |
|
| 35 | + public static function buildKey(Node $node, &$parent = null) |
|
| 36 | 36 | { |
| 37 | 37 | extract((array) $node, EXTR_REFS); |
| 38 | 38 | if (is_null($identifier)) { |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | public function buildSetKey(Node $node, &$parent) |
| 99 | 99 | { |
| 100 | 100 | $built = is_object($node->value) ? Builder::build($node->value) : null; |
| 101 | - $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
|
| 101 | + $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built; |
|
| 102 | 102 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
| 103 | 103 | if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($node->value, true), 1); |
| 104 | 104 | $parent->{trim($key, '\'" ')} = null; |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | { |
| 115 | 115 | $prop = array_keys(get_object_vars($parent)); |
| 116 | 116 | $key = end($prop); |
| 117 | - if ($node->value->type & (Y::ITEM|Y::KEY )) { |
|
| 117 | + if ($node->value->type & (Y::ITEM|Y::KEY)) { |
|
| 118 | 118 | $node->value = new NodeList($node->value); |
| 119 | 119 | } |
| 120 | 120 | $parent->{$key} = Builder::build(/** @scrutinizer ignore-type */ $node->value); |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | //public |
| 18 | 18 | /* @var null|string */ |
| 19 | 19 | public static $error; |
| 20 | - public const IGNORE_DIRECTIVES = 1;//DONT include_directive |
|
| 21 | - public const IGNORE_COMMENTS = 2;//DONT include_comments |
|
| 22 | - public const NO_PARSING_EXCEPTIONS = 4;//DONT throw Exception on parsing errors |
|
| 23 | - public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object |
|
| 20 | + public const IGNORE_DIRECTIVES = 1; //DONT include_directive |
|
| 21 | + public const IGNORE_COMMENTS = 2; //DONT include_comments |
|
| 22 | + public const NO_PARSING_EXCEPTIONS = 4; //DONT throw Exception on parsing errors |
|
| 23 | + public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object |
|
| 24 | 24 | |
| 25 | 25 | //privates |
| 26 | 26 | /* @var null|false|array */ |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | /* @var null|string */ |
| 29 | 29 | private $filePath; |
| 30 | 30 | /* @var integer */ |
| 31 | - private $debug = 0;///TODO: determine levels |
|
| 31 | + private $debug = 0; ///TODO: determine levels |
|
| 32 | 32 | /* @var integer */ |
| 33 | 33 | private $options = 0; |
| 34 | 34 | //Exceptions messages |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $source = $this->content ?? preg_split("/\n/m", preg_replace('/(\r\n|\r)/', "\n", $strContent), 0, PREG_SPLIT_DELIM_CAPTURE); |
| 79 | 79 | //TODO : be more permissive on $strContent values |
| 80 | 80 | if (!is_array($source) || !count($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT); |
| 81 | - return function () use($source) { |
|
| 81 | + return function() use($source) { |
|
| 82 | 82 | foreach ($source as $key => $value) { |
| 83 | 83 | yield ++$key => $value; |
| 84 | 84 | } |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | $target = $previous; |
| 112 | 112 | switch ($n->indent <=> $previous->indent) { |
| 113 | 113 | case -1: |
| 114 | - $target = $previous->getParent($n->indent);break;//, $n->type & Y::ITEM ? Y::KEY : null); |
|
| 114 | + $target = $previous->getParent($n->indent); break; //, $n->type & Y::ITEM ? Y::KEY : null); |
|
| 115 | 115 | case 0: |
| 116 | - $this->onEqualIndent($n, $previous, $target);break; |
|
| 116 | + $this->onEqualIndent($n, $previous, $target); break; |
|
| 117 | 117 | default: |
| 118 | 118 | $this->onMoreIndent($previous, $target); |
| 119 | 119 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | { |
| 157 | 157 | $deepest = $previous->getDeepestNode(); |
| 158 | 158 | if ($n->type & Y::KEY && $n->indent === 0) { |
| 159 | - $target = $previous->getParent(-1);//get root |
|
| 159 | + $target = $previous->getParent(-1); //get root |
|
| 160 | 160 | } elseif ($n->type & Y::ITEM && $deepest->type & Y::KEY && is_null($deepest->value)) { |
| 161 | 161 | $target = $deepest; |
| 162 | 162 | } else { |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | && !($deepest->type & Y::LITTERALS)) { |
| 193 | 193 | // $previous->getParent(0)->add($n); |
| 194 | 194 | return true; |
| 195 | - } elseif ($n->type & Y::TAG && is_null($n->value) ){//&& $previous->type & (Y::ROOT|Y::DOC_START|Y::DOC_END)) { |
|
| 195 | + } elseif ($n->type & Y::TAG && is_null($n->value)) {//&& $previous->type & (Y::ROOT|Y::DOC_START|Y::DOC_END)) { |
|
| 196 | 196 | $n->value = ''; |
| 197 | 197 | } |
| 198 | 198 | return false; |