@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | if($this->isValue()) { |
| 66 | 66 | if($elementCollection->isEmpty()) { |
| 67 | - if (!is_null($foundInEl)) { |
|
| 68 | - return $elementCollection->put($elementName, trim($this->reader->value)); |
|
| 69 | - } |
|
| 67 | + if (!is_null($foundInEl)) { |
|
| 68 | + return $elementCollection->put($elementName, trim($this->reader->value)); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | return trim($this->reader->value); |
| 72 | 72 | } else { |
@@ -141,11 +141,11 @@ discard block |
||
| 141 | 141 | return $this->reader->nodeType == XMLReader::TEXT || $this->reader->nodeType === XMLReader::CDATA; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - private function isEmptyElement(String $elementName = null){ |
|
| 145 | - if($elementName) { |
|
| 146 | - return $this->reader->isEmptyElement && $this->reader->name === $elementName; |
|
| 147 | - } else { |
|
| 148 | - return false; |
|
| 149 | - } |
|
| 150 | - } |
|
| 144 | + private function isEmptyElement(String $elementName = null){ |
|
| 145 | + if($elementName) { |
|
| 146 | + return $this->reader->isEmptyElement && $this->reader->name === $elementName; |
|
| 147 | + } else { |
|
| 148 | + return false; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | 151 | } |
@@ -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)); |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -54,17 +54,17 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $elementCollection = (new Collection())->merge($this->getCurrentElementAttributes()); |
| 56 | 56 | |
| 57 | - if($this->isEmptyElement($elementName)) { |
|
| 57 | + if ($this->isEmptyElement($elementName)) { |
|
| 58 | 58 | return $elementCollection; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - while($this->reader->read()) { |
|
| 62 | - if($this->isEndElement($elementName) && $this->reader->depth === $parentDepth) { |
|
| 61 | + while ($this->reader->read()) { |
|
| 62 | + if ($this->isEndElement($elementName) && $this->reader->depth === $parentDepth) { |
|
| 63 | 63 | break; |
| 64 | 64 | } |
| 65 | - if($this->isValue()) { |
|
| 66 | - if($elementCollection->isEmpty()) { |
|
| 67 | - if (!is_null($foundInEl)) { |
|
| 65 | + if ($this->isValue()) { |
|
| 66 | + if ($elementCollection->isEmpty()) { |
|
| 67 | + if ( ! is_null($foundInEl)) { |
|
| 68 | 68 | return $elementCollection->put($elementName, trim($this->reader->value)); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -73,8 +73,8 @@ discard block |
||
| 73 | 73 | return $elementCollection->put($elementName, trim($this->reader->value)); |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | - if($this->isElement()) { |
|
| 77 | - if($couldBeAnElementsList) { |
|
| 76 | + if ($this->isElement()) { |
|
| 77 | + if ($couldBeAnElementsList) { |
|
| 78 | 78 | $foundElementName = $this->reader->name; |
| 79 | 79 | $elementCollection->push(new Collection($this->extractElement($foundElementName, false, $this->reader->depth, $elementName))); |
| 80 | 80 | } else { |
@@ -87,10 +87,10 @@ discard block |
||
| 87 | 87 | return $elementCollection; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - private function getCurrentElementAttributes(){ |
|
| 90 | + private function getCurrentElementAttributes() { |
|
| 91 | 91 | $attributes = new Collection(); |
| 92 | - if($this->reader->hasAttributes) { |
|
| 93 | - while($this->reader->moveToNextAttribute()) { |
|
| 92 | + if ($this->reader->hasAttributes) { |
|
| 93 | + while ($this->reader->moveToNextAttribute()) { |
|
| 94 | 94 | $attributes->put($this->reader->name, $this->reader->value); |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | private function stop() |
| 109 | 109 | { |
| 110 | - if( ! $this->reader->close()){ |
|
| 110 | + if ( ! $this->reader->close()) { |
|
| 111 | 111 | throw new IncompleteParseException(); |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - private function shouldBeSkipped(){ |
|
| 116 | - if($this->skipFirstElement){ |
|
| 115 | + private function shouldBeSkipped() { |
|
| 116 | + if ($this->skipFirstElement) { |
|
| 117 | 117 | $this->skipFirstElement = false; |
| 118 | 118 | return true; |
| 119 | 119 | } |
@@ -121,28 +121,28 @@ discard block |
||
| 121 | 121 | return false; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - private function isElement(String $elementName = null){ |
|
| 125 | - if($elementName){ |
|
| 124 | + private function isElement(String $elementName = null) { |
|
| 125 | + if ($elementName) { |
|
| 126 | 126 | return $this->reader->nodeType == XMLReader::ELEMENT && $this->reader->name === $elementName; |
| 127 | 127 | } else { |
| 128 | 128 | return $this->reader->nodeType == XMLReader::ELEMENT; |
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - private function isEndElement(String $elementName = null){ |
|
| 133 | - if($elementName){ |
|
| 132 | + private function isEndElement(String $elementName = null) { |
|
| 133 | + if ($elementName) { |
|
| 134 | 134 | return $this->reader->nodeType == XMLReader::END_ELEMENT && $this->reader->name === $elementName; |
| 135 | 135 | } else { |
| 136 | 136 | return $this->reader->nodeType == XMLReader::END_ELEMENT; |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - private function isValue(){ |
|
| 140 | + private function isValue() { |
|
| 141 | 141 | return $this->reader->nodeType == XMLReader::TEXT || $this->reader->nodeType === XMLReader::CDATA; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - private function isEmptyElement(String $elementName = null){ |
|
| 145 | - if($elementName) { |
|
| 144 | + private function isEmptyElement(String $elementName = null) { |
|
| 145 | + if ($elementName) { |
|
| 146 | 146 | return $this->reader->isEmptyElement && $this->reader->name === $elementName; |
| 147 | 147 | } else { |
| 148 | 148 | return false; |