@@ -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 | protected $separateParameters = false; |
@@ -29,13 +29,13 @@ discard block |
||
29 | 29 | return $this; |
30 | 30 | } |
31 | 31 | |
32 | - public function withSeparatedParametersList(){ |
|
32 | + public function withSeparatedParametersList() { |
|
33 | 33 | $this->separateParameters = true; |
34 | 34 | |
35 | 35 | return $this; |
36 | 36 | } |
37 | 37 | |
38 | - public function withoutSkippingFirstElement(){ |
|
38 | + public function withoutSkippingFirstElement() { |
|
39 | 39 | $this->skipFirstElement = false; |
40 | 40 | |
41 | 41 | return $this; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | public function each(callable $function) |
45 | 45 | { |
46 | 46 | $this->start(); |
47 | - while($this->reader->read()){ |
|
47 | + while ($this->reader->read()) { |
|
48 | 48 | $this->searchElement($function); |
49 | 49 | } |
50 | 50 | $this->stop(); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | private function searchElement(callable $function) |
54 | 54 | { |
55 | - if($this->isElement() && ! $this->shouldBeSkipped()){ |
|
55 | + if ($this->isElement() && ! $this->shouldBeSkipped()) { |
|
56 | 56 | $function($this->extractElement($this->reader->name, false, $this->reader->depth), $this->reader->name); |
57 | 57 | } |
58 | 58 | } |
@@ -64,23 +64,23 @@ discard block |
||
64 | 64 | $elementCollection = new Collection(); |
65 | 65 | |
66 | 66 | $elementParameters = $this->getCurrentElementAttributes(); |
67 | - if($this->separateParameters){ |
|
67 | + if ($this->separateParameters) { |
|
68 | 68 | $elementCollection->put('__params', $elementParameters); |
69 | 69 | } else { |
70 | 70 | $elementCollection = $elementCollection->merge($elementParameters); |
71 | 71 | } |
72 | 72 | |
73 | - if($emptyElement) { |
|
73 | + if ($emptyElement) { |
|
74 | 74 | return $elementCollection; |
75 | 75 | } |
76 | 76 | |
77 | - while($this->reader->read()) { |
|
78 | - if($this->isEndElement($elementName) && $this->reader->depth === $parentDepth) { |
|
77 | + while ($this->reader->read()) { |
|
78 | + if ($this->isEndElement($elementName) && $this->reader->depth === $parentDepth) { |
|
79 | 79 | break; |
80 | 80 | } |
81 | - if($this->isValue()) { |
|
82 | - if($elementCollection->isEmpty()) { |
|
83 | - if (!is_null($foundInEl)) { |
|
81 | + if ($this->isValue()) { |
|
82 | + if ($elementCollection->isEmpty()) { |
|
83 | + if ( ! is_null($foundInEl)) { |
|
84 | 84 | return $elementCollection->put($elementName, trim($this->reader->value)); |
85 | 85 | } |
86 | 86 | |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | return $elementCollection->put($elementName, trim($this->reader->value)); |
90 | 90 | } |
91 | 91 | } |
92 | - if($this->isElement()) { |
|
93 | - if($couldBeAnElementsList) { |
|
92 | + if ($this->isElement()) { |
|
93 | + if ($couldBeAnElementsList) { |
|
94 | 94 | $foundElementName = $this->reader->name; |
95 | 95 | $elementCollection->push(new Collection($this->extractElement($foundElementName, false, $this->reader->depth, $elementName))); |
96 | 96 | } else { |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | return $elementCollection; |
104 | 104 | } |
105 | 105 | |
106 | - private function getCurrentElementAttributes(){ |
|
106 | + private function getCurrentElementAttributes() { |
|
107 | 107 | $attributes = new Collection(); |
108 | - if($this->reader->hasAttributes) { |
|
109 | - while($this->reader->moveToNextAttribute()) { |
|
108 | + if ($this->reader->hasAttributes) { |
|
109 | + while ($this->reader->moveToNextAttribute()) { |
|
110 | 110 | $attributes->put($this->reader->name, $this->reader->value); |
111 | 111 | } |
112 | 112 | } |
@@ -123,13 +123,13 @@ discard block |
||
123 | 123 | |
124 | 124 | private function stop() |
125 | 125 | { |
126 | - if( ! $this->reader->close()){ |
|
126 | + if ( ! $this->reader->close()) { |
|
127 | 127 | throw new IncompleteParseException(); |
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
131 | - private function shouldBeSkipped(){ |
|
132 | - if($this->skipFirstElement){ |
|
131 | + private function shouldBeSkipped() { |
|
132 | + if ($this->skipFirstElement) { |
|
133 | 133 | $this->skipFirstElement = false; |
134 | 134 | return true; |
135 | 135 | } |
@@ -137,28 +137,28 @@ discard block |
||
137 | 137 | return false; |
138 | 138 | } |
139 | 139 | |
140 | - private function isElement(String $elementName = null){ |
|
141 | - if($elementName){ |
|
140 | + private function isElement(String $elementName = null) { |
|
141 | + if ($elementName) { |
|
142 | 142 | return $this->reader->nodeType == XMLReader::ELEMENT && $this->reader->name === $elementName; |
143 | 143 | } else { |
144 | 144 | return $this->reader->nodeType == XMLReader::ELEMENT; |
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
148 | - private function isEndElement(String $elementName = null){ |
|
149 | - if($elementName){ |
|
148 | + private function isEndElement(String $elementName = null) { |
|
149 | + if ($elementName) { |
|
150 | 150 | return $this->reader->nodeType == XMLReader::END_ELEMENT && $this->reader->name === $elementName; |
151 | 151 | } else { |
152 | 152 | return $this->reader->nodeType == XMLReader::END_ELEMENT; |
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
156 | - private function isValue(){ |
|
156 | + private function isValue() { |
|
157 | 157 | return $this->reader->nodeType == XMLReader::TEXT || $this->reader->nodeType === XMLReader::CDATA; |
158 | 158 | } |
159 | 159 | |
160 | - private function isEmptyElement(String $elementName = null){ |
|
161 | - if($elementName) { |
|
160 | + private function isEmptyElement(String $elementName = null) { |
|
161 | + if ($elementName) { |
|
162 | 162 | return $this->reader->isEmptyElement && $this->reader->name === $elementName; |
163 | 163 | } else { |
164 | 164 | return false; |