@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @param string|array|\DOMNode|\DOMNodeList $content |
51 | 51 | * |
52 | - * @return \chillerlan\PrototypeDOM\Node\PrototypeElement |
|
52 | + * @return ElementTrait |
|
53 | 53 | */ |
54 | 54 | public function insert($content):PrototypeElement{ |
55 | 55 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param \chillerlan\PrototypeDOM\Node\PrototypeElement $node |
88 | 88 | * @param \chillerlan\PrototypeDOM\Node\PrototypeElement|null $refNode |
89 | 89 | * |
90 | - * @return \chillerlan\PrototypeDOM\Node\PrototypeElement |
|
90 | + * @return ElementTrait |
|
91 | 91 | */ |
92 | 92 | public function insert_before(PrototypeElement $node, PrototypeElement $refNode = null):PrototypeElement{ |
93 | 93 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | /** |
130 | 130 | * @param \chillerlan\PrototypeDOM\Node\PrototypeElement $node |
131 | 131 | * |
132 | - * @return \chillerlan\PrototypeDOM\Node\PrototypeElement |
|
132 | + * @return ElementTrait |
|
133 | 133 | */ |
134 | 134 | public function insert_bottom(PrototypeElement $node):PrototypeElement{ |
135 | 135 | $this->appendChild($this->importNode($node)); |
@@ -12,8 +12,6 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\PrototypeDOM\Node; |
14 | 14 | |
15 | -use chillerlan\PrototypeDOM\NodeList; |
|
16 | - |
|
17 | 15 | trait ElementTrait{ |
18 | 16 | |
19 | 17 | /** |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | use chillerlan\PrototypeDOM\NodeList; |
16 | 16 | |
17 | -trait ElementTrait{ |
|
17 | +trait ElementTrait { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @link http://api.prototypejs.org/dom/Element/wrap/ |
@@ -53,28 +53,28 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function insert($content):PrototypeElement{ |
55 | 55 | |
56 | - if(!\is_array($content)){ |
|
56 | + if (!\is_array($content)) { |
|
57 | 57 | |
58 | - foreach($this->ownerDocument->toNodeList($content) as $node){ |
|
58 | + foreach ($this->ownerDocument->toNodeList($content) as $node) { |
|
59 | 59 | $this->insert_bottom($node); |
60 | 60 | } |
61 | 61 | |
62 | 62 | return $this; |
63 | 63 | } |
64 | 64 | |
65 | - foreach(['before', 'after', 'top', 'bottom'] as $pos){ |
|
65 | + foreach (['before', 'after', 'top', 'bottom'] as $pos) { |
|
66 | 66 | |
67 | - if(!\array_key_exists($pos, $content)){ |
|
67 | + if (!\array_key_exists($pos, $content)) { |
|
68 | 68 | continue; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $nodes = $this->ownerDocument->toNodeList($content[$pos]); |
72 | 72 | |
73 | - if($pos === 'top' && $this->hasChildNodes() || $pos === 'after' && $this->nextSibling){ |
|
73 | + if ($pos === 'top' && $this->hasChildNodes() || $pos === 'after' && $this->nextSibling) { |
|
74 | 74 | $nodes->reverse(); |
75 | 75 | } |
76 | 76 | |
77 | - foreach($nodes as $node){ |
|
77 | + foreach ($nodes as $node) { |
|
78 | 78 | \call_user_func_array([$this, 'insert_'.$pos], [$node]); |
79 | 79 | } |
80 | 80 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function insert_before(PrototypeElement $node, PrototypeElement $refNode = null):PrototypeElement{ |
93 | 93 | |
94 | - if($this->parentNode){ |
|
94 | + if ($this->parentNode) { |
|
95 | 95 | $this->parentNode->insertBefore($this->importNode($node), $refNode ?? $this); |
96 | 96 | } |
97 | 97 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function insert_after(PrototypeElement $node):PrototypeElement{ |
107 | 107 | |
108 | - if(!$this->nextSibling && $this->parentNode){ |
|
108 | + if (!$this->nextSibling && $this->parentNode) { |
|
109 | 109 | return $this->parentNode->insert_bottom($node); // @codeCoverageIgnore |
110 | 110 | } |
111 | 111 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function insert_top(PrototypeElement $node):PrototypeElement{ |
121 | 121 | |
122 | - if($this->hasChildNodes()){ |
|
122 | + if ($this->hasChildNodes()) { |
|
123 | 123 | return $this->firstChild->insert_before($node, $this->firstChild); |
124 | 124 | } |
125 | 125 |
@@ -174,7 +174,7 @@ |
||
174 | 174 | * @param array $style |
175 | 175 | * @param bool $replace |
176 | 176 | * |
177 | - * @return \chillerlan\PrototypeDOM\Node\PrototypeHTMLElement |
|
177 | + * @return HTMLElementTrait |
|
178 | 178 | */ |
179 | 179 | public function setStyle(array $style, bool $replace = null):PrototypeHTMLElement{ |
180 | 180 | $currentStyle = $this->getStyles(); |
@@ -12,8 +12,6 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\PrototypeDOM\Node; |
14 | 14 | |
15 | -use chillerlan\Traits\Magic; |
|
16 | - |
|
17 | 15 | /** |
18 | 16 | * @property string $id |
19 | 17 | * @property string $class |
@@ -21,13 +21,13 @@ discard block |
||
21 | 21 | * @property string $src |
22 | 22 | * @property string $innerHTML |
23 | 23 | */ |
24 | -trait HTMLElementTrait{ |
|
24 | +trait HTMLElementTrait { |
|
25 | 25 | |
26 | 26 | protected function magic_get_id():string{ |
27 | 27 | return \trim($this->getAttribute('id')); |
28 | 28 | } |
29 | 29 | |
30 | - protected function magic_set_id($id){ |
|
30 | + protected function magic_set_id($id) { |
|
31 | 31 | return $this->setAttribute('id', $id); |
32 | 32 | } |
33 | 33 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | return \trim($this->getAttribute('class')); |
36 | 36 | } |
37 | 37 | |
38 | - protected function magic_set_class($class){ |
|
38 | + protected function magic_set_class($class) { |
|
39 | 39 | return $this->setAttribute('class', $class); |
40 | 40 | } |
41 | 41 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | return \trim($this->getAttribute('href')); |
44 | 44 | } |
45 | 45 | |
46 | - protected function magic_set_href($class){ |
|
46 | + protected function magic_set_href($class) { |
|
47 | 47 | return $this->setAttribute('href', $class); |
48 | 48 | } |
49 | 49 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | return \trim($this->getAttribute('src')); |
52 | 52 | } |
53 | 53 | |
54 | - protected function magic_set_src($class){ |
|
54 | + protected function magic_set_src($class) { |
|
55 | 55 | return $this->setAttribute('src', $class); |
56 | 56 | } |
57 | 57 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function identify(string $newID = null):string{ |
70 | 70 | $oldID = $this->id; |
71 | 71 | |
72 | - if($newID !== null){ |
|
72 | + if ($newID !== null) { |
|
73 | 73 | $this->id = $newID; |
74 | 74 | } |
75 | 75 | |
@@ -83,16 +83,16 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function classNames():array{ |
85 | 85 | |
86 | - if(!$this->hasAttributes()){ |
|
86 | + if (!$this->hasAttributes()) { |
|
87 | 87 | return []; |
88 | 88 | } |
89 | 89 | |
90 | 90 | $classnames = \explode(' ', $this->class); |
91 | 91 | $currentClassnames = []; |
92 | 92 | |
93 | - foreach($classnames as $classname){ |
|
93 | + foreach ($classnames as $classname) { |
|
94 | 94 | |
95 | - if(empty($classname)){ |
|
95 | + if (empty($classname)) { |
|
96 | 96 | continue; |
97 | 97 | } |
98 | 98 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function toggleClassName(string $classname):PrototypeHTMLElement{ |
146 | 146 | |
147 | - if($this->hasClassName($classname)){ |
|
147 | + if ($this->hasClassName($classname)) { |
|
148 | 148 | return $this->removeClassName($classname); |
149 | 149 | } |
150 | 150 | |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @return null|string |
160 | 160 | */ |
161 | - public function getStyle(string $property):?string{ |
|
161 | + public function getStyle(string $property): ?string{ |
|
162 | 162 | $currentStyle = $this->getStyles(); |
163 | 163 | |
164 | - if(\array_key_exists(\strtolower($property), $currentStyle)){ |
|
164 | + if (\array_key_exists(\strtolower($property), $currentStyle)) { |
|
165 | 165 | return $currentStyle[$property]; |
166 | 166 | } |
167 | 167 | |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | public function setStyle(array $style, bool $replace = null):PrototypeHTMLElement{ |
180 | 180 | $currentStyle = $this->getStyles(); |
181 | 181 | |
182 | - if($replace !== true){ |
|
182 | + if ($replace !== true) { |
|
183 | 183 | $style = \array_merge($currentStyle, $style); |
184 | 184 | } |
185 | 185 | |
186 | - foreach($style as $property => $value){ |
|
186 | + foreach ($style as $property => $value) { |
|
187 | 187 | $style[$property] = $property.': '.$value.';'; |
188 | 188 | } |
189 | 189 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | trait TraversalTrait{ |
22 | 22 | |
23 | 23 | /** |
24 | - * @param $selector |
|
24 | + * @param string|null $selector |
|
25 | 25 | * @param $index |
26 | 26 | * @param string $property |
27 | 27 | * @param int $nodeType https://secure.php.net/manual/dom.constants.php |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param null $expression |
66 | 66 | * @param int $index |
67 | 67 | * |
68 | - * @return \chillerlan\PrototypeDOM\Node\PrototypeNode|null |
|
68 | + * @return Element|null |
|
69 | 69 | */ |
70 | 70 | public function down($expression = null, int $index = null):?PrototypeNode{ |
71 | 71 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | /** |
189 | 189 | * @link http://api.prototypejs.org/dom/Element/firstDescendant/ |
190 | 190 | * |
191 | - * @return \chillerlan\PrototypeDOM\Node\PrototypeNode|null |
|
191 | + * @return Element|null |
|
192 | 192 | */ |
193 | 193 | public function firstDescendant():?PrototypeNode{ |
194 | 194 | return $this->descendants()->first(); |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @property \chillerlan\PrototypeDOM\Document $ownerDocument |
20 | 20 | */ |
21 | -trait TraversalTrait{ |
|
21 | +trait TraversalTrait { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @param $selector |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return \chillerlan\PrototypeDOM\Node\PrototypeNode|null |
30 | 30 | */ |
31 | - public function recursivelyFind($selector, int $index = null, string $property = null, int $nodeType = \XML_ELEMENT_NODE):?PrototypeNode{ |
|
31 | + public function recursivelyFind($selector, int $index = null, string $property = null, int $nodeType = \XML_ELEMENT_NODE): ?PrototypeNode{ |
|
32 | 32 | |
33 | - if(\is_numeric($selector)){ |
|
33 | + if (\is_numeric($selector)) { |
|
34 | 34 | return $this->ownerDocument->recursivelyFind($this, $property, null, $selector, $nodeType); |
35 | 35 | } |
36 | 36 | |
@@ -67,19 +67,19 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return \chillerlan\PrototypeDOM\Node\PrototypeNode|null |
69 | 69 | */ |
70 | - public function down($expression = null, int $index = null):?PrototypeNode{ |
|
70 | + public function down($expression = null, int $index = null): ?PrototypeNode{ |
|
71 | 71 | |
72 | - if($expression === null && $index === null){ |
|
72 | + if ($expression === null && $index === null) { |
|
73 | 73 | return $this->firstDescendant(); |
74 | 74 | } |
75 | 75 | |
76 | 76 | $index = $index ?? 0; |
77 | 77 | |
78 | - if(\is_int($expression)){ |
|
78 | + if (\is_int($expression)) { |
|
79 | 79 | return $this->select(['*'])->item($expression); |
80 | 80 | } |
81 | 81 | |
82 | - if(\is_array($expression)){ |
|
82 | + if (\is_array($expression)) { |
|
83 | 83 | return $this->select($expression)->item($index); |
84 | 84 | } |
85 | 85 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return \chillerlan\PrototypeDOM\Node\PrototypeNode|null |
96 | 96 | */ |
97 | - public function up($expression = null, int $index = null):?PrototypeNode{ |
|
97 | + public function up($expression = null, int $index = null): ?PrototypeNode{ |
|
98 | 98 | return $this->recursivelyFind($expression, $index, 'parentNode'); |
99 | 99 | } |
100 | 100 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @return \chillerlan\PrototypeDOM\Node\PrototypeNode|null |
108 | 108 | */ |
109 | - public function previous($expression = null, int $index = null):?PrototypeNode{ |
|
109 | + public function previous($expression = null, int $index = null): ?PrototypeNode{ |
|
110 | 110 | return $this->recursivelyFind($expression, $index, 'previousSibling'); |
111 | 111 | } |
112 | 112 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @return \chillerlan\PrototypeDOM\Node\PrototypeNode|null |
120 | 120 | */ |
121 | - public function next($expression = null, int $index = null):?PrototypeNode{ |
|
121 | + public function next($expression = null, int $index = null): ?PrototypeNode{ |
|
122 | 122 | return $this->recursivelyFind($expression, $index, 'nextSibling'); |
123 | 123 | } |
124 | 124 | |
@@ -132,13 +132,13 @@ discard block |
||
132 | 132 | public function childElements(int $nodeType = \XML_ELEMENT_NODE):NodeList{ |
133 | 133 | $children = new NodeList; |
134 | 134 | |
135 | - if(!$this->hasChildNodes()){ |
|
135 | + if (!$this->hasChildNodes()) { |
|
136 | 136 | return $children; |
137 | 137 | } |
138 | 138 | |
139 | - foreach($this->childNodes as $child){ |
|
139 | + foreach ($this->childNodes as $child) { |
|
140 | 140 | |
141 | - if($child->nodeType === $nodeType){ |
|
141 | + if ($child->nodeType === $nodeType) { |
|
142 | 142 | $children[] = $child; |
143 | 143 | } |
144 | 144 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * |
191 | 191 | * @return \chillerlan\PrototypeDOM\Node\PrototypeNode|null |
192 | 192 | */ |
193 | - public function firstDescendant():?PrototypeNode{ |
|
193 | + public function firstDescendant(): ?PrototypeNode{ |
|
194 | 194 | return $this->descendants()->first(); |
195 | 195 | } |
196 | 196 |
@@ -15,7 +15,11 @@ |
||
15 | 15 | use chillerlan\PrototypeDOM\Node\{Element, PrototypeNode}; |
16 | 16 | use chillerlan\Traits\{Enumerable, Interfaces\ArrayAccessTrait, Magic}; |
17 | 17 | use chillerlan\Traits\SPL\{CountableTrait, SeekableIteratorTrait}; |
18 | -use ArrayAccess, Countable, DOMNode, DOMNodeList, SeekableIterator; |
|
18 | +use ArrayAccess; |
|
19 | +use Countable; |
|
20 | +use DOMNode; |
|
21 | +use DOMNodeList; |
|
22 | +use SeekableIterator; |
|
19 | 23 | |
20 | 24 | /** |
21 | 25 | * @property int $length |
@@ -47,17 +47,17 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @throws \Exception |
49 | 49 | */ |
50 | - public function __construct(iterable $nodes = null){ |
|
50 | + public function __construct(iterable $nodes = null) { |
|
51 | 51 | |
52 | - if($nodes instanceof DOMNodeList){ |
|
52 | + if ($nodes instanceof DOMNodeList) { |
|
53 | 53 | $this->array = \iterator_to_array($nodes); |
54 | 54 | } |
55 | - elseif($nodes instanceof NodeList){ |
|
55 | + elseif ($nodes instanceof NodeList) { |
|
56 | 56 | $this->array = $nodes->toArray(); |
57 | 57 | } |
58 | - elseif(\is_iterable($nodes)){ |
|
59 | - foreach($nodes as $node){ |
|
60 | - if($node instanceof DOMNode || $node instanceof PrototypeNode){ |
|
58 | + elseif (\is_iterable($nodes)) { |
|
59 | + foreach ($nodes as $node) { |
|
60 | + if ($node instanceof DOMNode || $node instanceof PrototypeNode) { |
|
61 | 61 | $this->array[] = $node; |
62 | 62 | } |
63 | 63 | } |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function match(DOMNode $node):bool{ |
90 | 90 | |
91 | - foreach($this->array as $element){ |
|
91 | + foreach ($this->array as $element) { |
|
92 | 92 | |
93 | - if($element->isSameNode($node)){ |
|
93 | + if ($element->isSameNode($node)) { |
|
94 | 94 | return true; |
95 | 95 | } |
96 | 96 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return \chillerlan\PrototypeDOM\Node\Element|null |
106 | 106 | */ |
107 | - public function item(int $offset):?Element{ |
|
107 | + public function item(int $offset): ?Element{ |
|
108 | 108 | return $this->array[$offset] ?? null; |
109 | 109 | } |
110 | 110 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function offsetSet($offset, $value):void{ |
142 | 142 | |
143 | - if($value instanceof PrototypeNode){ |
|
143 | + if ($value instanceof PrototypeNode) { |
|
144 | 144 | |
145 | 145 | \is_int($offset) |
146 | 146 | ? $this->array[$offset] = $value |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return \chillerlan\PrototypeDOM\Node\Element|null |
157 | 157 | */ |
158 | - public function first():?Element{ |
|
158 | + public function first(): ?Element{ |
|
159 | 159 | return $this->__first(); |
160 | 160 | } |
161 | 161 | |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @return \chillerlan\PrototypeDOM\Node\Element|null |
166 | 166 | */ |
167 | - public function last():?Element{ |
|
167 | + public function last(): ?Element{ |
|
168 | 168 | return $this->__last(); |
169 | 169 | } |
170 | 170 |
@@ -51,11 +51,9 @@ |
||
51 | 51 | |
52 | 52 | if($nodes instanceof DOMNodeList){ |
53 | 53 | $this->array = \iterator_to_array($nodes); |
54 | - } |
|
55 | - elseif($nodes instanceof NodeList){ |
|
54 | + } elseif($nodes instanceof NodeList){ |
|
56 | 55 | $this->array = $nodes->toArray(); |
57 | - } |
|
58 | - elseif(\is_iterable($nodes)){ |
|
56 | + } elseif(\is_iterable($nodes)){ |
|
59 | 57 | foreach($nodes as $node){ |
60 | 58 | if($node instanceof DOMNode || $node instanceof PrototypeNode){ |
61 | 59 | $this->array[] = $node; |
@@ -12,6 +12,6 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\PrototypeDOM\Node; |
14 | 14 | |
15 | -class DocumentFragment extends \DOMDocumentFragment implements PrototypeElement{ |
|
15 | +class DocumentFragment extends \DOMDocumentFragment implements PrototypeElement { |
|
16 | 16 | use ElementTrait, NodeTrait, TraversalTrait; |
17 | 17 | } |
@@ -12,6 +12,6 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\PrototypeDOM\Node; |
14 | 14 | |
15 | -class Notation extends \DOMNotation implements PrototypeNode{ |
|
15 | +class Notation extends \DOMNotation implements PrototypeNode { |
|
16 | 16 | use NodeTrait; |
17 | 17 | } |
@@ -12,6 +12,6 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\PrototypeDOM\Node; |
14 | 14 | |
15 | -class ProcessingInstruction extends \DOMProcessingInstruction implements PrototypeNode{ |
|
15 | +class ProcessingInstruction extends \DOMProcessingInstruction implements PrototypeNode { |
|
16 | 16 | use NodeTrait; |
17 | 17 | } |
@@ -12,6 +12,6 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\PrototypeDOM\Node; |
14 | 14 | |
15 | -class Entity extends \DOMEntity implements PrototypeNode{ |
|
15 | +class Entity extends \DOMEntity implements PrototypeNode { |
|
16 | 16 | use NodeTrait; |
17 | 17 | } |
@@ -12,6 +12,6 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\PrototypeDOM\Node; |
14 | 14 | |
15 | -class Text extends \DOMText implements PrototypeElement{ |
|
15 | +class Text extends \DOMText implements PrototypeElement { |
|
16 | 16 | use ElementTrait, NodeTrait, TraversalTrait; |
17 | 17 | } |