@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | class FluidXml implements FluidInterface |
134 | 134 | { |
135 | 135 | use NewableTrait, |
136 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
137 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
136 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
137 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
138 | 138 | |
139 | 139 | const ROOT_NODE = 'doc'; |
140 | 140 | |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | $doc = $this->document; |
169 | 169 | |
170 | 170 | $defaults = [ 'root' => self::ROOT_NODE, |
171 | - 'version' => '1.0', |
|
172 | - 'encoding' => 'UTF-8', |
|
173 | - 'stylesheet' => null ]; |
|
171 | + 'version' => '1.0', |
|
172 | + 'encoding' => 'UTF-8', |
|
173 | + 'stylesheet' => null ]; |
|
174 | 174 | |
175 | 175 | if (\is_string($root)) { |
176 | 176 | // The root option can be specified as first argument |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | |
197 | 197 | if (! empty($opts['stylesheet'])) { |
198 | 198 | $attrs = 'type="text/xsl" ' |
199 | - . "encoding=\"{$opts['encoding']}\" " |
|
200 | - . 'indent="yes" ' |
|
201 | - . "href=\"{$opts['stylesheet']}\""; |
|
199 | + . "encoding=\"{$opts['encoding']}\" " |
|
200 | + . 'indent="yes" ' |
|
201 | + . "href=\"{$opts['stylesheet']}\""; |
|
202 | 202 | $stylesheet = new \DOMProcessingInstruction('xml-stylesheet', $attrs); |
203 | 203 | |
204 | 204 | $doc->dom->insertBefore($stylesheet, $doc->dom->documentElement); |
@@ -447,8 +447,8 @@ discard block |
||
447 | 447 | const MODE_EXPLICIT = 1; |
448 | 448 | |
449 | 449 | private $config = [ self::ID => '', |
450 | - self::URI => '', |
|
451 | - self::MODE => self::MODE_EXPLICIT ]; |
|
450 | + self::URI => '', |
|
451 | + self::MODE => self::MODE_EXPLICIT ]; |
|
452 | 452 | |
453 | 453 | public function __construct($id, $uri, $mode = 1) |
454 | 454 | { |
@@ -529,7 +529,6 @@ discard block |
||
529 | 529 | * |
530 | 530 | * ```php |
531 | 531 | * $xml = fluidxml(); |
532 | - |
|
533 | 532 | * $xml->query("/doc/book[@id='123']"); |
534 | 533 | * |
535 | 534 | * // Relative queries are valid. |
@@ -549,7 +548,6 @@ discard block |
||
549 | 548 | * |
550 | 549 | * ```php |
551 | 550 | * $xml = fluidxml(); |
552 | - |
|
553 | 551 | * $xml->appendChild('title', 'The Theory Of Everything'); |
554 | 552 | * $xml->appendChild([ 'author' => 'S. Hawking' ]); |
555 | 553 | * |
@@ -664,8 +662,8 @@ discard block |
||
664 | 662 | class FluidContext implements FluidInterface, \ArrayAccess, \Iterator |
665 | 663 | { |
666 | 664 | use NewableTrait, |
667 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
668 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
665 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
666 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
669 | 667 | |
670 | 668 | private $document; |
671 | 669 | private $nodes = []; |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | class FluidXml implements FluidInterface |
138 | 138 | { |
139 | 139 | use NewableTrait, |
140 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
141 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
140 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
141 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
142 | 142 | |
143 | 143 | const ROOT_NODE = 'doc'; |
144 | 144 | |
@@ -147,12 +147,12 @@ discard block |
||
147 | 147 | |
148 | 148 | public static function load($document) |
149 | 149 | { |
150 | - if (\is_string($document) && ! is_an_xml_string($document)) { |
|
150 | + if (\is_string($document) && !is_an_xml_string($document)) { |
|
151 | 151 | $file = $document; |
152 | 152 | $document = \file_get_contents($file); |
153 | 153 | |
154 | 154 | // file_get_contents returns false if it can't read. |
155 | - if (! $document) { |
|
155 | + if (!$document) { |
|
156 | 156 | throw new \Exception("File '$file' not accessible."); |
157 | 157 | } |
158 | 158 | } |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | |
163 | 163 | public function __construct($root = null, $options = []) |
164 | 164 | { |
165 | - $defaults = [ 'root' => self::ROOT_NODE, |
|
165 | + $defaults = ['root' => self::ROOT_NODE, |
|
166 | 166 | 'version' => '1.0', |
167 | 167 | 'encoding' => 'UTF-8', |
168 | - 'stylesheet' => null ]; |
|
168 | + 'stylesheet' => null]; |
|
169 | 169 | |
170 | 170 | if (\is_string($root)) { |
171 | 171 | // The root option can be specified as first argument |
@@ -190,11 +190,11 @@ discard block |
||
190 | 190 | |
191 | 191 | $this->handler = new FluidInsertionHandler($doc); |
192 | 192 | |
193 | - if (! empty($opts['root'])) { |
|
193 | + if (!empty($opts['root'])) { |
|
194 | 194 | $this->appendSibling($opts['root']); |
195 | 195 | } |
196 | 196 | |
197 | - if (! empty($opts['stylesheet'])) { |
|
197 | + if (!empty($opts['stylesheet'])) { |
|
198 | 198 | $attrs = 'type="text/xsl" ' |
199 | 199 | . "encoding=\"{$opts['encoding']}\" " |
200 | 200 | . 'indent="yes" ' |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | $namespaces = []; |
233 | 233 | |
234 | 234 | if (\is_string($arguments[0])) { |
235 | - $args = [ $arguments[0], $arguments[1] ]; |
|
235 | + $args = [$arguments[0], $arguments[1]]; |
|
236 | 236 | |
237 | 237 | if (isset($arguments[2])) { |
238 | 238 | $args[] = $arguments[2]; |
@@ -435,16 +435,16 @@ discard block |
||
435 | 435 | |
436 | 436 | class FluidNamespace |
437 | 437 | { |
438 | - const ID = 'id' ; |
|
439 | - const URI = 'uri' ; |
|
438 | + const ID = 'id'; |
|
439 | + const URI = 'uri'; |
|
440 | 440 | const MODE = 'mode'; |
441 | 441 | |
442 | 442 | const MODE_IMPLICIT = 0; |
443 | 443 | const MODE_EXPLICIT = 1; |
444 | 444 | |
445 | - private $config = [ self::ID => '', |
|
445 | + private $config = [self::ID => '', |
|
446 | 446 | self::URI => '', |
447 | - self::MODE => self::MODE_EXPLICIT ]; |
|
447 | + self::MODE => self::MODE_EXPLICIT]; |
|
448 | 448 | |
449 | 449 | public function __construct($id, $uri, $mode = 1) |
450 | 450 | { |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | { |
483 | 483 | $id = $this->id(); |
484 | 484 | |
485 | - if (! empty($id)) { |
|
485 | + if (!empty($id)) { |
|
486 | 486 | $id .= ':'; |
487 | 487 | } |
488 | 488 | |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | $nodes = \explode('/', $xpath); |
494 | 494 | |
495 | 495 | foreach ($nodes as $node) { |
496 | - if (! empty($node)) { |
|
496 | + if (!empty($node)) { |
|
497 | 497 | // An XPath query can have multiple slashes. |
498 | 498 | // Example: //target |
499 | 499 | $new_xpath .= "{$id}{$node}"; |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | { |
671 | 671 | $this->document = $document; |
672 | 672 | $this->dom = $document->dom; |
673 | - $this->namespaces =& $document->namespaces; |
|
673 | + $this->namespaces = & $document->namespaces; |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | public function insertElement(&$nodes, $element, &$optionals, $fn, $orig_context) |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | // offers to the user and is the same of: |
693 | 693 | // 1. appending a child switching the context |
694 | 694 | // 2. setting the attributes over the new context. |
695 | - if (! empty($attributes)) { |
|
695 | + if (!empty($attributes)) { |
|
696 | 696 | $new_context->setAttribute($attributes); |
697 | 697 | } |
698 | 698 | |
@@ -706,8 +706,8 @@ discard block |
||
706 | 706 | |
707 | 707 | protected function handleOptionals($element, &$optionals) |
708 | 708 | { |
709 | - if (! \is_array($element)) { |
|
710 | - $element = [ $element ]; |
|
709 | + if (!\is_array($element)) { |
|
710 | + $element = [$element]; |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | $switch_context = false; |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | } |
731 | 731 | } |
732 | 732 | |
733 | - return [ $element, $attributes, $switch_context ]; |
|
733 | + return [$element, $attributes, $switch_context]; |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | |
@@ -751,9 +751,9 @@ discard block |
||
751 | 751 | $v_is_string = \is_string($v); |
752 | 752 | $v_is_xml = $v_is_string && is_an_xml_string($v); |
753 | 753 | $k_is_special = $k_is_string && $k[0] === '@'; |
754 | - $k_isnt_special = ! $k_is_special; |
|
755 | - $v_isnt_string = ! $v_is_string; |
|
756 | - $v_isnt_xml = ! $v_is_xml; |
|
754 | + $k_isnt_special = !$k_is_special; |
|
755 | + $v_isnt_string = !$v_is_string; |
|
756 | + $v_isnt_xml = !$v_is_xml; |
|
757 | 757 | /////////////////////////////////////////////////////// |
758 | 758 | |
759 | 759 | if ($k_is_string && $k_isnt_special && $v_is_string && $v_isnt_xml) { |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | } |
774 | 774 | |
775 | 775 | ///////////////////////////////////////////////////// |
776 | - $k_is_special_a = $k_is_special && ! $k_is_special_c; |
|
776 | + $k_is_special_a = $k_is_special && !$k_is_special_c; |
|
777 | 777 | ///////////////////////////////////////////////////// |
778 | 778 | |
779 | 779 | if ($k_is_special_a && $v_is_string) { |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | $v_is_domnode = $v instanceof \DOMNode; |
826 | 826 | /////////////////////////////////////// |
827 | 827 | |
828 | - if ($k_is_integer && ! $v_is_domdoc && $v_is_domnode) { |
|
828 | + if ($k_is_integer && !$v_is_domdoc && $v_is_domnode) { |
|
829 | 829 | return $this->insertIntegerDomnode($parent, $k, $v, $fn, $optionals); |
830 | 830 | } |
831 | 831 | |
@@ -893,8 +893,8 @@ discard block |
||
893 | 893 | |
894 | 894 | protected function attachNodes($parent, $nodes, $fn) |
895 | 895 | { |
896 | - if (! \is_array($nodes) && ! $nodes instanceof \Traversable) { |
|
897 | - $nodes = [ $nodes ]; |
|
896 | + if (!\is_array($nodes) && !$nodes instanceof \Traversable) { |
|
897 | + $nodes = [$nodes]; |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | $context = []; |
@@ -943,7 +943,7 @@ discard block |
||
943 | 943 | $el = $this->createElement($k, $v); |
944 | 944 | $el = $fn($parent, $el); |
945 | 945 | |
946 | - return [ $el ]; |
|
946 | + return [$el]; |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | protected function insertStringMixed($parent, $k, $v, $fn, &$optionals) |
@@ -959,7 +959,7 @@ discard block |
||
959 | 959 | // they are supplied, so 'appendChild' is the perfect operation. |
960 | 960 | $this->newContext($el)->appendChild($v, ...$optionals); |
961 | 961 | |
962 | - return [ $el ]; |
|
962 | + return [$el]; |
|
963 | 963 | } |
964 | 964 | |
965 | 965 | protected function insertIntegerArray($parent, $k, $v, $fn, &$optionals) |
@@ -986,7 +986,7 @@ discard block |
||
986 | 986 | $el = $this->createElement($v); |
987 | 987 | $el = $fn($parent, $el); |
988 | 988 | |
989 | - return [ $el ]; |
|
989 | + return [$el]; |
|
990 | 990 | } |
991 | 991 | |
992 | 992 | protected function insertIntegerXml($parent, $k, $v, $fn) |
@@ -1058,8 +1058,8 @@ discard block |
||
1058 | 1058 | class FluidContext implements FluidInterface, \ArrayAccess, \Iterator |
1059 | 1059 | { |
1060 | 1060 | use NewableTrait, |
1061 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
1062 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
1061 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
1062 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
1063 | 1063 | |
1064 | 1064 | private $document; |
1065 | 1065 | private $handler; |
@@ -1071,14 +1071,14 @@ discard block |
||
1071 | 1071 | $this->document = $document; |
1072 | 1072 | $this->handler = $handler; |
1073 | 1073 | |
1074 | - if (! \is_array($context) && ! $context instanceof \Traversable) { |
|
1074 | + if (!\is_array($context) && !$context instanceof \Traversable) { |
|
1075 | 1075 | // DOMDocument, DOMElement and DOMNode are not iterable. |
1076 | 1076 | // DOMNodeList and FluidContext are iterable. |
1077 | - $context = [ $context ]; |
|
1077 | + $context = [$context]; |
|
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | foreach ($context as $n) { |
1081 | - if (! $n instanceof \DOMNode) { |
|
1081 | + if (!$n instanceof \DOMNode) { |
|
1082 | 1082 | throw new \Exception('Node type not recognized.'); |
1083 | 1083 | } |
1084 | 1084 | |
@@ -1289,7 +1289,7 @@ discard block |
||
1289 | 1289 | // the user has passed two arguments: |
1290 | 1290 | // 1. is the attribute name |
1291 | 1291 | // 2. is the attribute value |
1292 | - if (! \is_array($arguments[0])) { |
|
1292 | + if (!\is_array($arguments[0])) { |
|
1293 | 1293 | $attrs = [$arguments[0] => $arguments[1]]; |
1294 | 1294 | } |
1295 | 1295 | |
@@ -1422,7 +1422,7 @@ discard block |
||
1422 | 1422 | $found = ($r === $u) || $found; |
1423 | 1423 | } |
1424 | 1424 | |
1425 | - if (! $found) { |
|
1425 | + if (!$found) { |
|
1426 | 1426 | $set[] = $r; |
1427 | 1427 | } |
1428 | 1428 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @param array $arguments Options that influence the construction of the XML document. |
72 | 72 | * |
73 | - * @return FluidXml A new FluidXml instance. |
|
73 | + * @return FluidContext A new FluidXml instance. |
|
74 | 74 | */ |
75 | 75 | function fluidify(...$arguments) |
76 | 76 | { |
@@ -87,6 +87,9 @@ discard block |
||
87 | 87 | return new FluidNamespace(...$arguments); |
88 | 88 | } |
89 | 89 | |
90 | +/** |
|
91 | + * @param string $string |
|
92 | + */ |
|
90 | 93 | function is_an_xml_string($string) |
91 | 94 | { |
92 | 95 | // Removes any empty new line at the beginning, |
@@ -532,7 +535,7 @@ discard block |
||
532 | 535 | * $xml->query("/doc")->query("book[@id='123']"); |
533 | 536 | * ``` |
534 | 537 | * |
535 | - * @param string $xpath The XPath to execute. |
|
538 | + * @param string[] $xpath The XPath to execute. |
|
536 | 539 | * |
537 | 540 | * @return FluidContext The context associated to the DOMNodeList. |
538 | 541 | */ |
@@ -572,6 +575,10 @@ discard block |
||
572 | 575 | public function remove(...$xpath); |
573 | 576 | public function xml($strip = false); |
574 | 577 | // Aliases: |
578 | + |
|
579 | + /** |
|
580 | + * @return FluidContext |
|
581 | + */ |
|
575 | 582 | public function add($child, ...$optionals); |
576 | 583 | public function prepend($sibling, ...$optionals); |
577 | 584 | public function insertSiblingBefore($sibling, ...$optionals); |
@@ -635,6 +642,9 @@ discard block |
||
635 | 642 | private $context; |
636 | 643 | private $times; |
637 | 644 | |
645 | + /** |
|
646 | + * @param FluidContext $context |
|
647 | + */ |
|
638 | 648 | public function __construct($document, $handler, $context, $times) |
639 | 649 | { |
640 | 650 | $this->document = $document; |
@@ -667,6 +677,9 @@ discard block |
||
667 | 677 | private $dom; |
668 | 678 | private $namespaces; |
669 | 679 | |
680 | + /** |
|
681 | + * @param FluidDocument $document |
|
682 | + */ |
|
670 | 683 | public function __construct($document) |
671 | 684 | { |
672 | 685 | $this->document = $document; |
@@ -908,6 +921,10 @@ discard block |
||
908 | 921 | return $context; |
909 | 922 | } |
910 | 923 | |
924 | + /** |
|
925 | + * @param string $k |
|
926 | + * @param string $v |
|
927 | + */ |
|
911 | 928 | protected function insertSpecialContent($parent, $k, $v) |
912 | 929 | { |
913 | 930 | // The user has passed an element text content: |
@@ -925,6 +942,10 @@ discard block |
||
925 | 942 | return []; |
926 | 943 | } |
927 | 944 | |
945 | + /** |
|
946 | + * @param string $k |
|
947 | + * @param string $v |
|
948 | + */ |
|
928 | 949 | protected function insertSpecialAttribute($parent, $k, $v) |
929 | 950 | { |
930 | 951 | // The user has passed an attribute name and an attribute value: |
@@ -936,6 +957,10 @@ discard block |
||
936 | 957 | return []; |
937 | 958 | } |
938 | 959 | |
960 | + /** |
|
961 | + * @param string $k |
|
962 | + * @param string $v |
|
963 | + */ |
|
939 | 964 | protected function insertStringString($parent, $k, $v, $fn) |
940 | 965 | { |
941 | 966 | // The user has passed an element name and an element value: |
@@ -947,6 +972,9 @@ discard block |
||
947 | 972 | return [ $el ]; |
948 | 973 | } |
949 | 974 | |
975 | + /** |
|
976 | + * @param string $k |
|
977 | + */ |
|
950 | 978 | protected function insertStringMixed($parent, $k, $v, $fn, &$optionals) |
951 | 979 | { |
952 | 980 | // The user has passed one of these two cases: |
@@ -963,6 +991,9 @@ discard block |
||
963 | 991 | return [ $el ]; |
964 | 992 | } |
965 | 993 | |
994 | + /** |
|
995 | + * @param integer $k |
|
996 | + */ |
|
966 | 997 | protected function insertIntegerArray($parent, $k, $v, $fn, &$optionals) |
967 | 998 | { |
968 | 999 | // The user has passed a wrapper array: |
@@ -979,6 +1010,10 @@ discard block |
||
979 | 1010 | return $context; |
980 | 1011 | } |
981 | 1012 | |
1013 | + /** |
|
1014 | + * @param integer $k |
|
1015 | + * @param string $v |
|
1016 | + */ |
|
982 | 1017 | protected function insertIntegerString($parent, $k, $v, $fn) |
983 | 1018 | { |
984 | 1019 | // The user has passed a node name without a node value: |
@@ -990,6 +1025,10 @@ discard block |
||
990 | 1025 | return [ $el ]; |
991 | 1026 | } |
992 | 1027 | |
1028 | + /** |
|
1029 | + * @param integer $k |
|
1030 | + * @param string $v |
|
1031 | + */ |
|
993 | 1032 | protected function insertIntegerXml($parent, $k, $v, $fn) |
994 | 1033 | { |
995 | 1034 | // The user has passed an XML document instance: |
@@ -1019,6 +1058,10 @@ discard block |
||
1019 | 1058 | return $this->attachNodes($parent, $nodes, $fn); |
1020 | 1059 | } |
1021 | 1060 | |
1061 | + /** |
|
1062 | + * @param integer $k |
|
1063 | + * @param \DOMDocument $v |
|
1064 | + */ |
|
1022 | 1065 | protected function insertIntegerDomdocument($parent, $k, $v, $fn) |
1023 | 1066 | { |
1024 | 1067 | // A DOMDocument can have multiple root nodes. |
@@ -1030,26 +1073,46 @@ discard block |
||
1030 | 1073 | // return $this->attachNodes($parent, $v->documentElement, $fn); |
1031 | 1074 | } |
1032 | 1075 | |
1076 | + /** |
|
1077 | + * @param integer $k |
|
1078 | + * @param \DOMNodeList $v |
|
1079 | + */ |
|
1033 | 1080 | protected function insertIntegerDomnodelist($parent, $k, $v, $fn) |
1034 | 1081 | { |
1035 | 1082 | return $this->attachNodes($parent, $v, $fn); |
1036 | 1083 | } |
1037 | 1084 | |
1085 | + /** |
|
1086 | + * @param integer $k |
|
1087 | + * @param \DOMNode $v |
|
1088 | + */ |
|
1038 | 1089 | protected function insertIntegerDomnode($parent, $k, $v, $fn) |
1039 | 1090 | { |
1040 | 1091 | return $this->attachNodes($parent, $v, $fn); |
1041 | 1092 | } |
1042 | 1093 | |
1094 | + /** |
|
1095 | + * @param integer $k |
|
1096 | + * @param \SimpleXMLElement $v |
|
1097 | + */ |
|
1043 | 1098 | protected function insertIntegerSimplexml($parent, $k, $v, $fn) |
1044 | 1099 | { |
1045 | 1100 | return $this->attachNodes($parent, \dom_import_simplexml($v), $fn); |
1046 | 1101 | } |
1047 | 1102 | |
1103 | + /** |
|
1104 | + * @param integer $k |
|
1105 | + * @param FluidXml $v |
|
1106 | + */ |
|
1048 | 1107 | protected function insertIntegerFluidxml($parent, $k, $v, $fn) |
1049 | 1108 | { |
1050 | 1109 | return $this->attachNodes($parent, $v->dom()->documentElement, $fn); |
1051 | 1110 | } |
1052 | 1111 | |
1112 | + /** |
|
1113 | + * @param integer $k |
|
1114 | + * @param FluidContext $v |
|
1115 | + */ |
|
1053 | 1116 | protected function insertIntegerFluidcontext($parent, $k, $v, $fn) |
1054 | 1117 | { |
1055 | 1118 | return $this->attachNodes($parent, $v->asArray(), $fn); |
@@ -1433,6 +1496,9 @@ discard block |
||
1433 | 1496 | return $set; |
1434 | 1497 | } |
1435 | 1498 | |
1499 | + /** |
|
1500 | + * @param callable $fn |
|
1501 | + */ |
|
1436 | 1502 | protected function callfn($fn, $args) |
1437 | 1503 | { |
1438 | 1504 | if ($fn instanceof \Closure) { |