@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * |
17 | 17 | */ |
18 | -interface PrototypeHTMLElement extends PrototypeElement{ |
|
18 | +interface PrototypeHTMLElement extends PrototypeElement { |
|
19 | 19 | |
20 | 20 | public function getID():string; |
21 | 21 | public function setID(string $id):PrototypeHTMLElement; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * @link http://api.prototypejs.org/dom/Element/getStyle/ |
63 | 63 | */ |
64 | - public function getStyle(string $property):?string; |
|
64 | + public function getStyle(string $property): ?string; |
|
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @link http://api.prototypejs.org/dom/Element/setStyle/ |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\PrototypeDOM\NodeList; |
16 | 16 | use DOMNode; |
17 | 17 | |
18 | -interface PrototypeTraversal extends PrototypeNode{ |
|
18 | +interface PrototypeTraversal extends PrototypeNode { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @link http://api.prototypejs.org/dom/Element/select/ |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return \chillerlan\PrototypeDOM\Node\PrototypeTraversal|null |
32 | 32 | */ |
33 | - public function down($expression = null, int $index = null):?PrototypeTraversal; |
|
33 | + public function down($expression = null, int $index = null): ?PrototypeTraversal; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * @link http://api.prototypejs.org/dom/Element/up/ |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return \chillerlan\PrototypeDOM\Node\PrototypeTraversal|null |
42 | 42 | */ |
43 | - public function up($expression = null, int $index = null):?PrototypeTraversal; |
|
43 | + public function up($expression = null, int $index = null): ?PrototypeTraversal; |
|
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @link http://api.prototypejs.org/dom/Element/previous/ |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return \chillerlan\PrototypeDOM\Node\PrototypeTraversal|null |
52 | 52 | */ |
53 | - public function previous($expression = null, int $index = null):?PrototypeTraversal; |
|
53 | + public function previous($expression = null, int $index = null): ?PrototypeTraversal; |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @link http://api.prototypejs.org/dom/Element/next/ |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return \chillerlan\PrototypeDOM\Node\PrototypeTraversal|null |
62 | 62 | */ |
63 | - public function next($expression = null, int $index = null):?PrototypeTraversal; |
|
63 | + public function next($expression = null, int $index = null): ?PrototypeTraversal; |
|
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @link http://api.prototypejs.org/dom/Element/childElements/ |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | /** |
92 | 92 | * @link http://api.prototypejs.org/dom/Element/firstDescendant/ |
93 | 93 | */ |
94 | - public function firstDescendant():?PrototypeTraversal; |
|
94 | + public function firstDescendant(): ?PrototypeTraversal; |
|
95 | 95 | |
96 | 96 | /** |
97 | 97 | * @link http://api.prototypejs.org/dom/Element/previousSiblings/ |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @property \chillerlan\PrototypeDOM\Document $ownerDocument |
27 | 27 | */ |
28 | -trait PrototypeTraversalTrait{ |
|
28 | +trait PrototypeTraversalTrait { |
|
29 | 29 | use PrototypeNodeTrait; |
30 | 30 | |
31 | 31 | /** |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return \chillerlan\PrototypeDOM\Node\PrototypeTraversal|\DOMNode|null |
35 | 35 | */ |
36 | - public function recursivelyFind(string $selector = null, int $index = null, string $property = null, int $nodeType = XML_ELEMENT_NODE):?PrototypeTraversal{ |
|
36 | + public function recursivelyFind(string $selector = null, int $index = null, string $property = null, int $nodeType = XML_ELEMENT_NODE): ?PrototypeTraversal{ |
|
37 | 37 | |
38 | - if(is_numeric($selector)){ |
|
38 | + if (is_numeric($selector)) { |
|
39 | 39 | return $this->ownerDocument->recursivelyFind($this, $property, null, $selector, $nodeType); |
40 | 40 | } |
41 | 41 | |
@@ -52,19 +52,19 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * @inheritDoc |
54 | 54 | */ |
55 | - public function down($expression = null, int $index = null):?PrototypeTraversal{ |
|
55 | + public function down($expression = null, int $index = null): ?PrototypeTraversal{ |
|
56 | 56 | |
57 | - if($expression === null && $index === null){ |
|
57 | + if ($expression === null && $index === null) { |
|
58 | 58 | return $this->firstDescendant(); |
59 | 59 | } |
60 | 60 | |
61 | 61 | $index = $index ?? 0; |
62 | 62 | |
63 | - if(is_int($expression)){ |
|
63 | + if (is_int($expression)) { |
|
64 | 64 | return $this->select(['*'])->offsetGet($expression); |
65 | 65 | } |
66 | 66 | |
67 | - if(is_array($expression)){ |
|
67 | + if (is_array($expression)) { |
|
68 | 68 | return $this->select($expression)->offsetGet($index); |
69 | 69 | } |
70 | 70 | |
@@ -74,21 +74,21 @@ discard block |
||
74 | 74 | /** |
75 | 75 | * @inheritDoc |
76 | 76 | */ |
77 | - public function up($expression = null, int $index = null):?PrototypeTraversal{ |
|
77 | + public function up($expression = null, int $index = null): ?PrototypeTraversal{ |
|
78 | 78 | return $this->recursivelyFind($expression, $index, 'parentNode'); |
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @inheritDoc |
83 | 83 | */ |
84 | - public function previous($expression = null, int $index = null):?PrototypeTraversal{ |
|
84 | + public function previous($expression = null, int $index = null): ?PrototypeTraversal{ |
|
85 | 85 | return $this->recursivelyFind($expression, $index, 'previousSibling'); |
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | 89 | * @inheritDoc |
90 | 90 | */ |
91 | - public function next($expression = null, int $index = null):?PrototypeTraversal{ |
|
91 | + public function next($expression = null, int $index = null): ?PrototypeTraversal{ |
|
92 | 92 | return $this->recursivelyFind($expression, $index, 'nextSibling'); |
93 | 93 | } |
94 | 94 | |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | $nodeType = $nodeType ?? XML_ELEMENT_NODE; |
100 | 100 | $children = new NodeList; |
101 | 101 | |
102 | - if(!$this->hasChildNodes()){ |
|
102 | + if (!$this->hasChildNodes()) { |
|
103 | 103 | return $children; |
104 | 104 | } |
105 | 105 | |
106 | - foreach($this->childNodes as $child){ |
|
106 | + foreach ($this->childNodes as $child) { |
|
107 | 107 | |
108 | - if($child->nodeType === $nodeType){ |
|
108 | + if ($child->nodeType === $nodeType) { |
|
109 | 109 | $children[] = $child; |
110 | 110 | } |
111 | 111 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | /** |
146 | 146 | * @inheritDoc |
147 | 147 | */ |
148 | - public function firstDescendant():?PrototypeTraversal{ |
|
148 | + public function firstDescendant(): ?PrototypeTraversal{ |
|
149 | 149 | return $this->descendants()->first(); |
150 | 150 | } |
151 | 151 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | use function array_keys, array_unique, count, explode, implode, in_array, strtolower, trim; |
18 | 18 | |
19 | -class Element extends DOMElement implements PrototypeHTMLElement{ |
|
19 | +class Element extends DOMElement implements PrototypeHTMLElement { |
|
20 | 20 | use PrototypeHTMLElementTrait; |
21 | 21 | |
22 | 22 | /** |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function getAttributes():array{ |
26 | 26 | $attributes = []; |
27 | 27 | |
28 | - foreach($this->attributes as $attribute){ |
|
28 | + foreach ($this->attributes as $attribute) { |
|
29 | 29 | $attributes[$attribute->nodeName] = $attribute->nodeValue; |
30 | 30 | } |
31 | 31 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function setAttributes(array $attributes):PrototypeHTMLElement{ |
41 | 41 | |
42 | - foreach($attributes as $name => $value){ |
|
42 | + foreach ($attributes as $name => $value) { |
|
43 | 43 | $this->setAttribute($name, $value); |
44 | 44 | } |
45 | 45 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function removeAttributes(array $attributes):PrototypeHTMLElement{ |
55 | 55 | |
56 | - foreach($attributes as $name){ |
|
56 | + foreach ($attributes as $name) { |
|
57 | 57 | $this->removeAttribute($name); |
58 | 58 | } |
59 | 59 | |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | public function addClassNames(array $classnames):PrototypeHTMLElement{ |
69 | 69 | $currentClassnames = $this->classNames(); |
70 | 70 | |
71 | - foreach($classnames as $classname){ |
|
71 | + foreach ($classnames as $classname) { |
|
72 | 72 | |
73 | - if(!in_array($classname, $currentClassnames, true)){ |
|
73 | + if (!in_array($classname, $currentClassnames, true)) { |
|
74 | 74 | $currentClassnames[] = $classname; |
75 | 75 | } |
76 | 76 | |
@@ -87,10 +87,10 @@ discard block |
||
87 | 87 | public function removeClassNames(array $classnames):PrototypeHTMLElement{ |
88 | 88 | $currentClassnames = $this->classNames(); |
89 | 89 | |
90 | - foreach($classnames as $classname){ |
|
90 | + foreach ($classnames as $classname) { |
|
91 | 91 | $keys = array_keys($currentClassnames, $classname); |
92 | 92 | |
93 | - foreach($keys as $key){ |
|
93 | + foreach ($keys as $key) { |
|
94 | 94 | unset($currentClassnames[$key]); |
95 | 95 | } |
96 | 96 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function getStyles():array{ |
106 | 106 | |
107 | - if(!$this->hasAttributes()){ |
|
107 | + if (!$this->hasAttributes()) { |
|
108 | 108 | return []; |
109 | 109 | } |
110 | 110 | |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | |
113 | 113 | $currentStyle = []; |
114 | 114 | |
115 | - foreach($styles as $style){ |
|
115 | + foreach ($styles as $style) { |
|
116 | 116 | $s = explode(':', $style); |
117 | 117 | |
118 | - if(count($s) === 2){ |
|
118 | + if (count($s) === 2) { |
|
119 | 119 | $currentStyle[strtolower(trim($s[0]))] = trim($s[1]); |
120 | 120 | } |
121 | 121 |
@@ -39,7 +39,7 @@ discard block |
||
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 |
||
67 | 67 | */ |
68 | 68 | public function remove():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 |
||
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 |
||
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->remove(); |
100 | 100 | } |
101 | 101 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function purge():PrototypeNode{ |
112 | 112 | |
113 | - while($this->hasChildNodes()){ |
|
113 | + while ($this->hasChildNodes()) { |
|
114 | 114 | $this->firstChild->remove(); |
115 | 115 | } |
116 | 116 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | use function array_key_exists, call_user_func_array, is_array; |
19 | 19 | |
20 | -trait PrototypeElementTrait{ |
|
20 | +trait PrototypeElementTrait { |
|
21 | 21 | use PrototypeTraversalTrait; |
22 | 22 | |
23 | 23 | /** |
@@ -39,28 +39,28 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function insert($content):PrototypeElement{ |
41 | 41 | |
42 | - if(!is_array($content)){ |
|
42 | + if (!is_array($content)) { |
|
43 | 43 | |
44 | - foreach($this->ownerDocument->toNodeList($content) as $node){ |
|
44 | + foreach ($this->ownerDocument->toNodeList($content) as $node) { |
|
45 | 45 | $this->insert_bottom($node); |
46 | 46 | } |
47 | 47 | |
48 | 48 | return $this; |
49 | 49 | } |
50 | 50 | |
51 | - foreach(['before', 'after', 'top', 'bottom'] as $pos){ |
|
51 | + foreach (['before', 'after', 'top', 'bottom'] as $pos) { |
|
52 | 52 | |
53 | - if(!array_key_exists($pos, $content)){ |
|
53 | + if (!array_key_exists($pos, $content)) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $nodes = $this->ownerDocument->toNodeList($content[$pos]); |
58 | 58 | |
59 | - if($pos === 'top' && $this->hasChildNodes() || $pos === 'after' && $this->nextSibling){ |
|
59 | + if ($pos === 'top' && $this->hasChildNodes() || $pos === 'after' && $this->nextSibling) { |
|
60 | 60 | $nodes->reverse(); |
61 | 61 | } |
62 | 62 | |
63 | - foreach($nodes as $node){ |
|
63 | + foreach ($nodes as $node) { |
|
64 | 64 | call_user_func_array([$this, 'insert_'.$pos], [$node]); |
65 | 65 | } |
66 | 66 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function insert_before(PrototypeElement $node, PrototypeElement $refNode = null):PrototypeElement{ |
76 | 76 | |
77 | - if($this->parentNode){ |
|
77 | + if ($this->parentNode) { |
|
78 | 78 | $this->parentNode->insertBefore($this->importNode($node), $refNode ?? $this); |
79 | 79 | } |
80 | 80 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function insert_after(PrototypeElement $node):PrototypeElement{ |
88 | 88 | |
89 | - if(!$this->nextSibling && $this->parentNode){ |
|
89 | + if (!$this->nextSibling && $this->parentNode) { |
|
90 | 90 | return $this->parentNode->insert_bottom($node); // @codeCoverageIgnore |
91 | 91 | } |
92 | 92 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function insert_top(PrototypeElement $node):PrototypeElement{ |
100 | 100 | |
101 | - if($this->hasChildNodes()){ |
|
101 | + if ($this->hasChildNodes()) { |
|
102 | 102 | return $this->firstChild->insert_before($node, $this->firstChild); |
103 | 103 | } |
104 | 104 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * |
21 | 21 | */ |
22 | -trait PrototypeHTMLElementTrait{ |
|
22 | +trait PrototypeHTMLElementTrait { |
|
23 | 23 | use PrototypeElementTrait; |
24 | 24 | |
25 | 25 | public function getID():string{ |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public function identify(string $newID = null):string{ |
69 | 69 | $oldID = $this->getAttribute('id'); |
70 | 70 | |
71 | - if($newID !== null){ |
|
71 | + if ($newID !== null) { |
|
72 | 72 | $this->setAttribute('id', $newID); |
73 | 73 | } |
74 | 74 | |
@@ -80,17 +80,17 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function classNames():array{ |
82 | 82 | |
83 | - if(!$this->hasAttributes()){ |
|
83 | + if (!$this->hasAttributes()) { |
|
84 | 84 | return []; |
85 | 85 | } |
86 | 86 | |
87 | 87 | $classnames = explode(' ', $this->getClassName()); |
88 | 88 | $currentClassnames = []; |
89 | 89 | |
90 | - foreach($classnames as $classname){ |
|
90 | + foreach ($classnames as $classname) { |
|
91 | 91 | $classname = trim($classname); |
92 | 92 | |
93 | - if(!empty($classname)){ |
|
93 | + if (!empty($classname)) { |
|
94 | 94 | $currentClassnames[] = $classname; |
95 | 95 | } |
96 | 96 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function toggleClassName(string $classname):PrototypeHTMLElement{ |
127 | 127 | |
128 | - if($this->hasClassName($classname)){ |
|
128 | + if ($this->hasClassName($classname)) { |
|
129 | 129 | return $this->removeClassName($classname); |
130 | 130 | } |
131 | 131 | |
@@ -135,10 +135,10 @@ discard block |
||
135 | 135 | /** |
136 | 136 | * @inheritDoc |
137 | 137 | */ |
138 | - public function getStyle(string $property):?string{ |
|
138 | + public function getStyle(string $property): ?string{ |
|
139 | 139 | $currentStyle = $this->getStyles(); |
140 | 140 | |
141 | - if(array_key_exists(strtolower($property), $currentStyle)){ |
|
141 | + if (array_key_exists(strtolower($property), $currentStyle)) { |
|
142 | 142 | return $currentStyle[$property]; |
143 | 143 | } |
144 | 144 | |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | public function setStyle(array $style, bool $replace = null):PrototypeHTMLElement{ |
152 | 152 | $currentStyle = $this->getStyles(); |
153 | 153 | |
154 | - if($replace !== true){ |
|
154 | + if ($replace !== true) { |
|
155 | 155 | $style = array_merge($currentStyle, $style); |
156 | 156 | } |
157 | 157 | |
158 | - foreach($style as $property => $value){ |
|
158 | + foreach ($style as $property => $value) { |
|
159 | 159 | $style[$property] = $property.': '.$value.';'; |
160 | 160 | } |
161 | 161 |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\PrototypeDOM; |
14 | 14 | |
15 | -interface PrototypeEnumerable{ |
|
15 | +interface PrototypeEnumerable { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @link http://api.prototypejs.org/language/Enumerable/prototype/toArray/ |
@@ -26,7 +26,7 @@ discard block |
||
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 |
||
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 |
||
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'])->offsetGet(0)->nodeValue ?? null; |
77 | 77 | } |
78 | 78 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | public function setTitle(string $title):void{ |
83 | 83 | $currentTitle = $this->select(['head > title'])->offsetGet(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 |
||
91 | 91 | $head = $this->select(['head'])->offsetGet(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 | |
@@ -111,19 +111,19 @@ discard block |
||
111 | 111 | |
112 | 112 | public function loadDocument($content, bool $xml = null):Document{ |
113 | 113 | |
114 | - if($content instanceof NodeList){ |
|
114 | + if ($content instanceof NodeList) { |
|
115 | 115 | return $this->insertNodeList($content); |
116 | 116 | } |
117 | 117 | |
118 | - if($content instanceof DOMNodeList){ |
|
118 | + if ($content instanceof DOMNodeList) { |
|
119 | 119 | return $this->insertNodeList(new NodeList($content)); |
120 | 120 | } |
121 | 121 | |
122 | - if(!is_string($content)){ |
|
122 | + if (!is_string($content)) { |
|
123 | 123 | throw new DOMException('invalid document content'); |
124 | 124 | } |
125 | 125 | |
126 | - if(is_file($content) && is_readable($content)){ |
|
126 | + if (is_file($content) && is_readable($content)) { |
|
127 | 127 | return $this->loadDocumentFile($content, $xml); |
128 | 128 | } |
129 | 129 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | ? $this->load($file, $options) |
141 | 141 | : $this->loadHTMLFile($file, $options); |
142 | 142 | |
143 | - if($result === false){ |
|
143 | + if ($result === false) { |
|
144 | 144 | throw new DOMException('failed to load document from file: '.$file); // @codeCoverageIgnore |
145 | 145 | } |
146 | 146 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | ? $this->loadXML($documentSource, $options) |
158 | 158 | : $this->loadHTML($documentSource, $options); |
159 | 159 | |
160 | - if($result === false){ |
|
160 | + if ($result === false) { |
|
161 | 161 | throw new DOMException('failed to load document from string'); // @codeCoverageIgnore |
162 | 162 | } |
163 | 163 | |
@@ -169,19 +169,19 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function toNodeList($content):NodeList{ |
171 | 171 | |
172 | - if($content instanceof NodeList){ |
|
172 | + if ($content instanceof NodeList) { |
|
173 | 173 | return $content; |
174 | 174 | } |
175 | 175 | |
176 | - if($content instanceof DOMNode || $content instanceof PrototypeNode){ |
|
176 | + if ($content instanceof DOMNode || $content instanceof PrototypeNode) { |
|
177 | 177 | return new NodeList([$content]); |
178 | 178 | } |
179 | 179 | |
180 | - if($content instanceof DOMNodeList || is_iterable($content)){ |
|
180 | + if ($content instanceof DOMNodeList || is_iterable($content)) { |
|
181 | 181 | return new NodeList($content); |
182 | 182 | } |
183 | 183 | |
184 | - if(is_string($content)){ |
|
184 | + if (is_string($content)) { |
|
185 | 185 | $document = new self; |
186 | 186 | $document->loadHTML('<html lang="en"><body id="-import-content">'.$content.'</body></html>'); |
187 | 187 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | /** |
206 | 206 | * |
207 | 207 | */ |
208 | - public function query(string $xpath, DOMNode $contextNode = null):?NodeList{ |
|
208 | + public function query(string $xpath, DOMNode $contextNode = null): ?NodeList{ |
|
209 | 209 | $q = (new DOMXPath($this))->query($xpath, $contextNode); |
210 | 210 | |
211 | 211 | return $q !== false ? new NodeList($q) : null; |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | /** |
215 | 215 | * |
216 | 216 | */ |
217 | - public function querySelectorAll(string $selector, DOMNode $contextNode = null, string $axis = null):?NodeList{ |
|
217 | + public function querySelectorAll(string $selector, DOMNode $contextNode = null, string $axis = null): ?NodeList{ |
|
218 | 218 | return $this->query($this->cssSelectorConverter->toXPath($selector, $axis ?? 'descendant-or-self::'), $contextNode); |
219 | 219 | } |
220 | 220 | |
@@ -224,9 +224,9 @@ discard block |
||
224 | 224 | public function removeElementsBySelector(array $selectors, DOMNode $contextNode = null, string $axis = null):Document{ |
225 | 225 | $nodes = $this->select($selectors, $contextNode, $axis ?? 'descendant-or-self::'); |
226 | 226 | |
227 | - if(count($nodes) > 0){ |
|
227 | + if (count($nodes) > 0) { |
|
228 | 228 | |
229 | - foreach($nodes as $node){ |
|
229 | + foreach ($nodes as $node) { |
|
230 | 230 | $node->remove(); |
231 | 231 | } |
232 | 232 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function insertNodeList(NodeList $nodeList):Document{ |
242 | 242 | |
243 | - foreach($nodeList as $node){ |
|
243 | + foreach ($nodeList as $node) { |
|
244 | 244 | $this->appendChild($this->importNode($node->cloneNode(true), true)); |
245 | 245 | } |
246 | 246 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public function inspect(DOMNode $context = null, bool $xml = null):string{ |
258 | 258 | |
259 | - if($xml === true){ |
|
259 | + if ($xml === true) { |
|
260 | 260 | return $this->saveXML($context); |
261 | 261 | } |
262 | 262 | |
@@ -271,15 +271,15 @@ discard block |
||
271 | 271 | $nodeType = $nodeType ?? XML_ELEMENT_NODE; |
272 | 272 | $elements = new NodeList; |
273 | 273 | |
274 | - foreach($selectors ?? ['*'] as $selector){ |
|
274 | + foreach ($selectors ?? ['*'] as $selector) { |
|
275 | 275 | |
276 | - if(!is_string($selector)){ |
|
276 | + if (!is_string($selector)) { |
|
277 | 277 | continue; |
278 | 278 | } |
279 | 279 | |
280 | - foreach($this->querySelectorAll($selector, $contextNode, $axis ?? 'descendant-or-self::') as $element){ |
|
280 | + foreach ($this->querySelectorAll($selector, $contextNode, $axis ?? 'descendant-or-self::') as $element) { |
|
281 | 281 | |
282 | - if($element->nodeType === $nodeType){ |
|
282 | + if ($element->nodeType === $nodeType) { |
|
283 | 283 | $elements[] = $element; |
284 | 284 | } |
285 | 285 | |
@@ -299,15 +299,15 @@ discard block |
||
299 | 299 | $maxLength = $maxLength ?? -1; |
300 | 300 | $nodes = new NodeList; |
301 | 301 | |
302 | - if(in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])){ |
|
302 | + if (in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])) { |
|
303 | 303 | |
304 | - while($element = $element->{$property}){ |
|
304 | + while ($element = $element->{$property}) { |
|
305 | 305 | |
306 | - if($element->nodeType === $nodeType){ |
|
306 | + if ($element->nodeType === $nodeType) { |
|
307 | 307 | $nodes[] = $element; |
308 | 308 | } |
309 | 309 | |
310 | - if(count($nodes) === $maxLength){ |
|
310 | + if (count($nodes) === $maxLength) { |
|
311 | 311 | break; |
312 | 312 | } |
313 | 313 | |
@@ -321,15 +321,15 @@ discard block |
||
321 | 321 | /** |
322 | 322 | * @see https://secure.php.net/manual/dom.constants.php |
323 | 323 | */ |
324 | - public function recursivelyFind(PrototypeNode $element, string $property = null, string $selector = null, int $index = null, int $nodeType = null):?DOMNode{ |
|
324 | + public function recursivelyFind(PrototypeNode $element, string $property = null, string $selector = null, int $index = null, int $nodeType = null): ?DOMNode{ |
|
325 | 325 | $nodeType = $nodeType ?? XML_ELEMENT_NODE; |
326 | 326 | $index = $index ?? 0; |
327 | 327 | |
328 | - if(in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])){ |
|
328 | + if (in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])) { |
|
329 | 329 | |
330 | - while($element = $element->{$property}){ |
|
330 | + while ($element = $element->{$property}) { |
|
331 | 331 | |
332 | - if($element->nodeType !== $nodeType || $selector !== null && !$element->match($selector) || --$index >= 0){ |
|
332 | + if ($element->nodeType !== $nodeType || $selector !== null && !$element->match($selector) || --$index >= 0) { |
|
333 | 333 | continue; |
334 | 334 | } |
335 | 335 | |
@@ -346,9 +346,9 @@ discard block |
||
346 | 346 | */ |
347 | 347 | public function match(DOMNode $element, string $selector):bool{ |
348 | 348 | |
349 | - foreach($this->select([$selector]) as $match){ |
|
349 | + foreach ($this->select([$selector]) as $match) { |
|
350 | 350 | |
351 | - if($element->isSameNode($match)){ |
|
351 | + if ($element->isSameNode($match)) { |
|
352 | 352 | return true; |
353 | 353 | } |
354 | 354 | |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | /** @var \chillerlan\PrototypeDOM\Node\PrototypeHTMLElement $element */ |
365 | 365 | $element = $this->createElement($tag); |
366 | 366 | |
367 | - if($attributes !== null){ |
|
367 | + if ($attributes !== null) { |
|
368 | 368 | $element->setAttributes($attributes); |
369 | 369 | } |
370 | 370 | |
@@ -377,9 +377,9 @@ discard block |
||
377 | 377 | * @return \chillerlan\PrototypeDOM\Node\PrototypeHTMLElement|\DOMNode|null |
378 | 378 | * @throws \DOMException |
379 | 379 | */ |
380 | - public function getElementById($elementId):?DOMNode{ |
|
380 | + public function getElementById($elementId): ?DOMNode{ |
|
381 | 381 | |
382 | - if(!is_string($elementId)){ |
|
382 | + if (!is_string($elementId)) { |
|
383 | 383 | throw new DOMException('invalid element id'); |
384 | 384 | } |
385 | 385 |