@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | use FluidAliasesTrait, |
11 | 11 | FluidSaveTrait, |
12 | 12 | NewableTrait, |
13 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
14 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
13 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
14 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
15 | 15 | |
16 | 16 | private $document; |
17 | 17 | private $handler; |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | $this->document = $document; |
24 | 24 | $this->handler = $handler; |
25 | 25 | |
26 | - if (! \is_array($context) && ! $context instanceof \Traversable) { |
|
26 | + if (!\is_array($context) && !$context instanceof \Traversable) { |
|
27 | 27 | // DOMDocument, DOMElement and DOMNode are not iterable. |
28 | 28 | // DOMNodeList and FluidContext are iterable. |
29 | - $context = [ $context ]; |
|
29 | + $context = [$context]; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | foreach ($context as $n) { |
33 | - if (! $n instanceof \DOMNode) { |
|
33 | + if (!$n instanceof \DOMNode) { |
|
34 | 34 | throw new \Exception('Node type not recognized.'); |
35 | 35 | } |
36 | 36 | |
@@ -212,14 +212,14 @@ discard block |
||
212 | 212 | // addChild($child, $value?, $attributes? = [], $switchContext? = false) |
213 | 213 | public function addChild($child, ...$optionals) |
214 | 214 | { |
215 | - return $this->handler->insertElement($this->nodes, $child, $optionals, function ($parent, $element) { |
|
215 | + return $this->handler->insertElement($this->nodes, $child, $optionals, function($parent, $element) { |
|
216 | 216 | return $parent->appendChild($element); |
217 | 217 | }, $this); |
218 | 218 | } |
219 | 219 | |
220 | 220 | public function prependSibling($sibling, ...$optionals) |
221 | 221 | { |
222 | - return $this->handler->insertElement($this->nodes, $sibling, $optionals, function ($sibling, $element) { |
|
222 | + return $this->handler->insertElement($this->nodes, $sibling, $optionals, function($sibling, $element) { |
|
223 | 223 | if ($sibling->parentNode === null) { |
224 | 224 | // If the node doesn't have at least one parent node, |
225 | 225 | // the sibling creation fails. In this case we replace |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | |
235 | 235 | public function appendSibling($sibling, ...$optionals) |
236 | 236 | { |
237 | - return $this->handler->insertElement($this->nodes, $sibling, $optionals, function ($sibling, $element) { |
|
237 | + return $this->handler->insertElement($this->nodes, $sibling, $optionals, function($sibling, $element) { |
|
238 | 238 | if ($sibling->parentNode === null) { |
239 | 239 | // If the node doesn't have at least one parent node, |
240 | 240 | // the sibling creation fails. In this case we replace |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | if (\is_array($name)) { |
256 | 256 | $attrs = $name; |
257 | 257 | } else { |
258 | - $attrs = [ $name => $value ]; |
|
258 | + $attrs = [$name => $value]; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | foreach ($this->nodes as $n) { |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | |
289 | 289 | public function getText($glue = PHP_EOL) |
290 | 290 | { |
291 | - return implode($glue, $this->map(function ($i, $n) { return $n->textContent; })); |
|
291 | + return implode($glue, $this->map(function($i, $n) { return $n->textContent; })); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | public function setText($text) |
@@ -412,10 +412,10 @@ discard block |
||
412 | 412 | |
413 | 413 | protected function resolveQuery($query) |
414 | 414 | { |
415 | - if ( $query === '.' |
|
415 | + if ($query === '.' |
|
416 | 416 | || $query[0] === '/' |
417 | - || ( $query[0] === '.' && $query[1] === '/' ) |
|
418 | - || ( $query[0] === '.' && $query[1] === '.' ) ) { |
|
417 | + || ($query[0] === '.' && $query[1] === '/') |
|
418 | + || ($query[0] === '.' && $query[1] === '.')) { |
|
419 | 419 | return $query; |
420 | 420 | } |
421 | 421 | |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | $found = ($r === $u) || $found; |
434 | 434 | } |
435 | 435 | |
436 | - if (! $found) { |
|
436 | + if (!$found) { |
|
437 | 437 | $set[] = $r; |
438 | 438 | } |
439 | 439 | } |
@@ -4,15 +4,15 @@ |
||
4 | 4 | |
5 | 5 | trait FluidAliasesTrait |
6 | 6 | { |
7 | - public function size() { return $this->length(); } |
|
8 | - public function __invoke(...$query) { return $this->query(...$query); } |
|
9 | - public function add($child, ...$optionals) { return $this->addChild($child, ...$optionals); } |
|
7 | + public function size() { return $this->length(); } |
|
8 | + public function __invoke(...$query) { return $this->query(...$query); } |
|
9 | + public function add($child, ...$optionals) { return $this->addChild($child, ...$optionals); } |
|
10 | 10 | public function prepend($sibling, ...$optionals) { return $this->prependSibling($sibling, ...$optionals); } |
11 | - public function append($sibling, ...$optionals) { return $this->appendSibling($sibling, ...$optionals); } |
|
12 | - public function attr($name, $value = null) { return $this->setAttribute($name, $value); } |
|
13 | - public function text($text = null) { return $text ? $this->setText($text) : $this->getText(); } |
|
14 | - public function cdata($text) { return $this->setCdata($text); } |
|
15 | - public function comment($text) { return $this->setComment($text); } |
|
11 | + public function append($sibling, ...$optionals) { return $this->appendSibling($sibling, ...$optionals); } |
|
12 | + public function attr($name, $value = null) { return $this->setAttribute($name, $value); } |
|
13 | + public function text($text = null) { return $text ? $this->setText($text) : $this->getText(); } |
|
14 | + public function cdata($text) { return $this->setCdata($text); } |
|
15 | + public function comment($text) { return $this->setComment($text); } |
|
16 | 16 | abstract public function length(); |
17 | 17 | abstract public function query(...$query); |
18 | 18 | abstract public function addChild($child, ...$optionals); |
@@ -4,15 +4,33 @@ |
||
4 | 4 | |
5 | 5 | trait FluidAliasesTrait |
6 | 6 | { |
7 | - public function size() { return $this->length(); } |
|
8 | - public function __invoke(...$query) { return $this->query(...$query); } |
|
9 | - public function add($child, ...$optionals) { return $this->addChild($child, ...$optionals); } |
|
10 | - public function prepend($sibling, ...$optionals) { return $this->prependSibling($sibling, ...$optionals); } |
|
11 | - public function append($sibling, ...$optionals) { return $this->appendSibling($sibling, ...$optionals); } |
|
12 | - public function attr($name, $value = null) { return $this->setAttribute($name, $value); } |
|
13 | - public function text($text = null) { return $text ? $this->setText($text) : $this->getText(); } |
|
14 | - public function cdata($text) { return $this->setCdata($text); } |
|
15 | - public function comment($text) { return $this->setComment($text); } |
|
7 | + public function size() |
|
8 | + { |
|
9 | +return $this->length(); } |
|
10 | + public function __invoke(...$query) |
|
11 | + { |
|
12 | +return $this->query(...$query); } |
|
13 | + public function add($child, ...$optionals) |
|
14 | + { |
|
15 | +return $this->addChild($child, ...$optionals); } |
|
16 | + public function prepend($sibling, ...$optionals) |
|
17 | + { |
|
18 | +return $this->prependSibling($sibling, ...$optionals); } |
|
19 | + public function append($sibling, ...$optionals) |
|
20 | + { |
|
21 | +return $this->appendSibling($sibling, ...$optionals); } |
|
22 | + public function attr($name, $value = null) |
|
23 | + { |
|
24 | +return $this->setAttribute($name, $value); } |
|
25 | + public function text($text = null) |
|
26 | + { |
|
27 | +return $text ? $this->setText($text) : $this->getText(); } |
|
28 | + public function cdata($text) |
|
29 | + { |
|
30 | +return $this->setCdata($text); } |
|
31 | + public function comment($text) |
|
32 | + { |
|
33 | +return $this->setComment($text); } |
|
16 | 34 | abstract public function length(); |
17 | 35 | abstract public function query(...$query); |
18 | 36 | abstract public function addChild($child, ...$optionals); |
@@ -11,15 +11,15 @@ discard block |
||
11 | 11 | use FluidAliasesTrait, |
12 | 12 | FluidSaveTrait, |
13 | 13 | NewableTrait, |
14 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
15 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
14 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
15 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
16 | 16 | |
17 | 17 | const ROOT_NODE = 'doc'; |
18 | 18 | |
19 | - private $defaults = [ 'root' => self::ROOT_NODE, |
|
19 | + private $defaults = ['root' => self::ROOT_NODE, |
|
20 | 20 | 'version' => '1.0', |
21 | 21 | 'encoding' => 'UTF-8', |
22 | - 'stylesheet' => null ]; |
|
22 | + 'stylesheet' => null]; |
|
23 | 23 | |
24 | 24 | private $document; |
25 | 25 | private $handler; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | $document = \file_get_contents($file); |
33 | 33 | |
34 | 34 | // file_get_contents() returns false in case of error. |
35 | - if (! $document) { |
|
35 | + if (!$document) { |
|
36 | 36 | throw new \Exception("File '$file' not accessible."); |
37 | 37 | } |
38 | 38 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | private function initStylesheet(&$options) |
98 | 98 | { |
99 | - if (! empty($options['stylesheet'])) { |
|
99 | + if (!empty($options['stylesheet'])) { |
|
100 | 100 | $attrs = 'type="text/xsl" ' |
101 | 101 | . "encoding=\"{$options['encoding']}\" " |
102 | 102 | . 'indent="yes" ' |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | private function initRoot(&$options) |
118 | 118 | { |
119 | - if (! empty($options['root'])) { |
|
119 | + if (!empty($options['root'])) { |
|
120 | 120 | $this->appendSibling($options['root']); |
121 | 121 | } |
122 | 122 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $el = $this->document->dom; |
145 | 145 | } |
146 | 146 | |
147 | - return [ $el ]; |
|
147 | + return [$el]; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | public function __toString() |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | $namespaces = []; |
188 | 188 | |
189 | 189 | if (\is_string($arguments[0])) { |
190 | - $args = [ $arguments[0], $arguments[1] ]; |
|
190 | + $args = [$arguments[0], $arguments[1]]; |
|
191 | 191 | |
192 | 192 | if (isset($arguments[2])) { |
193 | 193 | $args[] = $arguments[2]; |
@@ -206,20 +206,20 @@ discard block |
||
206 | 206 | return $this; |
207 | 207 | } |
208 | 208 | |
209 | - public function query(...$query) { return $this->context()->query(...$query); } |
|
209 | + public function query(...$query) { return $this->context()->query(...$query); } |
|
210 | 210 | public function times($times, callable $fn = null) { return $this->context()->times($times, $fn); } |
211 | - public function each(callable $fn) { return $this->context()->each($fn); } |
|
212 | - public function map(callable $fn) { return $this->context()->map($fn); } |
|
213 | - public function filter(callable $fn) { return $this->context()->filter($fn); } |
|
211 | + public function each(callable $fn) { return $this->context()->each($fn); } |
|
212 | + public function map(callable $fn) { return $this->context()->map($fn); } |
|
213 | + public function filter(callable $fn) { return $this->context()->filter($fn); } |
|
214 | 214 | public function setAttribute($name, $value = null) { $this->context()->setAttribute($name, $value); return $this; } |
215 | - public function getText($glue = PHP_EOL) { return $this->context()->getText($glue); } |
|
216 | - public function setText($text) { $this->context()->setText($text); return $this; } |
|
217 | - public function addText($text) { $this->context()->addText($text); return $this; } |
|
218 | - public function setCdata($text) { $this->context()->setCdata($text); return $this; } |
|
219 | - public function addCdata($text) { $this->context()->addCdata($text); return $this; } |
|
220 | - public function setComment($text) { $this->context()->setComment($text); return $this; } |
|
221 | - public function addComment($text) { $this->context()->addComment($text); return $this; } |
|
222 | - public function remove(...$query) { $this->context()->remove(...$query); return $this; } |
|
215 | + public function getText($glue = PHP_EOL) { return $this->context()->getText($glue); } |
|
216 | + public function setText($text) { $this->context()->setText($text); return $this; } |
|
217 | + public function addText($text) { $this->context()->addText($text); return $this; } |
|
218 | + public function setCdata($text) { $this->context()->setCdata($text); return $this; } |
|
219 | + public function addCdata($text) { $this->context()->addCdata($text); return $this; } |
|
220 | + public function setComment($text) { $this->context()->setComment($text); return $this; } |
|
221 | + public function addComment($text) { $this->context()->addComment($text); return $this; } |
|
222 | + public function remove(...$query) { $this->context()->remove(...$query); return $this; } |
|
223 | 223 | |
224 | 224 | public function addChild($child, ...$optionals) |
225 | 225 | { |
@@ -206,20 +206,48 @@ |
||
206 | 206 | return $this; |
207 | 207 | } |
208 | 208 | |
209 | - public function query(...$query) { return $this->context()->query(...$query); } |
|
210 | - public function times($times, callable $fn = null) { return $this->context()->times($times, $fn); } |
|
211 | - public function each(callable $fn) { return $this->context()->each($fn); } |
|
212 | - public function map(callable $fn) { return $this->context()->map($fn); } |
|
213 | - public function filter(callable $fn) { return $this->context()->filter($fn); } |
|
214 | - public function setAttribute($name, $value = null) { $this->context()->setAttribute($name, $value); return $this; } |
|
215 | - public function getText($glue = PHP_EOL) { return $this->context()->getText($glue); } |
|
216 | - public function setText($text) { $this->context()->setText($text); return $this; } |
|
217 | - public function addText($text) { $this->context()->addText($text); return $this; } |
|
218 | - public function setCdata($text) { $this->context()->setCdata($text); return $this; } |
|
219 | - public function addCdata($text) { $this->context()->addCdata($text); return $this; } |
|
220 | - public function setComment($text) { $this->context()->setComment($text); return $this; } |
|
221 | - public function addComment($text) { $this->context()->addComment($text); return $this; } |
|
222 | - public function remove(...$query) { $this->context()->remove(...$query); return $this; } |
|
209 | + public function query(...$query) |
|
210 | + { |
|
211 | +return $this->context()->query(...$query); } |
|
212 | + public function times($times, callable $fn = null) |
|
213 | + { |
|
214 | +return $this->context()->times($times, $fn); } |
|
215 | + public function each(callable $fn) |
|
216 | + { |
|
217 | +return $this->context()->each($fn); } |
|
218 | + public function map(callable $fn) |
|
219 | + { |
|
220 | +return $this->context()->map($fn); } |
|
221 | + public function filter(callable $fn) |
|
222 | + { |
|
223 | +return $this->context()->filter($fn); } |
|
224 | + public function setAttribute($name, $value = null) |
|
225 | + { |
|
226 | +$this->context()->setAttribute($name, $value); return $this; } |
|
227 | + public function getText($glue = PHP_EOL) |
|
228 | + { |
|
229 | +return $this->context()->getText($glue); } |
|
230 | + public function setText($text) |
|
231 | + { |
|
232 | +$this->context()->setText($text); return $this; } |
|
233 | + public function addText($text) |
|
234 | + { |
|
235 | +$this->context()->addText($text); return $this; } |
|
236 | + public function setCdata($text) |
|
237 | + { |
|
238 | +$this->context()->setCdata($text); return $this; } |
|
239 | + public function addCdata($text) |
|
240 | + { |
|
241 | +$this->context()->addCdata($text); return $this; } |
|
242 | + public function setComment($text) |
|
243 | + { |
|
244 | +$this->context()->setComment($text); return $this; } |
|
245 | + public function addComment($text) |
|
246 | + { |
|
247 | +$this->context()->addComment($text); return $this; } |
|
248 | + public function remove(...$query) |
|
249 | + { |
|
250 | +$this->context()->remove(...$query); return $this; } |
|
223 | 251 | |
224 | 252 | public function addChild($child, ...$optionals) |
225 | 253 | { |