Passed
Push — master ( 8c2778...04210d )
by Domenico
02:17
created
src/HtmlParser.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
      * @throws InvalidXmlException
30 30
      * @throws XmlParsingException
31 31
      */
32
-    public static function parse( $xml, $isXmlFragment = false ) {
33
-        $parser = new static( $xml, $isXmlFragment, true );
32
+    public static function parse($xml, $isXmlFragment = false) {
33
+        $parser = new static($xml, $isXmlFragment, true);
34 34
 
35 35
         return $parser->extractNodes();
36 36
     }
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
      */
41 41
     protected function getNodeListFromQueryPath() {
42 42
 
43
-        $xpath = new DOMXPath( $this->dom );
43
+        $xpath = new DOMXPath($this->dom);
44 44
 
45
-        if ( $this->isXmlFragment ) {
46
-            $htmlNodeList = $xpath->query( "/" . self::fragmentDocumentRoot );
45
+        if ($this->isXmlFragment) {
46
+            $htmlNodeList = $xpath->query("/".self::fragmentDocumentRoot);
47 47
         } else {
48
-            $htmlNodeList = $xpath->query( "/html" );
48
+            $htmlNodeList = $xpath->query("/html");
49 49
         }
50 50
 
51 51
         return $htmlNodeList;
Please login to merge, or discard this patch.
src/XmlParser.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
      * @throws InvalidXmlException
31 31
      * @throws XmlParsingException
32 32
      */
33
-    public static function parse( $xml, $isXmlFragment = false ) {
34
-        $parser = new static( $xml, $isXmlFragment );
33
+    public static function parse($xml, $isXmlFragment = false) {
34
+        $parser = new static($xml, $isXmlFragment);
35 35
 
36 36
         return $parser->extractNodes();
37 37
     }
@@ -39,14 +39,14 @@  discard block
 block discarded – undo
39 39
     /**
40 40
      * @return DOMNodeList
41 41
      */
42
-    protected function getNodeListFromQueryPath(){
42
+    protected function getNodeListFromQueryPath() {
43 43
 
44
-        $xpath = new DOMXPath( $this->dom );
44
+        $xpath = new DOMXPath($this->dom);
45 45
 
46
-        if ( $this->isXmlFragment ) {
47
-            $xmlNodeList = $xpath->query( "/" . self::fragmentDocumentRoot );
46
+        if ($this->isXmlFragment) {
47
+            $xmlNodeList = $xpath->query("/".self::fragmentDocumentRoot);
48 48
         } else {
49
-            $xmlNodeList = $xpath->query( "*" );
49
+            $xmlNodeList = $xpath->query("*");
50 50
         }
51 51
 
52 52
         return $xmlNodeList;
Please login to merge, or discard this patch.
src/AbstractParser.php 1 patch
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -25,39 +25,39 @@  discard block
 block discarded – undo
25 25
     const regexpEntity         = '/&#x([0-1]{0,1}[0-9A-F]{1,2})/u'; //  
26 26
     const regexpAscii          = '/([\x{00}-\x{1F}\x{7F}]{1})/u';
27 27
     protected static $asciiPlaceHoldMap = [
28
-            '00' => [ 'symbol' => 'NULL', 'placeHold' => '', 'numeral' => 0x00 ],
29
-            '01' => [ 'symbol' => 'SOH', 'placeHold' => '', 'numeral' => 0x01 ],
30
-            '02' => [ 'symbol' => 'STX', 'placeHold' => '', 'numeral' => 0x02 ],
31
-            '03' => [ 'symbol' => 'ETX', 'placeHold' => '', 'numeral' => 0x03 ],
32
-            '04' => [ 'symbol' => 'EOT', 'placeHold' => '', 'numeral' => 0x04 ],
33
-            '05' => [ 'symbol' => 'ENQ', 'placeHold' => '', 'numeral' => 0x05 ],
34
-            '06' => [ 'symbol' => 'ACK', 'placeHold' => '', 'numeral' => 0x06 ],
35
-            '07' => [ 'symbol' => 'BEL', 'placeHold' => '', 'numeral' => 0x07 ],
36
-            '08' => [ 'symbol' => 'BS', 'placeHold' => '', 'numeral' => 0x08 ],
37
-            '09' => [ 'symbol' => 'HT', 'placeHold' => '', 'numeral' => 0x09 ],
38
-            '0A' => [ 'symbol' => 'LF', 'placeHold' => '', 'numeral' => 0x0A ],
39
-            '0B' => [ 'symbol' => 'VT', 'placeHold' => '', 'numeral' => 0x0B ],
40
-            '0C' => [ 'symbol' => 'FF', 'placeHold' => '', 'numeral' => 0x0C ],
41
-            '0D' => [ 'symbol' => 'CR', 'placeHold' => '', 'numeral' => 0x0D ],
42
-            '0E' => [ 'symbol' => 'SO', 'placeHold' => '', 'numeral' => 0x0E ],
43
-            '0F' => [ 'symbol' => 'SI', 'placeHold' => '', 'numeral' => 0x0F ],
44
-            '10' => [ 'symbol' => 'DLE', 'placeHold' => '', 'numeral' => 0x10 ],
45
-            '11' => [ 'symbol' => 'DC', 'placeHold' => '', 'numeral' => 0x11 ],
46
-            '12' => [ 'symbol' => 'DC', 'placeHold' => '', 'numeral' => 0x12 ],
47
-            '13' => [ 'symbol' => 'DC', 'placeHold' => '', 'numeral' => 0x13 ],
48
-            '14' => [ 'symbol' => 'DC', 'placeHold' => '', 'numeral' => 0x14 ],
49
-            '15' => [ 'symbol' => 'NAK', 'placeHold' => '', 'numeral' => 0x15 ],
50
-            '16' => [ 'symbol' => 'SYN', 'placeHold' => '', 'numeral' => 0x16 ],
51
-            '17' => [ 'symbol' => 'ETB', 'placeHold' => '', 'numeral' => 0x17 ],
52
-            '18' => [ 'symbol' => 'CAN', 'placeHold' => '', 'numeral' => 0x18 ],
53
-            '19' => [ 'symbol' => 'EM', 'placeHold' => '', 'numeral' => 0x19 ],
54
-            '1A' => [ 'symbol' => 'SUB', 'placeHold' => '', 'numeral' => 0x1A ],
55
-            '1B' => [ 'symbol' => 'ESC', 'placeHold' => '', 'numeral' => 0x1B ],
56
-            '1C' => [ 'symbol' => 'FS', 'placeHold' => '', 'numeral' => 0x1C ],
57
-            '1D' => [ 'symbol' => 'GS', 'placeHold' => '', 'numeral' => 0x1D ],
58
-            '1E' => [ 'symbol' => 'RS', 'placeHold' => '', 'numeral' => 0x1E ],
59
-            '1F' => [ 'symbol' => 'US', 'placeHold' => '', 'numeral' => 0x1F ],
60
-            '7F' => [ 'symbol' => 'DEL', 'placeHold' => '', 'numeral' => 0x7F ],
28
+            '00' => ['symbol' => 'NULL', 'placeHold' => '', 'numeral' => 0x00],
29
+            '01' => ['symbol' => 'SOH', 'placeHold' => '', 'numeral' => 0x01],
30
+            '02' => ['symbol' => 'STX', 'placeHold' => '', 'numeral' => 0x02],
31
+            '03' => ['symbol' => 'ETX', 'placeHold' => '', 'numeral' => 0x03],
32
+            '04' => ['symbol' => 'EOT', 'placeHold' => '', 'numeral' => 0x04],
33
+            '05' => ['symbol' => 'ENQ', 'placeHold' => '', 'numeral' => 0x05],
34
+            '06' => ['symbol' => 'ACK', 'placeHold' => '', 'numeral' => 0x06],
35
+            '07' => ['symbol' => 'BEL', 'placeHold' => '', 'numeral' => 0x07],
36
+            '08' => ['symbol' => 'BS', 'placeHold' => '', 'numeral' => 0x08],
37
+            '09' => ['symbol' => 'HT', 'placeHold' => '', 'numeral' => 0x09],
38
+            '0A' => ['symbol' => 'LF', 'placeHold' => '', 'numeral' => 0x0A],
39
+            '0B' => ['symbol' => 'VT', 'placeHold' => '', 'numeral' => 0x0B],
40
+            '0C' => ['symbol' => 'FF', 'placeHold' => '', 'numeral' => 0x0C],
41
+            '0D' => ['symbol' => 'CR', 'placeHold' => '', 'numeral' => 0x0D],
42
+            '0E' => ['symbol' => 'SO', 'placeHold' => '', 'numeral' => 0x0E],
43
+            '0F' => ['symbol' => 'SI', 'placeHold' => '', 'numeral' => 0x0F],
44
+            '10' => ['symbol' => 'DLE', 'placeHold' => '', 'numeral' => 0x10],
45
+            '11' => ['symbol' => 'DC', 'placeHold' => '', 'numeral' => 0x11],
46
+            '12' => ['symbol' => 'DC', 'placeHold' => '', 'numeral' => 0x12],
47
+            '13' => ['symbol' => 'DC', 'placeHold' => '', 'numeral' => 0x13],
48
+            '14' => ['symbol' => 'DC', 'placeHold' => '', 'numeral' => 0x14],
49
+            '15' => ['symbol' => 'NAK', 'placeHold' => '', 'numeral' => 0x15],
50
+            '16' => ['symbol' => 'SYN', 'placeHold' => '', 'numeral' => 0x16],
51
+            '17' => ['symbol' => 'ETB', 'placeHold' => '', 'numeral' => 0x17],
52
+            '18' => ['symbol' => 'CAN', 'placeHold' => '', 'numeral' => 0x18],
53
+            '19' => ['symbol' => 'EM', 'placeHold' => '', 'numeral' => 0x19],
54
+            '1A' => ['symbol' => 'SUB', 'placeHold' => '', 'numeral' => 0x1A],
55
+            '1B' => ['symbol' => 'ESC', 'placeHold' => '', 'numeral' => 0x1B],
56
+            '1C' => ['symbol' => 'FS', 'placeHold' => '', 'numeral' => 0x1C],
57
+            '1D' => ['symbol' => 'GS', 'placeHold' => '', 'numeral' => 0x1D],
58
+            '1E' => ['symbol' => 'RS', 'placeHold' => '', 'numeral' => 0x1E],
59
+            '1F' => ['symbol' => 'US', 'placeHold' => '', 'numeral' => 0x1F],
60
+            '7F' => ['symbol' => 'DEL', 'placeHold' => '', 'numeral' => 0x7F],
61 61
     ];
62 62
 
63 63
     /**
@@ -76,14 +76,14 @@  discard block
 block discarded – undo
76 76
      * @throws InvalidXmlException
77 77
      * @throws XmlParsingException
78 78
      */
79
-    protected function __construct( $xml, $isXmlFragment, $isHtml = false ) {
80
-        $xml                 = $this->removeNotPrintableChars( $xml );
79
+    protected function __construct($xml, $isXmlFragment, $isHtml = false) {
80
+        $xml                 = $this->removeNotPrintableChars($xml);
81 81
         $this->isXmlFragment = $isXmlFragment;
82 82
 
83 83
         $this->dom = XmlDomLoader::load(
84 84
                 $xml,
85 85
                 new Config(
86
-                        ( $isXmlFragment ? self::fragmentDocumentRoot : null ),
86
+                        ($isXmlFragment ? self::fragmentDocumentRoot : null),
87 87
                         $isHtml,
88 88
                         LIBXML_NONET | LIBXML_NOBLANKS
89 89
                 )
@@ -100,36 +100,36 @@  discard block
 block discarded – undo
100 100
      *
101 101
      * @return string
102 102
      */
103
-    protected function removeNotPrintableChars( $seg ) {
103
+    protected function removeNotPrintableChars($seg) {
104 104
 
105
-        preg_match_all( self::regexpAscii, $seg, $matches );
105
+        preg_match_all(self::regexpAscii, $seg, $matches);
106 106
 
107
-        if ( !empty( $matches[ 1 ] ) ) {
107
+        if (!empty($matches[1])) {
108 108
             $test_src = $seg;
109
-            foreach ( $matches[ 1 ] as $v ) {
110
-                $key      = sprintf( "%02X", ord( $v ) );
111
-                $hexNum   = sprintf( "/(\\x{%s})/u", $key );
112
-                $test_src = preg_replace( $hexNum, self::$asciiPlaceHoldMap[ $key ][ 'placeHold' ], $test_src, 1 );
109
+            foreach ($matches[1] as $v) {
110
+                $key      = sprintf("%02X", ord($v));
111
+                $hexNum   = sprintf("/(\\x{%s})/u", $key);
112
+                $test_src = preg_replace($hexNum, self::$asciiPlaceHoldMap[$key]['placeHold'], $test_src, 1);
113 113
             }
114 114
 
115 115
             $seg = $test_src;
116 116
         }
117 117
 
118
-        preg_match_all( self::regexpEntity, $seg, $matches );
118
+        preg_match_all(self::regexpEntity, $seg, $matches);
119 119
 
120
-        if ( !empty( $matches[ 1 ] ) ) {
120
+        if (!empty($matches[1])) {
121 121
             $test_src = $seg;
122
-            foreach ( $matches[ 1 ] as $v ) {
123
-                $byte = sprintf( "%02X", hexdec( $v ) );
124
-                if ( $byte[ 0 ] == '0' ) {
125
-                    $regexp = '/&#x([' . $byte[ 0 ] . ']?' . $byte[ 1 ] . ');/u';
122
+            foreach ($matches[1] as $v) {
123
+                $byte = sprintf("%02X", hexdec($v));
124
+                if ($byte[0] == '0') {
125
+                    $regexp = '/&#x(['.$byte[0].']?'.$byte[1].');/u';
126 126
                 } else {
127
-                    $regexp = '/&#x(' . $byte . ');/u';
127
+                    $regexp = '/&#x('.$byte.');/u';
128 128
                 }
129 129
 
130
-                $key = sprintf( "%02X", hexdec( $v ) );
131
-                if ( array_key_exists( $key, self::$asciiPlaceHoldMap ) ) {
132
-                    $test_src = preg_replace( $regexp, self::$asciiPlaceHoldMap[ $key ][ 'placeHold' ], $test_src );
130
+                $key = sprintf("%02X", hexdec($v));
131
+                if (array_key_exists($key, self::$asciiPlaceHoldMap)) {
132
+                    $test_src = preg_replace($regexp, self::$asciiPlaceHoldMap[$key]['placeHold'], $test_src);
133 133
                 }
134 134
 
135 135
             }
@@ -146,20 +146,20 @@  discard block
 block discarded – undo
146 146
      *
147 147
      * @return ArrayObject
148 148
      */
149
-    protected function mapElements( DOMNodeList $elementList, ArrayObject $elements ) {
149
+    protected function mapElements(DOMNodeList $elementList, ArrayObject $elements) {
150 150
 
151
-        for ( $i = 0; $i < $elementList->length; $i++ ) {
151
+        for ($i = 0; $i < $elementList->length; $i++) {
152 152
 
153
-            $element = $elementList->item( $i );
153
+            $element = $elementList->item($i);
154 154
 
155
-            $elements[] = (object)[
156
-                    'node'         => $this->dom->saveXML( $element ),
155
+            $elements[] = (object) [
156
+                    'node'         => $this->dom->saveXML($element),
157 157
                     'tagName'      => $element->nodeName,
158
-                    'attributes'   => $this->getAttributes( $element ),
159
-                    'text'         => ( $element instanceof DOMText ) ? $element->textContent : null,
160
-                    'self_closed'  => ( $element instanceof DOMText ) ? null : !$element->hasChildNodes(),
161
-                    'has_children' => ( $element instanceof DOMText ) ? null : $element->hasChildNodes(),
162
-                    'inner_html'   => $element->hasChildNodes() ? $this->mapElements( $element->childNodes, new ArrayObject() ) : new ArrayObject()
158
+                    'attributes'   => $this->getAttributes($element),
159
+                    'text'         => ($element instanceof DOMText) ? $element->textContent : null,
160
+                    'self_closed'  => ($element instanceof DOMText) ? null : !$element->hasChildNodes(),
161
+                    'has_children' => ($element instanceof DOMText) ? null : $element->hasChildNodes(),
162
+                    'inner_html'   => $element->hasChildNodes() ? $this->mapElements($element->childNodes, new ArrayObject()) : new ArrayObject()
163 163
             ];
164 164
 
165 165
         }
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
      *
174 174
      * @return array
175 175
      */
176
-    protected function getAttributes( DOMNode $element ) {
176
+    protected function getAttributes(DOMNode $element) {
177 177
 
178
-        if ( !$element->hasAttributes() ) {
178
+        if (!$element->hasAttributes()) {
179 179
             return [];
180 180
         }
181 181
 
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
         /**
185 185
          * @var DOMAttr $attr
186 186
          */
187
-        foreach ( $element->attributes as $attr ) {
188
-            $attributesMap[ $attr->nodeName ] = $attr->nodeValue;
187
+        foreach ($element->attributes as $attr) {
188
+            $attributesMap[$attr->nodeName] = $attr->nodeValue;
189 189
         }
190 190
 
191 191
         return $attributesMap;
@@ -200,15 +200,15 @@  discard block
 block discarded – undo
200 200
 
201 201
         $htmlNodeList = $this->getNodeListFromQueryPath();
202 202
 
203
-        if ( !$htmlNodeList instanceof DOMNodeList ) {
204
-            throw new DOMException( 'Bad DOMNodeList' );
203
+        if (!$htmlNodeList instanceof DOMNodeList) {
204
+            throw new DOMException('Bad DOMNodeList');
205 205
         }
206 206
 
207
-        if ( $this->isXmlFragment && $htmlNodeList->item( 0 )->nodeName == self::fragmentDocumentRoot ) {
207
+        if ($this->isXmlFragment && $htmlNodeList->item(0)->nodeName == self::fragmentDocumentRoot) {
208 208
             // there is a fake root node, skip the first element end start with child nodes
209
-            $this->mapElements( $htmlNodeList->item( 0 )->childNodes, $this->elements );
209
+            $this->mapElements($htmlNodeList->item(0)->childNodes, $this->elements);
210 210
         } else {
211
-            $this->mapElements( $htmlNodeList, $this->elements );
211
+            $this->mapElements($htmlNodeList, $this->elements);
212 212
         }
213 213
 
214 214
         return $this->elements;
Please login to merge, or discard this patch.