@@ -12,7 +12,7 @@ |
||
12 | 12 | { |
13 | 13 | public function add(NodeGeneric $child):NodeGeneric |
14 | 14 | { |
15 | - if($this->_parent instanceof NodeGeneric) { |
|
15 | + if ($this->_parent instanceof NodeGeneric) { |
|
16 | 16 | return $this->_parent->add($child); |
17 | 17 | } else { |
18 | 18 | throw new \ParseError(__METHOD__." no parent to add to", 1); |
@@ -29,7 +29,7 @@ |
||
29 | 29 | public function build(&$parent = null) |
30 | 30 | { |
31 | 31 | $built = is_null($this->value) ? null : $this->value->build(); |
32 | - $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
|
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 | 34 | if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
35 | 35 | $parent->{trim($key, '\'" ')} = null; |
@@ -34,7 +34,9 @@ |
||
34 | 34 | $built = is_null($this->value) ? null : $this->value->build(); |
35 | 35 | $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" '): $built; |
36 | 36 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
37 | - if (empty($key)) throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
|
37 | + if (empty($key)) { |
|
38 | + throw new \Exception("Cant serialize complex key: ".var_export($this->value, true)); |
|
39 | + } |
|
38 | 40 | $parent->{trim($key, '\'" ')} = null; |
39 | 41 | return null; |
40 | 42 | } |
@@ -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 = ' '; |
@@ -31,10 +31,10 @@ |
||
31 | 31 | $result = $this->getChildValue($first, $indent); |
32 | 32 | foreach ($list as $child) { |
33 | 33 | $separator = ($result && $result[-1] === "\n") ? '' : $refSeparator; |
34 | - if($child->indent > $indent || $child instanceof Blank) { |
|
34 | + if ($child->indent > $indent || $child instanceof Blank) { |
|
35 | 35 | $separator = "\n"; |
36 | 36 | } |
37 | - $result .= $separator .$this->getChildValue($child, $indent); |
|
37 | + $result .= $separator.$this->getChildValue($child, $indent); |
|
38 | 38 | } |
39 | 39 | } |
40 | 40 | return $result; |
@@ -94,7 +94,7 @@ |
||
94 | 94 | * @return string The child value. |
95 | 95 | * @todo double check behaviour for KEY and ITEM |
96 | 96 | */ |
97 | - protected function getChildValue(object $child, $refIndent=0):string |
|
97 | + protected function getChildValue(object $child, $refIndent = 0):string |
|
98 | 98 | { |
99 | 99 | $value = $child->value; |
100 | 100 | $start = ''; |
@@ -32,7 +32,9 @@ |
||
32 | 32 | |
33 | 33 | public function add(NodeGeneric $child):NodeGeneric |
34 | 34 | { |
35 | - if (is_null($this->value)) $this->value = new NodeList(); |
|
35 | + if (is_null($this->value)) { |
|
36 | + $this->value = new NodeList(); |
|
37 | + } |
|
36 | 38 | $candidate = $child; |
37 | 39 | if (!$child->isOneOf('Scalar', 'Blank', 'Comment', 'Quoted')) { |
38 | 40 | $candidate = new Scalar((string) $child->raw, $child->line); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | |
62 | 62 | public function add(NodeGeneric $child):NodeGeneric |
63 | 63 | { |
64 | - if ($this->value instanceof NodeGeneric && $this->value->isOneOf('Literal','LiteralFolded', 'Anchor')) { |
|
64 | + if ($this->value instanceof NodeGeneric && $this->value->isOneOf('Literal', 'LiteralFolded', 'Anchor')) { |
|
65 | 65 | return $this->value->add($child); |
66 | 66 | } else { |
67 | 67 | return parent::add($child); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | if ($current instanceof Comment) { |
97 | 97 | return true; |
98 | 98 | } |
99 | - if($current instanceof Scalar) { |
|
99 | + if ($current instanceof Scalar) { |
|
100 | 100 | return $node->isOneOf('Scalar', 'Blank'); |
101 | 101 | } |
102 | 102 | if ($current instanceof Item) { |
@@ -35,7 +35,7 @@ |
||
35 | 35 | public function setIdentifier(string $keyString) |
36 | 36 | { |
37 | 37 | if ($keyString === '') { |
38 | - throw new \ParseError(sprintf(self::ERROR_NO_KEYNAME, $this->line)); |
|
38 | + throw new \ParseError(sprintf(self::ERROR_NO_KEYNAME, $this->line)); |
|
39 | 39 | } else { |
40 | 40 | $node = NodeFactory::get($keyString); |
41 | 41 | if ($node->isOneOf('Tag', 'Quoted')) { |
@@ -24,4 +24,6 @@ |
||
24 | 24 | if ($nameResultPair[$testName] !== $text) { |
25 | 25 | var_dump('EXPECTED', $nameResultPair[$testName]); |
26 | 26 | var_dump('RECEIVED', $text); |
27 | -} else echo 'WRITE OK !!!'; |
|
27 | +} else { |
|
28 | + echo 'WRITE OK !!!'; |
|
29 | +} |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | define('PROJECT_ROOT', __DIR__."/../"); |
3 | 3 | |
4 | -require_once PROJECT_ROOT . 'vendor/autoload.php'; |
|
4 | +require_once PROJECT_ROOT.'vendor/autoload.php'; |
|
5 | 5 | |
6 | 6 | use Dallgoot\Yaml; |
7 | 7 | // use Dallgoot\Yaml\{Loader, Dumper}; |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | // $yaml = (new Loader('./dummy.yml', null, 0))->parse(); |
15 | 15 | // var_dump($yaml); |
16 | 16 | $testName = 'yamlObject_properties'; |
17 | -$yamlObject = (include PROJECT_ROOT . "tests/cases/dumping/$testName.php"); |
|
18 | -echo memory_get_usage() . "\n"; |
|
17 | +$yamlObject = (include PROJECT_ROOT."tests/cases/dumping/$testName.php"); |
|
18 | +echo memory_get_usage()."\n"; |
|
19 | 19 | |
20 | 20 | $text = Yaml::dump($yamlObject, 0); |
21 | 21 | |
22 | -echo memory_get_usage() . "\n"; |
|
23 | -$nameResultPair = get_object_vars(/** @scrutinizer ignore-type */ Yaml::parseFile(PROJECT_ROOT . 'tests/definitions/dumping_tests.yml')); |
|
22 | +echo memory_get_usage()."\n"; |
|
23 | +$nameResultPair = get_object_vars(/** @scrutinizer ignore-type */ Yaml::parseFile(PROJECT_ROOT.'tests/definitions/dumping_tests.yml')); |
|
24 | 24 | |
25 | 25 | // var_dump($nameResultPair); |
26 | 26 |
@@ -62,7 +62,6 @@ discard block |
||
62 | 62 | %TAG !! tag:example.com,2000:app/ |
63 | 63 | %TAG !e! tag:example.com,2000:app/ |
64 | 64 | !<tag:yaml.org,2002:str> foo : |
65 | - |
|
66 | 65 | */ |
67 | 66 | /** |
68 | 67 | * Add Handlers for legacy Yaml tags |
@@ -107,16 +106,16 @@ discard block |
||
107 | 106 | self::createCoreSchema(); |
108 | 107 | } |
109 | 108 | if (!($value instanceof NodeGeneric) && !($value instanceof NodeList) ) { |
110 | - throw new \Exception(sprintf(self::WRONG_VALUE, $identifier, gettype($value))); |
|
109 | + throw new \Exception(sprintf(self::WRONG_VALUE, $identifier, gettype($value))); |
|
111 | 110 | } else { |
112 | 111 | // try { |
113 | 112 | if (!preg_match(Regex::TAG_PARTS, $identifier, $matches)) { |
114 | 113 | throw new \UnexpectedValueException("Tag '$identifier' is invalid", 1); |
115 | 114 | } |
116 | 115 | return self::runHandler($matches['handle'], |
117 | - $matches['tagname'], |
|
118 | - $value, |
|
119 | - $parent); |
|
116 | + $matches['tagname'], |
|
117 | + $value, |
|
118 | + $parent); |
|
120 | 119 | // } catch (\UnexpectedValueException $e) { |
121 | 120 | // return new Tagged($identifier, is_null($value) ? null : $value->build($parent)); |
122 | 121 | // } catch (\Throwable $e) { |
@@ -106,7 +106,7 @@ |
||
106 | 106 | if (count(self::$schemas) === 0) { |
107 | 107 | self::createCoreSchema(); |
108 | 108 | } |
109 | - if (!($value instanceof NodeGeneric) && !($value instanceof NodeList) ) { |
|
109 | + if (!($value instanceof NodeGeneric) && !($value instanceof NodeList)) { |
|
110 | 110 | throw new \Exception(sprintf(self::WRONG_VALUE, $identifier, gettype($value))); |
111 | 111 | } else { |
112 | 112 | // try { |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function str(object $node, &$parent = null) |
59 | 59 | { |
60 | - if($node instanceof Nodes\Literals){ |
|
60 | + if ($node instanceof Nodes\Literals) { |
|
61 | 61 | $node = $node->value; |
62 | 62 | } |
63 | 63 | if ($node instanceof Nodes\NodeGeneric) { |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $list[] = $this->str($child); |
73 | 73 | } |
74 | 74 | // return new Nodes\Scalar(implode('',$list), 0); |
75 | - return implode('',$list); |
|
75 | + return implode('', $list); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $keyValue = $key->value->build(); |
134 | 134 | if (is_null($parent)) { |
135 | 135 | return [$keyName => $keyValue]; |
136 | - } else{ |
|
136 | + } else { |
|
137 | 137 | $parent[$keyName] = $keyValue; |
138 | 138 | } |
139 | 139 | } else { |
@@ -39,7 +39,7 @@ |
||
39 | 39 | throw new \Exception(__METHOD__." expects a YamlObject as parent", 1); |
40 | 40 | } |
41 | 41 | if (!is_null($this->value)) { |
42 | - if ($this->value instanceof Tag){ |
|
42 | + if ($this->value instanceof Tag) { |
|
43 | 43 | preg_match(Regex::TAG_PARTS, $this->value->raw, $tagparts); |
44 | 44 | if (preg_match("/(?(DEFINE)".Regex::TAG_URI.')(?&url)/', $tagparts['tagname'], $matches)) { |
45 | 45 | // throw new \UnexpectedValueException("Tag '".$this->value->raw."' is invalid", 1); |