@@ -69,7 +69,7 @@ |
||
| 69 | 69 | return $this->_anchors[$name]; |
| 70 | 70 | } |
| 71 | 71 | throw new \UnexpectedValueException(sprintf(self::UNKNOWN_REFERENCE, |
| 72 | - $name, implode(',',array_keys($this->_anchors))) |
|
| 72 | + $name, implode(',', array_keys($this->_anchors))) |
|
| 73 | 73 | ); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -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); |
@@ -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) |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | && !($child instanceof Directive) |
| 65 | 65 | && !($child instanceof Blank) |
| 66 | 66 | && !($child instanceof Docstart |
| 67 | - && is_null($child->value)) ) return true; |
|
| 67 | + && is_null($child->value))) return true; |
|
| 68 | 68 | } |
| 69 | 69 | return false; |
| 70 | 70 | } |
@@ -72,12 +72,12 @@ discard block |
||
| 72 | 72 | public function push($node) |
| 73 | 73 | { |
| 74 | 74 | $type = null; |
| 75 | - if ($node instanceof Item ) $type = self::SEQUENCE; |
|
| 75 | + if ($node instanceof Item) $type = self::SEQUENCE; |
|
| 76 | 76 | elseif ($node instanceof Key) $type = self::MAPPING; |
| 77 | 77 | elseif ($node instanceof SetKey |
| 78 | 78 | || $node instanceof SetValue) { |
| 79 | 79 | $type = self::SET; |
| 80 | - } elseif ($node instanceof Scalar ){ |
|
| 80 | + } elseif ($node instanceof Scalar) { |
|
| 81 | 81 | $type = self::MULTILINE; |
| 82 | 82 | } |
| 83 | 83 | if (!is_null($type) && $this->checkTypeCoherence($type)) { |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | $output = trim($first->raw); |
| 140 | 140 | foreach ($list as $child) { |
| 141 | 141 | if ($child instanceof Scalar) { |
| 142 | - $separator = isset($output[-1]) && $output[-1] === "\n" ? '' : ' '; |
|
| 142 | + $separator = isset($output[-1]) && $output[-1] === "\n" ? '' : ' '; |
|
| 143 | 143 | $output .= $separator.trim($child->raw); |
| 144 | 144 | } elseif ($child instanceof Blank) { |
| 145 | 145 | $output .= "\n"; |
@@ -165,10 +165,10 @@ discard block |
||
| 165 | 165 | if ($child instanceof Comment) { |
| 166 | 166 | // $child->build(); |
| 167 | 167 | } else { |
| 168 | - if($child->value instanceof Comment) { |
|
| 168 | + if ($child->value instanceof Comment) { |
|
| 169 | 169 | // $child->value->build(); |
| 170 | 170 | // $child->value = null; |
| 171 | - } elseif($child->value instanceof NodeList) { |
|
| 171 | + } elseif ($child->value instanceof NodeList) { |
|
| 172 | 172 | $child->value = $child->value->filterComment(); |
| 173 | 173 | } |
| 174 | 174 | $out->push($child); |
@@ -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 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 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 | $debug = (int) (isset($argv[1]) ? $argv[1] : null); |
| 12 | 12 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * load and parse if file exists |
| 15 | 15 | */ |
| 16 | 16 | // $content = file_get_contents('./tests/cases/parsing/multidoc_mapping.yml');//var_dump($content); |
| 17 | -$content = file_get_contents('./tests/definitions/examples_tests.yml');//var_dump($content); |
|
| 17 | +$content = file_get_contents('./tests/definitions/examples_tests.yml'); //var_dump($content); |
|
| 18 | 18 | $yaml = Yaml::parse($content, 0, $debug); |
| 19 | 19 | // var_dump($yaml); |
| 20 | 20 | var_dump(json_encode($yaml, JSON_OPTIONS)); |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Dallgoot\Yaml; |
| 3 | 3 | |
| 4 | -require_once __DIR__ . '/../../vendor/autoload.php'; |
|
| 4 | +require_once __DIR__.'/../../vendor/autoload.php'; |
|
| 5 | 5 | |
| 6 | 6 | use Dallgoot; |
| 7 | 7 | |
| 8 | -$fileName = __DIR__ . '/../dummy.yml'; |
|
| 8 | +$fileName = __DIR__.'/../dummy.yml'; |
|
| 9 | 9 | |
| 10 | 10 | $yamlObject = Yaml::parseFile($fileName, $options = null, $debug = null); |
| 11 | 11 | |
@@ -20,10 +20,10 @@ discard block |
||
| 20 | 20 | //public |
| 21 | 21 | /* @var null|string */ |
| 22 | 22 | public static $error; |
| 23 | - public const IGNORE_DIRECTIVES = 1;//DONT include_directive |
|
| 24 | - public const IGNORE_COMMENTS = 2;//DONT include_comments |
|
| 25 | - public const NO_PARSING_EXCEPTIONS = 4;//DONT throw Exception on parsing errors |
|
| 26 | - public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object |
|
| 23 | + public const IGNORE_DIRECTIVES = 1; //DONT include_directive |
|
| 24 | + public const IGNORE_COMMENTS = 2; //DONT include_comments |
|
| 25 | + public const NO_PARSING_EXCEPTIONS = 4; //DONT throw Exception on parsing errors |
|
| 26 | + public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object |
|
| 27 | 27 | |
| 28 | 28 | //private |
| 29 | 29 | /* @var null|array */ |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $previous = $target->add($node); |
| 145 | 145 | } |
| 146 | 146 | $this->_attachBlankLines($previous); |
| 147 | - if ($this->_debug === 1){ |
|
| 147 | + if ($this->_debug === 1) { |
|
| 148 | 148 | return null; |
| 149 | 149 | } |
| 150 | 150 | return Builder::buildContent($root, $this->_debug); |
@@ -183,8 +183,8 @@ discard block |
||
| 183 | 183 | { |
| 184 | 184 | $deepest = $previous->getDeepestNode(); |
| 185 | 185 | if ($deepest instanceof Nodes\Partial) { |
| 186 | - return $deepest->specialProcess($current, $this->_blankBuffer); |
|
| 187 | - } elseif(!($current instanceof Nodes\Partial)) { |
|
| 186 | + return $deepest->specialProcess($current, $this->_blankBuffer); |
|
| 187 | + } elseif (!($current instanceof Nodes\Partial)) { |
|
| 188 | 188 | return $current->specialProcess($previous, $this->_blankBuffer); |
| 189 | 189 | } |
| 190 | 190 | return false; |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | elseif ((bool) preg_match(Regex::KEY, $trimmed, $matches)) return new Nodes\Key($nodeString, $line, $matches); |
| 28 | 28 | else { |
| 29 | 29 | $first = $trimmed[0]; |
| 30 | - $stringGroups = ["-" ,'>|' ,'"\'',"#%" ,"{[" ,":?" ,'*&!']; |
|
| 31 | - $methodGroups = ['Hyphen','Literal','Quoted','Special','Compact','SetElement','NodeAction']; |
|
| 30 | + $stringGroups = ["-", '>|', '"\'', "#%", "{[", ":?", '*&!']; |
|
| 31 | + $methodGroups = ['Hyphen', 'Literal', 'Quoted', 'Special', 'Compact', 'SetElement', 'NodeAction']; |
|
| 32 | 32 | foreach ($stringGroups as $groupIndex => $stringRef) { |
| 33 | 33 | if (is_int(strpos($stringRef, $first))) { |
| 34 | 34 | $methodName = 'on'.$methodGroups[$groupIndex]; |
@@ -134,9 +134,9 @@ discard block |
||
| 134 | 134 | if (!((bool) preg_match(Regex::NODE_ACTIONS, trim($nodeString), $matches))) { |
| 135 | 135 | return new Nodes\Scalar($nodeString, $line); |
| 136 | 136 | } |
| 137 | - $action = trim($matches['action']);//var_dump($matches); |
|
| 137 | + $action = trim($matches['action']); //var_dump($matches); |
|
| 138 | 138 | switch ($action[0]) { |
| 139 | - case '!': return new Nodes\Tag ($nodeString, $line); |
|
| 139 | + case '!': return new Nodes\Tag($nodeString, $line); |
|
| 140 | 140 | default : |
| 141 | 141 | return new Nodes\Anchor($nodeString, $line); |
| 142 | 142 | // case '&': return new NodeAnchor($nodeString, $line); |
@@ -87,8 +87,8 @@ |
||
| 87 | 87 | private function dumpYamlObject(YamlObject $obj):string |
| 88 | 88 | { |
| 89 | 89 | if ($this->multipleDocs || $obj->hasDocStart() || $obj->isTagged() || $obj->isScalar()) { |
| 90 | - $this->multipleDocs = true; |
|
| 91 | - // && $this->$result instanceof DLL) $this->$result->push("---"); |
|
| 90 | + $this->multipleDocs = true; |
|
| 91 | + // && $this->$result instanceof DLL) $this->$result->push("---"); |
|
| 92 | 92 | } |
| 93 | 93 | if (count($obj) > 0) { |
| 94 | 94 | return $this->iteratorToString($obj, '-', 0); |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | public function dump($dataType, int $indent):string |
| 34 | 34 | { |
| 35 | - if(is_null($dataType)) { |
|
| 35 | + if (is_null($dataType)) { |
|
| 36 | 36 | return ''; |
| 37 | - } elseif(is_resource($dataType)) { |
|
| 37 | + } elseif (is_resource($dataType)) { |
|
| 38 | 38 | return get_resource_type($dataType); |
| 39 | 39 | } elseif (is_scalar($dataType)) { |
| 40 | 40 | return $this->dumpScalar($dataType, $indent); |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | |
| 104 | - private function iteratorToString(iterable $iterator, string $mask, int $indent, bool $isCompact=false):string |
|
| 104 | + private function iteratorToString(iterable $iterator, string $mask, int $indent, bool $isCompact = false):string |
|
| 105 | 105 | { |
| 106 | 106 | $pairs = []; |
| 107 | 107 | foreach (new \ArrayIterator($iterator) as $key => $value) { |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | if (is_array($subject) || $subject instanceof \ArrayIterator) { |
| 134 | 134 | $max = count($subject); |
| 135 | 135 | $objectAsArray = is_array($subject) ? $subject : $subject->getArrayCopy(); |
| 136 | - if(array_keys($objectAsArray) !== range(0, $max-1)) { |
|
| 136 | + if (array_keys($objectAsArray) !== range(0, $max - 1)) { |
|
| 137 | 137 | $pairs = $objectAsArray; |
| 138 | 138 | } else { |
| 139 | 139 | $valuesList = []; |