Passed
Push — master ( 6db13f...a4c5d4 )
by smiley
15:37
created
src/Document.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 /**
27 27
  *
28 28
  */
29
-class Document extends DOMDocument{
29
+class Document extends DOMDocument {
30 30
 
31 31
 	protected const NODE_CLASSES = [
32 32
 		'DOMAttr'                  => Attr::class,
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
 	/**
52 52
 	 * Document constructor.
53 53
 	 */
54
-	public function __construct($content = null, bool $xml = null, string $version = null, string $encoding = null){
54
+	public function __construct($content = null, bool $xml = null, string $version = null, string $encoding = null) {
55 55
 		parent::__construct($version ?? '1.0', $encoding ?? 'UTF-8');
56 56
 
57
-		foreach($this::NODE_CLASSES as $baseClass => $extendedClass){
57
+		foreach ($this::NODE_CLASSES as $baseClass => $extendedClass) {
58 58
 			$this->registerNodeClass($baseClass, $extendedClass);
59 59
 		}
60 60
 
61
-		if($content !== null){
61
+		if ($content !== null) {
62 62
 			$this->loadDocument($content, $xml);
63 63
 		}
64 64
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	/**
73 73
 	 * @return string|null
74 74
 	 */
75
-	public function getTitle():?string{
75
+	public function getTitle(): ?string{
76 76
 		return $this->select(['head > title'])->item(0)->nodeValue ?? null;
77 77
 	}
78 78
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	public function setTitle(string $title):void{
83 83
 		$currentTitle = $this->select(['head > title'])->item(0);
84 84
 
85
-		if($currentTitle instanceof Element){
85
+		if ($currentTitle instanceof Element) {
86 86
 			$currentTitle->update($title);
87 87
 
88 88
 			return;
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
 		$head         = $this->select(['head'])->item(0);
92 92
 		$currentTitle = $this->newElement('title')->update($title);
93 93
 
94
-		if(!$head){
94
+		if (!$head) {
95 95
 			$html = $this->select(['html'])->first();
96 96
 
97
-			if(!$html instanceof PrototypeHTMLElement){
97
+			if (!$html instanceof PrototypeHTMLElement) {
98 98
 				throw new DOMException('html header missing');
99 99
 			}
100 100
 
@@ -114,19 +114,19 @@  discard block
 block discarded – undo
114 114
 	 */
115 115
 	public function loadDocument($content, bool $xml = null):Document{
116 116
 
117
-		if($content instanceof NodeList){
117
+		if ($content instanceof NodeList) {
118 118
 			return $this->insertNodeList($content);
119 119
 		}
120 120
 
121
-		if($content instanceof DOMNodeList){
121
+		if ($content instanceof DOMNodeList) {
122 122
 			return $this->insertNodeList(new NodeList($content));
123 123
 		}
124 124
 
125
-		if(!is_string($content)){
125
+		if (!is_string($content)) {
126 126
 			throw new DOMException('invalid document content');
127 127
 		}
128 128
 
129
-		if(is_file($content) && is_readable($content)){
129
+		if (is_file($content) && is_readable($content)) {
130 130
 			return $this->loadDocumentFile($content, $xml);
131 131
 		}
132 132
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 			? $this->load($file, $options)
144 144
 			: $this->loadHTMLFile($file, $options);
145 145
 
146
-		if($result === false){
146
+		if ($result === false) {
147 147
 			throw new DOMException('failed to load document from file: '.$file); // @codeCoverageIgnore
148 148
 		}
149 149
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 			? $this->loadXML($documentSource, $options)
161 161
 			: $this->loadHTML($documentSource, $options);
162 162
 
163
-		if($result === false){
163
+		if ($result === false) {
164 164
 			throw new DOMException('failed to load document from string'); // @codeCoverageIgnore
165 165
 		}
166 166
 
@@ -172,19 +172,19 @@  discard block
 block discarded – undo
172 172
 	 */
173 173
 	public function toNodeList($content):NodeList{
174 174
 
175
-		if($content instanceof NodeList){
175
+		if ($content instanceof NodeList) {
176 176
 			return $content;
177 177
 		}
178 178
 
179
-		if($content instanceof DOMNode || $content instanceof PrototypeNode){
179
+		if ($content instanceof DOMNode || $content instanceof PrototypeNode) {
180 180
 			return new NodeList([$content]);
181 181
 		}
182 182
 
183
-		if($content instanceof DOMNodeList || is_iterable($content)){
183
+		if ($content instanceof DOMNodeList || is_iterable($content)) {
184 184
 			return new NodeList($content);
185 185
 		}
186 186
 
187
-		if(is_string($content)){
187
+		if (is_string($content)) {
188 188
 			$document = new self;
189 189
 			$document->loadHTML('<html lang="en"><body id="-import-content">'.$content.'</body></html>');
190 190
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	/**
209 209
 	 *
210 210
 	 */
211
-	public function query(string $xpath, DOMNode $contextNode = null):?NodeList{
211
+	public function query(string $xpath, DOMNode $contextNode = null): ?NodeList{
212 212
 		$q = (new DOMXPath($this))->query($xpath, $contextNode);
213 213
 
214 214
 		return $q !== false ? new NodeList($q) : null;
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	/**
218 218
 	 *
219 219
 	 */
220
-	public function querySelectorAll(string $selector, DOMNode $contextNode = null, string $axis = null):?NodeList{
220
+	public function querySelectorAll(string $selector, DOMNode $contextNode = null, string $axis = null): ?NodeList{
221 221
 		return $this->query($this->cssSelectorConverter->toXPath($selector, $axis ?? 'descendant-or-self::'), $contextNode);
222 222
 	}
223 223
 
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
 	public function removeElementsBySelector(array $selectors, DOMNode $contextNode = null, string $axis = null):Document{
228 228
 		$nodes = $this->select($selectors, $contextNode, $axis ?? 'descendant-or-self::');
229 229
 
230
-		if(count($nodes) > 0){
230
+		if (count($nodes) > 0) {
231 231
 
232
-			foreach($nodes as $node){
232
+			foreach ($nodes as $node) {
233 233
 				$node->removeNode();
234 234
 			}
235 235
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 	 */
244 244
 	public function insertNodeList(NodeList $nodeList):Document{
245 245
 
246
-		foreach($nodeList as $node){
246
+		foreach ($nodeList as $node) {
247 247
 			$this->appendChild($this->importNode($node->cloneNode(true), true));
248 248
 		}
249 249
 
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 */
260 260
 	public function inspect(DOMNode $context = null, bool $xml = null):string{
261 261
 
262
-		if($xml === true){
262
+		if ($xml === true) {
263 263
 			return $this->saveXML($context);
264 264
 		}
265 265
 
@@ -274,15 +274,15 @@  discard block
 block discarded – undo
274 274
 		$nodeType = $nodeType ?? XML_ELEMENT_NODE;
275 275
 		$elements = new NodeList;
276 276
 
277
-		foreach($selectors ?? ['*'] as $selector){
277
+		foreach ($selectors ?? ['*'] as $selector) {
278 278
 
279
-			if(!is_string($selector)){
279
+			if (!is_string($selector)) {
280 280
 				continue;
281 281
 			}
282 282
 
283
-			foreach($this->querySelectorAll($selector, $contextNode, $axis ?? 'descendant-or-self::') as $element){
283
+			foreach ($this->querySelectorAll($selector, $contextNode, $axis ?? 'descendant-or-self::') as $element) {
284 284
 
285
-				if($element->nodeType === $nodeType){
285
+				if ($element->nodeType === $nodeType) {
286 286
 					$elements[] = $element;
287 287
 				}
288 288
 
@@ -302,15 +302,15 @@  discard block
 block discarded – undo
302 302
 		$maxLength = $maxLength ?? -1;
303 303
 		$nodes     = new NodeList;
304 304
 
305
-		if(in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])){
305
+		if (in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])) {
306 306
 
307
-			while($element = $element->{$property}){
307
+			while ($element = $element->{$property}) {
308 308
 
309
-				if($element->nodeType === $nodeType){
309
+				if ($element->nodeType === $nodeType) {
310 310
 					$nodes[] = $element;
311 311
 				}
312 312
 
313
-				if(count($nodes) === $maxLength){
313
+				if (count($nodes) === $maxLength) {
314 314
 					break;
315 315
 				}
316 316
 
@@ -324,15 +324,15 @@  discard block
 block discarded – undo
324 324
 	/**
325 325
 	 * @see https://secure.php.net/manual/dom.constants.php
326 326
 	 */
327
-	public function recursivelyFind(PrototypeNode $element, string $property = null, string $selector = null, int $index = null, int $nodeType = null):?DOMNode{
327
+	public function recursivelyFind(PrototypeNode $element, string $property = null, string $selector = null, int $index = null, int $nodeType = null): ?DOMNode{
328 328
 		$nodeType = $nodeType ?? XML_ELEMENT_NODE;
329 329
 		$index    = $index ?? 0;
330 330
 
331
-		if(in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])){
331
+		if (in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])) {
332 332
 
333
-			while($element = $element->{$property}){
333
+			while ($element = $element->{$property}) {
334 334
 
335
-				if($element->nodeType !== $nodeType || $selector !== null && !$element->match($selector) || --$index >= 0){
335
+				if ($element->nodeType !== $nodeType || $selector !== null && !$element->match($selector) || --$index >= 0) {
336 336
 					continue;
337 337
 				}
338 338
 
@@ -349,9 +349,9 @@  discard block
 block discarded – undo
349 349
 	 */
350 350
 	public function match(DOMNode $element, string $selector):bool{
351 351
 
352
-		foreach($this->select([$selector]) as $match){
352
+		foreach ($this->select([$selector]) as $match) {
353 353
 
354
-			if($element->isSameNode($match)){
354
+			if ($element->isSameNode($match)) {
355 355
 				return true;
356 356
 			}
357 357
 
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 		/** @var \chillerlan\PrototypeDOM\Node\PrototypeHTMLElement $element */
368 368
 		$element = $this->createElement($tag);
369 369
 
370
-		if($attributes !== null){
370
+		if ($attributes !== null) {
371 371
 			$element->setAttributes($attributes);
372 372
 		}
373 373
 
@@ -380,9 +380,9 @@  discard block
 block discarded – undo
380 380
 	 * @return \chillerlan\PrototypeDOM\Node\PrototypeHTMLElement|\DOMNode|null
381 381
 	 * @throws \DOMException
382 382
 	 */
383
-	public function getElementById($elementId):?DOMNode{
383
+	public function getElementById($elementId): ?DOMNode{
384 384
 
385
-		if(!is_string($elementId)){
385
+		if (!is_string($elementId)) {
386 386
 			throw new DOMException('invalid element id');
387 387
 		}
388 388
 
Please login to merge, or discard this patch.
src/Node/PrototypeNodeTrait.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
  * @property string                                $baseURI
40 40
  * @property string                                $textContent
41 41
  */
42
-trait PrototypeNodeTrait{
42
+trait PrototypeNodeTrait {
43 43
 
44 44
 	/**
45 45
 	 * @inheritDoc
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 */
68 68
 	public function removeNode():PrototypeNode{
69 69
 
70
-		if(!$this->parentNode){
70
+		if (!$this->parentNode) {
71 71
 			return $this;
72 72
 		}
73 73
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 */
80 80
 	public function replace(PrototypeNode $newnode):PrototypeNode{
81 81
 
82
-		if(!$this->parentNode){
82
+		if (!$this->parentNode) {
83 83
 			return $this;
84 84
 		}
85 85
 
@@ -92,10 +92,10 @@  discard block
 block discarded – undo
92 92
 	public function cleanWhitespace():PrototypeNode{
93 93
 		$node = $this->firstChild;
94 94
 
95
-		while($node){
95
+		while ($node) {
96 96
 			$nextNode = $node->nextSibling;
97 97
 
98
-			if($node->nodeType === XML_TEXT_NODE && $node->empty()){
98
+			if ($node->nodeType === XML_TEXT_NODE && $node->empty()) {
99 99
 				$node->removeNode();
100 100
 			}
101 101
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 */
111 111
 	public function purge():PrototypeNode{
112 112
 
113
-		while($this->hasChildNodes()){
113
+		while ($this->hasChildNodes()) {
114 114
 			$this->firstChild->removeNode();
115 115
 		}
116 116
 
Please login to merge, or discard this patch.