@@ -66,9 +66,9 @@ |
||
66 | 66 | } |
67 | 67 | if($this->isValue()) { |
68 | 68 | if($elementCollection->isEmpty()) { |
69 | - if (!is_null($foundInEl)) { |
|
70 | - return $elementCollection->put($elementName, trim($this->reader->value)); |
|
71 | - } |
|
69 | + if (!is_null($foundInEl)) { |
|
70 | + return $elementCollection->put($elementName, trim($this->reader->value)); |
|
71 | + } |
|
72 | 72 | |
73 | 73 | return trim($this->reader->value); |
74 | 74 | } else { |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | class XMLParser implements StreamParserInterface |
19 | 19 | { |
20 | - protected $reader,$source; |
|
20 | + protected $reader, $source; |
|
21 | 21 | |
22 | 22 | protected $skipFirstElement = true; |
23 | 23 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | return $this; |
29 | 29 | } |
30 | 30 | |
31 | - public function withoutSkippingFirstElement(){ |
|
31 | + public function withoutSkippingFirstElement() { |
|
32 | 32 | $this->skipFirstElement = false; |
33 | 33 | |
34 | 34 | return $this; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public function each(callable $function) |
38 | 38 | { |
39 | 39 | $this->start(); |
40 | - while($this->reader->read()){ |
|
40 | + while ($this->reader->read()) { |
|
41 | 41 | $this->searchElement($function); |
42 | 42 | } |
43 | 43 | $this->stop(); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | private function searchElement(callable $function) |
47 | 47 | { |
48 | - if($this->isElement() && ! $this->shouldBeSkipped()){ |
|
48 | + if ($this->isElement() && ! $this->shouldBeSkipped()) { |
|
49 | 49 | $function($this->extractElement($this->reader->name, false, $this->reader->depth), $this->reader->name); |
50 | 50 | } |
51 | 51 | } |
@@ -56,17 +56,17 @@ discard block |
||
56 | 56 | |
57 | 57 | $elementCollection = (new Collection())->merge($this->getCurrentElementAttributes()); |
58 | 58 | |
59 | - if($emptyElement) { |
|
59 | + if ($emptyElement) { |
|
60 | 60 | return $elementCollection; |
61 | 61 | } |
62 | 62 | |
63 | - while($this->reader->read()) { |
|
64 | - if($this->isEndElement($elementName) && $this->reader->depth === $parentDepth) { |
|
63 | + while ($this->reader->read()) { |
|
64 | + if ($this->isEndElement($elementName) && $this->reader->depth === $parentDepth) { |
|
65 | 65 | break; |
66 | 66 | } |
67 | - if($this->isValue()) { |
|
68 | - if($elementCollection->isEmpty()) { |
|
69 | - if (!is_null($foundInEl)) { |
|
67 | + if ($this->isValue()) { |
|
68 | + if ($elementCollection->isEmpty()) { |
|
69 | + if ( ! is_null($foundInEl)) { |
|
70 | 70 | return $elementCollection->put($elementName, trim($this->reader->value)); |
71 | 71 | } |
72 | 72 | |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | return $elementCollection->put($elementName, trim($this->reader->value)); |
76 | 76 | } |
77 | 77 | } |
78 | - if($this->isElement()) { |
|
79 | - if($couldBeAnElementsList) { |
|
78 | + if ($this->isElement()) { |
|
79 | + if ($couldBeAnElementsList) { |
|
80 | 80 | $foundElementName = $this->reader->name; |
81 | 81 | $elementCollection->push(new Collection($this->extractElement($foundElementName, false, $this->reader->depth, $elementName))); |
82 | 82 | } else { |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | return $elementCollection; |
90 | 90 | } |
91 | 91 | |
92 | - private function getCurrentElementAttributes(){ |
|
92 | + private function getCurrentElementAttributes() { |
|
93 | 93 | $attributes = new Collection(); |
94 | - if($this->reader->hasAttributes) { |
|
95 | - while($this->reader->moveToNextAttribute()) { |
|
94 | + if ($this->reader->hasAttributes) { |
|
95 | + while ($this->reader->moveToNextAttribute()) { |
|
96 | 96 | $attributes->put($this->reader->name, $this->reader->value); |
97 | 97 | } |
98 | 98 | } |
@@ -109,13 +109,13 @@ discard block |
||
109 | 109 | |
110 | 110 | private function stop() |
111 | 111 | { |
112 | - if( ! $this->reader->close()){ |
|
112 | + if ( ! $this->reader->close()) { |
|
113 | 113 | throw new IncompleteParseException(); |
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | - private function shouldBeSkipped(){ |
|
118 | - if($this->skipFirstElement){ |
|
117 | + private function shouldBeSkipped() { |
|
118 | + if ($this->skipFirstElement) { |
|
119 | 119 | $this->skipFirstElement = false; |
120 | 120 | return true; |
121 | 121 | } |
@@ -123,28 +123,28 @@ discard block |
||
123 | 123 | return false; |
124 | 124 | } |
125 | 125 | |
126 | - private function isElement(String $elementName = null){ |
|
127 | - if($elementName){ |
|
126 | + private function isElement(String $elementName = null) { |
|
127 | + if ($elementName) { |
|
128 | 128 | return $this->reader->nodeType == XMLReader::ELEMENT && $this->reader->name === $elementName; |
129 | 129 | } else { |
130 | 130 | return $this->reader->nodeType == XMLReader::ELEMENT; |
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
134 | - private function isEndElement(String $elementName = null){ |
|
135 | - if($elementName){ |
|
134 | + private function isEndElement(String $elementName = null) { |
|
135 | + if ($elementName) { |
|
136 | 136 | return $this->reader->nodeType == XMLReader::END_ELEMENT && $this->reader->name === $elementName; |
137 | 137 | } else { |
138 | 138 | return $this->reader->nodeType == XMLReader::END_ELEMENT; |
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
142 | - private function isValue(){ |
|
142 | + private function isValue() { |
|
143 | 143 | return $this->reader->nodeType == XMLReader::TEXT || $this->reader->nodeType === XMLReader::CDATA; |
144 | 144 | } |
145 | 145 | |
146 | - private function isEmptyElement(String $elementName = null){ |
|
147 | - if($elementName) { |
|
146 | + private function isEmptyElement(String $elementName = null) { |
|
147 | + if ($elementName) { |
|
148 | 148 | return $this->reader->isEmptyElement && $this->reader->name === $elementName; |
149 | 149 | } else { |
150 | 150 | return false; |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | { |
18 | 18 | protected $reader, $source, $headers, $currentLine; |
19 | 19 | |
20 | - public static $delimiters = [",", ";"]; |
|
20 | + public static $delimiters = [ ",", ";" ]; |
|
21 | 21 | public static $fieldDelimiter = ","; |
22 | 22 | public static $skipsEmptyLines = true; |
23 | 23 | |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | public function each(callable $function) |
32 | 32 | { |
33 | 33 | $this->start(); |
34 | - while($this->read()){ |
|
35 | - if($this->currentLineIsValid()){ |
|
34 | + while ($this->read()) { |
|
35 | + if ($this->currentLineIsValid()) { |
|
36 | 36 | $function($this->getCurrentLineAsCollection()); |
37 | 37 | } |
38 | 38 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | return $this; |
50 | 50 | } |
51 | 51 | |
52 | - private function close(){ |
|
53 | - if( ! fclose($this->reader)){ |
|
52 | + private function close() { |
|
53 | + if ( ! fclose($this->reader)) { |
|
54 | 54 | throw new IncompleteParseException(); |
55 | 55 | } |
56 | 56 | } |
@@ -63,20 +63,20 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | private function currentLineIsValid(): bool{ |
66 | - if(static::$skipsEmptyLines){ |
|
66 | + if (static::$skipsEmptyLines) { |
|
67 | 67 | return ! $this->currentLineIsEmpty(); |
68 | 68 | } |
69 | 69 | |
70 | 70 | return true; |
71 | 71 | } |
72 | 72 | |
73 | - private function currentLineIsEmpty(){ |
|
74 | - return $this->currentLine->reject(function($value){ |
|
73 | + private function currentLineIsEmpty() { |
|
74 | + return $this->currentLine->reject(function($value) { |
|
75 | 75 | return $this->isEmptyValue($value); |
76 | 76 | })->isEmpty(); |
77 | 77 | } |
78 | 78 | |
79 | - private function isEmptyValue($value){ |
|
79 | + private function isEmptyValue($value) { |
|
80 | 80 | return $value === "" || $value === null; |
81 | 81 | } |
82 | 82 | |
@@ -87,25 +87,25 @@ discard block |
||
87 | 87 | |
88 | 88 | return $headers->intersectByKeys($this->currentLine) |
89 | 89 | ->combine($values->recursive()) |
90 | - ->reject(function($value){ |
|
90 | + ->reject(function($value) { |
|
91 | 91 | return $this->isEmptyValue($value); |
92 | 92 | }); |
93 | 93 | } |
94 | 94 | |
95 | - private function formatCurrentLineValues(Collection $collection){ |
|
95 | + private function formatCurrentLineValues(Collection $collection) { |
|
96 | 96 | $this->explodeCollectionValues($collection); |
97 | 97 | return $collection; |
98 | 98 | } |
99 | 99 | |
100 | - private function explodeCollectionValues(Collection $collection){ |
|
101 | - $collection->transform(function($value){ |
|
100 | + private function explodeCollectionValues(Collection $collection) { |
|
101 | + $collection->transform(function($value) { |
|
102 | 102 | (new Collection(static::$delimiters))->each(function($delimiter) use (&$value){ |
103 | - if( ! is_array($value) && strpos($value, $delimiter) !== false){ |
|
103 | + if ( ! is_array($value) && strpos($value, $delimiter) !== false) { |
|
104 | 104 | $value = explode($delimiter, $value); |
105 | 105 | } |
106 | 106 | }); |
107 | - if(is_array($value)){ |
|
108 | - return (new Collection($value))->reject(function($value){ |
|
107 | + if (is_array($value)) { |
|
108 | + return (new Collection($value))->reject(function($value) { |
|
109 | 109 | return $this->isEmptyValue($value); |
110 | 110 | }); |
111 | 111 | } else { |