@@ -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)); |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -54,19 +54,19 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $elementCollection = (new Collection())->merge($this->getCurrentElementAttributes()); |
| 56 | 56 | |
| 57 | - while($this->reader->read()){ |
|
| 58 | - if($this->isEndElement($elementName)){ |
|
| 57 | + while ($this->reader->read()) { |
|
| 58 | + if ($this->isEndElement($elementName)) { |
|
| 59 | 59 | break; |
| 60 | 60 | } |
| 61 | - if($this->isValue()){ |
|
| 62 | - if($elementCollection->isEmpty()){ |
|
| 61 | + if ($this->isValue()) { |
|
| 62 | + if ($elementCollection->isEmpty()) { |
|
| 63 | 63 | return trim($this->reader->value); |
| 64 | 64 | } else { |
| 65 | 65 | return $elementCollection->put($elementName, trim($this->reader->value)); |
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | - if($this->isElement()){ |
|
| 69 | - if($couldBeAnElementsList){ |
|
| 68 | + if ($this->isElement()) { |
|
| 69 | + if ($couldBeAnElementsList) { |
|
| 70 | 70 | $foundElementName = $this->reader->name; |
| 71 | 71 | $elementCollection->push(new Collection($this->extractElement($foundElementName))); |
| 72 | 72 | } else { |
@@ -79,10 +79,10 @@ discard block |
||
| 79 | 79 | return $elementCollection; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - private function getCurrentElementAttributes(){ |
|
| 82 | + private function getCurrentElementAttributes() { |
|
| 83 | 83 | $attributes = new Collection(); |
| 84 | - if($this->reader->hasAttributes) { |
|
| 85 | - while($this->reader->moveToNextAttribute()) { |
|
| 84 | + if ($this->reader->hasAttributes) { |
|
| 85 | + while ($this->reader->moveToNextAttribute()) { |
|
| 86 | 86 | $attributes->put($this->reader->name, $this->reader->value); |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -99,13 +99,13 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | private function stop() |
| 101 | 101 | { |
| 102 | - if( ! $this->reader->close()){ |
|
| 102 | + if ( ! $this->reader->close()) { |
|
| 103 | 103 | throw new IncompleteParseException(); |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - private function shouldBeSkipped(){ |
|
| 108 | - if($this->skipFirstElement){ |
|
| 107 | + private function shouldBeSkipped() { |
|
| 108 | + if ($this->skipFirstElement) { |
|
| 109 | 109 | $this->skipFirstElement = false; |
| 110 | 110 | return true; |
| 111 | 111 | } |
@@ -113,23 +113,23 @@ discard block |
||
| 113 | 113 | return false; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - private function isElement(String $elementName = null){ |
|
| 117 | - if($elementName){ |
|
| 116 | + private function isElement(String $elementName = null) { |
|
| 117 | + if ($elementName) { |
|
| 118 | 118 | return $this->reader->nodeType == XMLReader::ELEMENT && $this->reader->name === $elementName; |
| 119 | 119 | } else { |
| 120 | 120 | return $this->reader->nodeType == XMLReader::ELEMENT; |
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - private function isEndElement(String $elementName = null){ |
|
| 125 | - if($elementName){ |
|
| 124 | + private function isEndElement(String $elementName = null) { |
|
| 125 | + if ($elementName) { |
|
| 126 | 126 | return $this->reader->nodeType == XMLReader::END_ELEMENT && $this->reader->name === $elementName; |
| 127 | 127 | } else { |
| 128 | 128 | return $this->reader->nodeType == XMLReader::END_ELEMENT; |
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - private function isValue(){ |
|
| 132 | + private function isValue() { |
|
| 133 | 133 | return $this->reader->nodeType == XMLReader::TEXT || $this->reader->nodeType === XMLReader::CDATA; |
| 134 | 134 | } |
| 135 | 135 | } |