@@ -39,8 +39,8 @@ discard block  | 
                                                    ||
| 39 | 39 | }  | 
                                                        
| 40 | 40 | |
| 41 | 41 | /**  | 
                                                        
| 42 | - * @param $selector  | 
                                                        |
| 43 | - * @param $index  | 
                                                        |
| 42 | + * @param string|null $selector  | 
                                                        |
| 43 | + * @param null|integer $index  | 
                                                        |
| 44 | 44 | * @param string $property  | 
                                                        
| 45 | 45 | * @param int $nodeType  | 
                                                        
| 46 | 46 | *  | 
                                                        
@@ -198,7 +198,7 @@ discard block  | 
                                                    ||
| 198 | 198 | }  | 
                                                        
| 199 | 199 | |
| 200 | 200 | /**  | 
                                                        
| 201 | - * @return \DOMNode|null  | 
                                                        |
| 201 | + * @return Element|null  | 
                                                        |
| 202 | 202 | */  | 
                                                        
| 203 | 203 |  	public function firstDescendant(){ | 
                                                        
| 204 | 204 | return $this->descendants()[0] ?? null;  | 
                                                        
@@ -14,7 +14,7 @@ discard block  | 
                                                    ||
| 14 | 14 | |
| 15 | 15 | use DOMElement;  | 
                                                        
| 16 | 16 | |
| 17 | -class Element extends DOMElement{ | 
                                                        |
| 17 | +class Element extends DOMElement { | 
                                                        |
| 18 | 18 | use NodeTraversalTrait, NodeManipulationTrait;  | 
                                                        
| 19 | 19 | |
| 20 | 20 | /**  | 
                                                        
@@ -25,7 +25,7 @@ discard block  | 
                                                    ||
| 25 | 25 |  	public function id(string $newID = null):string { | 
                                                        
| 26 | 26 |  		$oldID = $this->getAttribute('id'); | 
                                                        
| 27 | 27 | |
| 28 | -		if(!is_null($newID)){ | 
                                                        |
| 28 | +		if (!is_null($newID)) { | 
                                                        |
| 29 | 29 |  			$this->setAttribute('id', $newID); | 
                                                        
| 30 | 30 | }  | 
                                                        
| 31 | 31 | |
@@ -38,14 +38,14 @@ discard block  | 
                                                    ||
| 38 | 38 |  	public function getClassNames():array{ | 
                                                        
| 39 | 39 | $currentClassnames = [];  | 
                                                        
| 40 | 40 | |
| 41 | -		if($this->hasAttributes()){ | 
                                                        |
| 41 | +		if ($this->hasAttributes()) { | 
                                                        |
| 42 | 42 |  			$classnames = explode(' ', trim($this->getAttribute('class'))); | 
                                                        
| 43 | 43 | |
| 44 | -			if(!empty($classnames)){ | 
                                                        |
| 44 | +			if (!empty($classnames)) { | 
                                                        |
| 45 | 45 | |
| 46 | -				foreach($classnames as $classname){ | 
                                                        |
| 46 | +				foreach ($classnames as $classname) { | 
                                                        |
| 47 | 47 | |
| 48 | -					if(empty($classname)){ | 
                                                        |
| 48 | +					if (empty($classname)) { | 
                                                        |
| 49 | 49 | continue;  | 
                                                        
| 50 | 50 | }  | 
                                                        
| 51 | 51 | |
@@ -76,9 +76,9 @@ discard block  | 
                                                    ||
| 76 | 76 |  	public function addClassNames(array $classnames):Element{ | 
                                                        
| 77 | 77 | $currentClassnames = $this->getClassNames();  | 
                                                        
| 78 | 78 | |
| 79 | -		foreach($classnames as $classname){ | 
                                                        |
| 79 | +		foreach ($classnames as $classname) { | 
                                                        |
| 80 | 80 | |
| 81 | -			if(!in_array($classname, $currentClassnames, true)){ | 
                                                        |
| 81 | +			if (!in_array($classname, $currentClassnames, true)) { | 
                                                        |
| 82 | 82 | array_push($currentClassnames, $classname);  | 
                                                        
| 83 | 83 | }  | 
                                                        
| 84 | 84 | |
@@ -97,12 +97,12 @@ discard block  | 
                                                    ||
| 97 | 97 |  	public function removeClassNames(array $classnames):Element{ | 
                                                        
| 98 | 98 | $currentClassnames = $this->getClassNames();  | 
                                                        
| 99 | 99 | |
| 100 | -		foreach($classnames as $classname){ | 
                                                        |
| 100 | +		foreach ($classnames as $classname) { | 
                                                        |
| 101 | 101 | $keys = array_keys($currentClassnames, $classname);  | 
                                                        
| 102 | 102 | |
| 103 | -			if(!empty($keys)){ | 
                                                        |
| 103 | +			if (!empty($keys)) { | 
                                                        |
| 104 | 104 | |
| 105 | -				foreach($keys as $key){ | 
                                                        |
| 105 | +				foreach ($keys as $key) { | 
                                                        |
| 106 | 106 | unset($currentClassnames[$key]);  | 
                                                        
| 107 | 107 | }  | 
                                                        
| 108 | 108 | |
@@ -151,15 +151,15 @@ discard block  | 
                                                    ||
| 151 | 151 |  	public function getStyle():array{ | 
                                                        
| 152 | 152 | $currentStyle = [];  | 
                                                        
| 153 | 153 | |
| 154 | -		if($this->hasAttributes()){ | 
                                                        |
| 154 | +		if ($this->hasAttributes()) { | 
                                                        |
| 155 | 155 |  			$styles = explode(';', trim($this->getAttribute('style'))); | 
                                                        
| 156 | 156 | |
| 157 | -			if(!empty($styles)){ | 
                                                        |
| 157 | +			if (!empty($styles)) { | 
                                                        |
| 158 | 158 | |
| 159 | -				foreach($styles as $style){ | 
                                                        |
| 159 | +				foreach ($styles as $style) { | 
                                                        |
| 160 | 160 |  					$s = explode(':', $style); | 
                                                        
| 161 | 161 | |
| 162 | -					if(count($s) === 2){ | 
                                                        |
| 162 | +					if (count($s) === 2) { | 
                                                        |
| 163 | 163 | $currentStyle[strtolower(trim($s[0]))] = trim($s[1]);  | 
                                                        
| 164 | 164 | }  | 
                                                        
| 165 | 165 | |
@@ -177,10 +177,10 @@ discard block  | 
                                                    ||
| 177 | 177 | *  | 
                                                        
| 178 | 178 | * @return bool|string  | 
                                                        
| 179 | 179 | */  | 
                                                        
| 180 | -	public function hasStyle(string $property){ | 
                                                        |
| 180 | +	public function hasStyle(string $property) { | 
                                                        |
| 181 | 181 | $currentStyle = $this->getStyle();  | 
                                                        
| 182 | 182 | |
| 183 | -		if(array_key_exists(strtolower($property), $currentStyle)){ | 
                                                        |
| 183 | +		if (array_key_exists(strtolower($property), $currentStyle)) { | 
                                                        |
| 184 | 184 | return $currentStyle[$property];  | 
                                                        
| 185 | 185 | }  | 
                                                        
| 186 | 186 | |
@@ -196,11 +196,11 @@ discard block  | 
                                                    ||
| 196 | 196 |  	public function setStyle(array $style, bool $replace = false):Element{ | 
                                                        
| 197 | 197 | $currentStyle = $this->getStyle();  | 
                                                        
| 198 | 198 | |
| 199 | -		if(!$replace){ | 
                                                        |
| 199 | +		if (!$replace) { | 
                                                        |
| 200 | 200 | $style = array_merge($currentStyle, $style);  | 
                                                        
| 201 | 201 | }  | 
                                                        
| 202 | 202 | |
| 203 | -		foreach($style as $property => $value){ | 
                                                        |
| 203 | +		foreach ($style as $property => $value) { | 
                                                        |
| 204 | 204 | $style[$property] = $property.': '.$value.';';  | 
                                                        
| 205 | 205 | }  | 
                                                        
| 206 | 206 | |
@@ -215,7 +215,7 @@ discard block  | 
                                                    ||
| 215 | 215 |  	public function getAttributes():array{ | 
                                                        
| 216 | 216 | $attributes = [];  | 
                                                        
| 217 | 217 | |
| 218 | -		foreach($this->attributes as $attribute){ | 
                                                        |
| 218 | +		foreach ($this->attributes as $attribute) { | 
                                                        |
| 219 | 219 | $attributes[$attribute->nodeName] = $attribute->nodeValue;  | 
                                                        
| 220 | 220 | }  | 
                                                        
| 221 | 221 | |
@@ -229,7 +229,7 @@ discard block  | 
                                                    ||
| 229 | 229 | */  | 
                                                        
| 230 | 230 |  	public function setAttributes(array $attributes):Element{ | 
                                                        
| 231 | 231 | |
| 232 | -		foreach($attributes as $name => $value){ | 
                                                        |
| 232 | +		foreach ($attributes as $name => $value) { | 
                                                        |
| 233 | 233 | $this->setAttribute($name, $value);  | 
                                                        
| 234 | 234 | }  | 
                                                        
| 235 | 235 | |
@@ -243,7 +243,7 @@ discard block  | 
                                                    ||
| 243 | 243 | */  | 
                                                        
| 244 | 244 |  	public function removeAttributes(array $attributes):Element{ | 
                                                        
| 245 | 245 | |
| 246 | -		foreach($attributes as $name){ | 
                                                        |
| 246 | +		foreach ($attributes as $name) { | 
                                                        |
| 247 | 247 | $this->removeAttribute($name);  | 
                                                        
| 248 | 248 | }  | 
                                                        
| 249 | 249 | |
@@ -15,7 +15,7 @@ discard block  | 
                                                    ||
| 15 | 15 | use DOMDocument, DOMNode, DOMNodeList, DOMXPath;  | 
                                                        
| 16 | 16 | use Symfony\Component\CssSelector\CssSelectorConverter;  | 
                                                        
| 17 | 17 | |
| 18 | -class Document extends DOMDocument{ | 
                                                        |
| 18 | +class Document extends DOMDocument { | 
                                                        |
| 19 | 19 | |
| 20 | 20 | /**  | 
                                                        
| 21 | 21 | * Document constructor.  | 
                                                        
@@ -23,7 +23,7 @@ discard block  | 
                                                    ||
| 23 | 23 | * @param string|null $version  | 
                                                        
| 24 | 24 | * @param string|null $encoding  | 
                                                        
| 25 | 25 | */  | 
                                                        
| 26 | -	public function __construct($version = null, $encoding = null){ | 
                                                        |
| 26 | +	public function __construct($version = null, $encoding = null) { | 
                                                        |
| 27 | 27 | parent::__construct($version, $encoding);  | 
                                                        
| 28 | 28 | |
| 29 | 29 |  		$this->registerNodeClass('DOMElement', Element::class); | 
                                                        
@@ -73,21 +73,21 @@ discard block  | 
                                                    ||
| 73 | 73 | */  | 
                                                        
| 74 | 74 |  	public function select($selectors = null, DOMNode $contextNode = null, string $axis = 'descendant-or-self::', int $nodeType = XML_ELEMENT_NODE):array{ | 
                                                        
| 75 | 75 | |
| 76 | -		if(is_string($selectors)){ | 
                                                        |
| 76 | +		if (is_string($selectors)) { | 
                                                        |
| 77 | 77 | $selectors = [trim($selectors)];  | 
                                                        
| 78 | 78 | }  | 
                                                        
| 79 | 79 | |
| 80 | -		if(!is_array($selectors) || empty($selectors)){ | 
                                                        |
| 80 | +		if (!is_array($selectors) || empty($selectors)) { | 
                                                        |
| 81 | 81 | $selectors = ['*'];  | 
                                                        
| 82 | 82 | }  | 
                                                        
| 83 | 83 | |
| 84 | 84 | $elements = [];  | 
                                                        
| 85 | 85 | |
| 86 | -		foreach($selectors as $selector){ | 
                                                        |
| 86 | +		foreach ($selectors as $selector) { | 
                                                        |
| 87 | 87 | |
| 88 | -			foreach($this->getElementsBySelector($selector, $contextNode, $axis) as $element){ | 
                                                        |
| 88 | +			foreach ($this->getElementsBySelector($selector, $contextNode, $axis) as $element) { | 
                                                        |
| 89 | 89 | |
| 90 | -				if($element->nodeType === $nodeType){ | 
                                                        |
| 90 | +				if ($element->nodeType === $nodeType) { | 
                                                        |
| 91 | 91 | $elements[] = $element;  | 
                                                        
| 92 | 92 | }  | 
                                                        
| 93 | 93 | |
@@ -120,9 +120,9 @@ discard block  | 
                                                    ||
| 120 | 120 |  	public function removeElementsBySelector($selectors, DOMNode $contextNode = null, string $axis = 'descendant-or-self::'):Document{ | 
                                                        
| 121 | 121 | $nodes = $this->select($selectors, $contextNode, $axis);  | 
                                                        
| 122 | 122 | |
| 123 | -		if(count($nodes) > 0){ | 
                                                        |
| 123 | +		if (count($nodes) > 0) { | 
                                                        |
| 124 | 124 | /** @var \chillerlan\PrototypeDOM\Element $node */  | 
                                                        
| 125 | -			foreach($nodes as $node){ | 
                                                        |
| 125 | +			foreach ($nodes as $node) { | 
                                                        |
| 126 | 126 | $node->remove();  | 
                                                        
| 127 | 127 | }  | 
                                                        
| 128 | 128 | |
@@ -139,21 +139,21 @@ discard block  | 
                                                    ||
| 139 | 139 | */  | 
                                                        
| 140 | 140 |  	public function _toDOMNodeList($content):DOMNodeList{ | 
                                                        
| 141 | 141 | |
| 142 | -		if($content instanceof DOMNodeList){ | 
                                                        |
| 142 | +		if ($content instanceof DOMNodeList) { | 
                                                        |
| 143 | 143 | return $content;  | 
                                                        
| 144 | 144 | }  | 
                                                        
| 145 | 145 | |
| 146 | 146 | $document = new Document;  | 
                                                        
| 147 | 147 | |
| 148 | -		if($content instanceof DOMNode){ | 
                                                        |
| 148 | +		if ($content instanceof DOMNode) { | 
                                                        |
| 149 | 149 |  			$document->loadHTML('<html><body id="content"></body></html>'); | 
                                                        
| 150 | 150 | |
| 151 | 151 |  			$document->getElementById('content')->appendChild($document->importNode($content, true)); | 
                                                        
| 152 | 152 | }  | 
                                                        
| 153 | -		elseif(is_string($content)){ | 
                                                        |
| 153 | +		elseif (is_string($content)) { | 
                                                        |
| 154 | 154 |  			$document->loadHTML('<html><body id="content">'.$content.'</body></html>'); | 
                                                        
| 155 | 155 | }  | 
                                                        
| 156 | -		else{ | 
                                                        |
| 156 | +		else { | 
                                                        |
| 157 | 157 |  			throw new \Exception('invalid content'); // @codeCoverageIgnore | 
                                                        
| 158 | 158 | }  | 
                                                        
| 159 | 159 | |
@@ -171,15 +171,15 @@ discard block  | 
                                                    ||
| 171 | 171 |  	public function recursivelyCollect(DOMNode $element, string $property, int $maxLength = -1, int $nodeType = XML_ELEMENT_NODE):array{ | 
                                                        
| 172 | 172 | $nodes = [];  | 
                                                        
| 173 | 173 | |
| 174 | -		if(in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])){ | 
                                                        |
| 174 | +		if (in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])) { | 
                                                        |
| 175 | 175 | |
| 176 | -			while($element = $element->{$property}){ | 
                                                        |
| 176 | +			while ($element = $element->{$property}) { | 
                                                        |
| 177 | 177 | |
| 178 | -				if($element->nodeType === $nodeType){ | 
                                                        |
| 178 | +				if ($element->nodeType === $nodeType) { | 
                                                        |
| 179 | 179 | $nodes[] = $element;  | 
                                                        
| 180 | 180 | }  | 
                                                        
| 181 | 181 | |
| 182 | -				if(count($nodes) === $maxLength){ | 
                                                        |
| 182 | +				if (count($nodes) === $maxLength) { | 
                                                        |
| 183 | 183 | break;  | 
                                                        
| 184 | 184 | }  | 
                                                        
| 185 | 185 | |
@@ -199,14 +199,14 @@ discard block  | 
                                                    ||
| 199 | 199 | *  | 
                                                        
| 200 | 200 | * @return \DOMNode|null  | 
                                                        
| 201 | 201 | */  | 
                                                        
| 202 | -	public function _recursivelyFind(DOMNode $element, string $property, string $selector = null, int $index = 0, int $nodeType = XML_ELEMENT_NODE){ | 
                                                        |
| 202 | +	public function _recursivelyFind(DOMNode $element, string $property, string $selector = null, int $index = 0, int $nodeType = XML_ELEMENT_NODE) { | 
                                                        |
| 203 | 203 | |
| 204 | -		if(in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])){ | 
                                                        |
| 204 | +		if (in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])) { | 
                                                        |
| 205 | 205 | |
| 206 | 206 | /** @var \chillerlan\PrototypeDOM\Element $element */  | 
                                                        
| 207 | -			while($element = $element->{$property}){ | 
                                                        |
| 207 | +			while ($element = $element->{$property}) { | 
                                                        |
| 208 | 208 | |
| 209 | -				if($element->nodeType !== $nodeType || !is_null($selector) && !$element->match($selector) || --$index >= 0){ | 
                                                        |
| 209 | +				if ($element->nodeType !== $nodeType || !is_null($selector) && !$element->match($selector) || --$index >= 0) { | 
                                                        |
| 210 | 210 | continue;  | 
                                                        
| 211 | 211 | }  | 
                                                        
| 212 | 212 | |
@@ -226,9 +226,9 @@ discard block  | 
                                                    ||
| 226 | 226 | */  | 
                                                        
| 227 | 227 |  	public function match(DOMNode $element, string $selector):bool{ | 
                                                        
| 228 | 228 | |
| 229 | -		foreach($this->select($selector) as $match){ | 
                                                        |
| 229 | +		foreach ($this->select($selector) as $match) { | 
                                                        |
| 230 | 230 | |
| 231 | -			if($element->isSameNode($match)){ | 
                                                        |
| 231 | +			if ($element->isSameNode($match)) { | 
                                                        |
| 232 | 232 | return true;  | 
                                                        
| 233 | 233 | }  | 
                                                        
| 234 | 234 | |
@@ -247,7 +247,7 @@ discard block  | 
                                                    ||
| 247 | 247 | /** @var \chillerlan\PrototypeDOM\Element $element */  | 
                                                        
| 248 | 248 | $element = $this->createElement($tag);  | 
                                                        
| 249 | 249 | |
| 250 | -		if($attributes){ | 
                                                        |
| 250 | +		if ($attributes) { | 
                                                        |
| 251 | 251 | $element->setAttributes($attributes);  | 
                                                        
| 252 | 252 | }  | 
                                                        
| 253 | 253 | |