@@ -12,6 +12,6 @@ |
||
12 | 12 | { |
13 | 13 | public function build(&$parent = null) |
14 | 14 | { |
15 | - return substr(trim($this->raw), 1,-1); |
|
15 | + return substr(trim($this->raw), 1, -1); |
|
16 | 16 | } |
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -67,7 +67,7 @@ |
||
67 | 67 | foreach ($node as $key => $child) { |
68 | 68 | $list[] = $this->str($child); |
69 | 69 | } |
70 | - return new Nodes\Scalar(implode('',$list), 0); |
|
70 | + return new Nodes\Scalar(implode('', $list), 0); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 |
@@ -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); |
@@ -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,10 +14,10 @@ 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"); |
|
17 | +$yamlObject = (include PROJECT_ROOT."tests/cases/dumping/$testName.php"); |
|
18 | 18 | $text = Yaml::dump($yamlObject, 0); |
19 | 19 | |
20 | -$nameResultPair = get_object_vars(Yaml::parseFile(PROJECT_ROOT . 'tests/definitions/dumping_tests.yml')); |
|
20 | +$nameResultPair = get_object_vars(Yaml::parseFile(PROJECT_ROOT.'tests/definitions/dumping_tests.yml')); |
|
21 | 21 | |
22 | 22 | // var_dump($nameResultPair); |
23 | 23 |
@@ -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 | +} |
@@ -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 |
@@ -114,9 +113,9 @@ discard block |
||
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 @@ discard block |
||
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 { |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | } catch (\UnexpectedValueException $e) { |
121 | 121 | return new Tagged($identifier, is_null($value) ? null : $value->build($parent)); |
122 | 122 | } catch (\Throwable $e) { |
123 | - throw new \Exception("Tagged value could not be transformed for tag '$identifier'", 1, $e);; |
|
123 | + throw new \Exception("Tagged value could not be transformed for tag '$identifier'", 1, $e); ; |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | } elseif ($compound instanceof YamlObject) { |
67 | 67 | return $this->dumpYamlObject($compound); |
68 | 68 | } elseif ($compound instanceof Compact) { |
69 | - return $this->dumpCompact($compound, $indent); |
|
69 | + return $this->dumpCompact($compound, $indent); |
|
70 | 70 | } elseif (is_array($compound)) { |
71 | 71 | $iterator = new \ArrayIterator($compound); |
72 | 72 | $mask = '-'; |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | private function dumpYamlObject(YamlObject $obj):string |
90 | 90 | { |
91 | 91 | if ($this->multipleDocs || $obj->hasDocStart() || $obj->isTagged()) { |
92 | - $this->multipleDocs = true; |
|
93 | - // && $this->$result instanceof DLL) $this->$result->push("---"); |
|
92 | + $this->multipleDocs = true; |
|
93 | + // && $this->$result instanceof DLL) $this->$result->push("---"); |
|
94 | 94 | } |
95 | 95 | if (count($obj) > 0) { |
96 | 96 | 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); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | } elseif (is_array($compound)) { |
71 | 71 | $iterator = new \ArrayIterator($compound); |
72 | 72 | $mask = '-'; |
73 | - $refKeys = range(0, count($compound)-1); |
|
73 | + $refKeys = range(0, count($compound) - 1); |
|
74 | 74 | if (array_keys($compound) !== $refKeys) { |
75 | 75 | $mask = '%s:'; |
76 | 76 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | foreach ($iterable as $key => $value) { |
108 | 108 | $separator = "\n"; |
109 | 109 | $valueIndent = $indent + self::INDENT; |
110 | - if (is_scalar($value) || $value instanceof Compact || $value instanceof \DateTime ) { |
|
110 | + if (is_scalar($value) || $value instanceof Compact || $value instanceof \DateTime) { |
|
111 | 111 | $separator = ' '; |
112 | 112 | $valueIndent = 0; |
113 | 113 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | if (is_array($subject) || $subject instanceof \ArrayIterator) { |
136 | 136 | $max = count($subject); |
137 | 137 | $objectAsArray = is_array($subject) ? $subject : $subject->getArrayCopy(); |
138 | - if(array_keys($objectAsArray) !== range(0, $max-1)) { |
|
138 | + if (array_keys($objectAsArray) !== range(0, $max - 1)) { |
|
139 | 139 | $pairs = $objectAsArray; |
140 | 140 | } else { |
141 | 141 | $valuesList = []; |
@@ -25,7 +25,9 @@ discard block |
||
25 | 25 | |
26 | 26 | public function __construct(int $options = null) |
27 | 27 | { |
28 | - if (is_int($options)) $this->options = $options; |
|
28 | + if (is_int($options)) { |
|
29 | + $this->options = $options; |
|
30 | + } |
|
29 | 31 | } |
30 | 32 | |
31 | 33 | |
@@ -45,8 +47,12 @@ discard block |
||
45 | 47 | |
46 | 48 | public function dumpScalar($dataType):string |
47 | 49 | { |
48 | - if ($dataType === \INF) return '.inf'; |
|
49 | - if ($dataType === -\INF) return '-.inf'; |
|
50 | + if ($dataType === \INF) { |
|
51 | + return '.inf'; |
|
52 | + } |
|
53 | + if ($dataType === -\INF) { |
|
54 | + return '-.inf'; |
|
55 | + } |
|
50 | 56 | $precision = "%.".$this->floatPrecision."F"; |
51 | 57 | switch (gettype($dataType)) { |
52 | 58 | case 'boolean': return $dataType ? 'true' : 'false'; |
@@ -77,9 +83,13 @@ discard block |
||
77 | 83 | } elseif (is_iterable($compound)) { |
78 | 84 | $iterator = $compound; |
79 | 85 | } elseif (is_object($compound)) { |
80 | - if ($compound instanceof Tagged) return $this->dumpTagged($compound, $indent); |
|
86 | + if ($compound instanceof Tagged) { |
|
87 | + return $this->dumpTagged($compound, $indent); |
|
88 | + } |
|
81 | 89 | //TODO: consider dumping datetime as date strings according to a format provided by user |
82 | - if ($compound instanceof \DateTime) return $compound->format(self::DATE_FORMAT); |
|
90 | + if ($compound instanceof \DateTime) { |
|
91 | + return $compound->format(self::DATE_FORMAT); |
|
92 | + } |
|
83 | 93 | $iterator = new \ArrayIterator(get_object_vars($compound)); |
84 | 94 | } |
85 | 95 | return $this->iteratorToString($iterator, $mask, $indent); |
@@ -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 | if (!preg_match(Regex::TAG_PARTS, $this->value->raw, $matches)) { |
44 | 44 | throw new \UnexpectedValueException("Tag '".$this->value->raw."' is invalid", 1); |
45 | 45 | } |