@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @param array $arguments Options that influence the construction of the XML document. |
70 | 70 | * |
71 | - * @return FluidXml A new FluidXml instance. |
|
71 | + * @return FluidContext A new FluidXml instance. |
|
72 | 72 | */ |
73 | 73 | function fluidify(...$arguments) |
74 | 74 | { |
@@ -85,6 +85,9 @@ discard block |
||
85 | 85 | return new FluidNamespace(...$arguments); |
86 | 86 | } |
87 | 87 | |
88 | +/** |
|
89 | + * @param string $string |
|
90 | + */ |
|
88 | 91 | function is_an_xml_string($string) |
89 | 92 | { |
90 | 93 | // Removes any empty new line at the beginning, |
@@ -143,12 +146,16 @@ discard block |
||
143 | 146 | * $xml->query("/doc")->query("book[@id='123']"); |
144 | 147 | * ``` |
145 | 148 | * |
146 | - * @param string $xpath The XPath to execute. |
|
149 | + * @param string[] $xpath The XPath to execute. |
|
147 | 150 | * |
148 | 151 | * @return FluidContext The context associated to the DOMNodeList. |
149 | 152 | */ |
150 | 153 | public function query(...$xpath); |
151 | 154 | public function times($times, callable $fn = null); |
155 | + |
|
156 | + /** |
|
157 | + * @return FluidContext |
|
158 | + */ |
|
152 | 159 | public function each(callable $fn); |
153 | 160 | |
154 | 161 | /** |
@@ -165,9 +172,6 @@ discard block |
||
165 | 172 | * ``` |
166 | 173 | * |
167 | 174 | * @param string|array $child The child/children to add. |
168 | - * @param string $value The child text content. |
|
169 | - * @param bool $switchContext Whether to return the current context |
|
170 | - * or the context of the created node. |
|
171 | 175 | * |
172 | 176 | * @return FluidContext The context associated to the DOMNodeList. |
173 | 177 | */ |
@@ -182,6 +186,10 @@ discard block |
||
182 | 186 | public function remove(...$xpath); |
183 | 187 | public function xml($strip = false); |
184 | 188 | // Aliases: |
189 | + |
|
190 | + /** |
|
191 | + * @return FluidContext |
|
192 | + */ |
|
185 | 193 | public function add($child, ...$optionals); |
186 | 194 | public function prepend($sibling, ...$optionals); |
187 | 195 | public function insertSiblingBefore($sibling, ...$optionals); |
@@ -478,6 +486,10 @@ discard block |
||
478 | 486 | return new FluidContext($context, $this->namespaces); |
479 | 487 | } |
480 | 488 | |
489 | + /** |
|
490 | + * @param FluidContext $helpContext |
|
491 | + * @param FluidContext $newContext |
|
492 | + */ |
|
481 | 493 | protected function chooseContext($helpContext, $newContext) |
482 | 494 | { |
483 | 495 | // If the two contextes are diffent, the user has requested |
@@ -876,6 +888,10 @@ discard block |
||
876 | 888 | return new FluidContext($context, $this->namespaces); |
877 | 889 | } |
878 | 890 | |
891 | + /** |
|
892 | + * @param string $name |
|
893 | + * @param string $value |
|
894 | + */ |
|
879 | 895 | protected function createElement($name, $value = null) |
880 | 896 | { |
881 | 897 | // The DOMElement instance must be different for every node, |
@@ -1211,6 +1227,9 @@ discard block |
||
1211 | 1227 | protected $context; |
1212 | 1228 | protected $times; |
1213 | 1229 | |
1230 | + /** |
|
1231 | + * @param FluidContext $context |
|
1232 | + */ |
|
1214 | 1233 | public function __construct($context, $times) |
1215 | 1234 | { |
1216 | 1235 | $this->context = $context; |
@@ -136,7 +136,6 @@ discard block |
||
136 | 136 | * |
137 | 137 | * ```php |
138 | 138 | * $xml = fluidxml(); |
139 | - |
|
140 | 139 | * $xml->query("/doc/book[@id='123']"); |
141 | 140 | * |
142 | 141 | * // Relative queries are valid. |
@@ -156,7 +155,6 @@ discard block |
||
156 | 155 | * |
157 | 156 | * ```php |
158 | 157 | * $xml = fluidxml(); |
159 | - |
|
160 | 158 | * $xml->appendChild('title', 'The Theory Of Everything'); |
161 | 159 | * $xml->appendChild([ 'author' => 'S. Hawking' ]); |
162 | 160 | * |
@@ -234,8 +232,8 @@ discard block |
||
234 | 232 | class FluidXml implements FluidInterface |
235 | 233 | { |
236 | 234 | use FluidNamespaceTrait, |
237 | - FluidXmlShadowTrait, // For compatibility with PHP 5.6. |
|
238 | - FluidContextShadowTrait; // For compatibility with PHP 5.6. |
|
235 | + FluidXmlShadowTrait, // For compatibility with PHP 5.6. |
|
236 | + FluidContextShadowTrait; // For compatibility with PHP 5.6. |
|
239 | 237 | |
240 | 238 | const ROOT_NODE = 'doc'; |
241 | 239 | |
@@ -266,9 +264,9 @@ discard block |
||
266 | 264 | public function __construct($root = null, $options = []) |
267 | 265 | { |
268 | 266 | $defaults = [ 'root' => self::ROOT_NODE, |
269 | - 'version' => '1.0', |
|
270 | - 'encoding' => 'UTF-8', |
|
271 | - 'stylesheet' => null ]; |
|
267 | + 'version' => '1.0', |
|
268 | + 'encoding' => 'UTF-8', |
|
269 | + 'stylesheet' => null ]; |
|
272 | 270 | |
273 | 271 | if (\is_string($root)) { |
274 | 272 | // The root option can be specified as first argument |
@@ -292,9 +290,9 @@ discard block |
||
292 | 290 | |
293 | 291 | if ($opts['stylesheet']) { |
294 | 292 | $attrs = "type=\"text/xsl\" " |
295 | - . "encoding=\"{$opts['encoding']}\" " |
|
296 | - . "indent=\"yes\" " |
|
297 | - . "href=\"{$opts['stylesheet']}\""; |
|
293 | + . "encoding=\"{$opts['encoding']}\" " |
|
294 | + . "indent=\"yes\" " |
|
295 | + . "href=\"{$opts['stylesheet']}\""; |
|
298 | 296 | $stylesheet = new \DOMProcessingInstruction('xml-stylesheet', $attrs); |
299 | 297 | |
300 | 298 | $this->dom->insertBefore($stylesheet, $this->dom->documentElement); |
@@ -493,7 +491,7 @@ discard block |
||
493 | 491 | class FluidContext implements FluidInterface, \ArrayAccess, \Iterator |
494 | 492 | { |
495 | 493 | use FluidNamespaceTrait, |
496 | - FluidContextShadowTrait; // For compatibility with PHP 5.6. |
|
494 | + FluidContextShadowTrait; // For compatibility with PHP 5.6. |
|
497 | 495 | |
498 | 496 | private $dom; |
499 | 497 | private $nodes = []; |
@@ -1142,8 +1140,8 @@ discard block |
||
1142 | 1140 | const MODE_EXPLICIT = 1; |
1143 | 1141 | |
1144 | 1142 | private $config = [ self::ID => '', |
1145 | - self::URI => '', |
|
1146 | - self::MODE => self::MODE_EXPLICIT ]; |
|
1143 | + self::URI => '', |
|
1144 | + self::MODE => self::MODE_EXPLICIT ]; |
|
1147 | 1145 | |
1148 | 1146 | public function __construct($id, $uri, $mode = 1) |
1149 | 1147 | { |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $namespaces = []; |
211 | 211 | |
212 | 212 | if (\is_string($arguments[0])) { |
213 | - $args = [ $arguments[0], $arguments[1] ]; |
|
213 | + $args = [$arguments[0], $arguments[1]]; |
|
214 | 214 | |
215 | 215 | if (isset($arguments[2])) { |
216 | 216 | $args[] = $arguments[2]; |
@@ -234,8 +234,8 @@ discard block |
||
234 | 234 | class FluidXml implements FluidInterface |
235 | 235 | { |
236 | 236 | use FluidNamespaceTrait, |
237 | - FluidXmlShadowTrait, // For compatibility with PHP 5.6. |
|
238 | - FluidContextShadowTrait; // For compatibility with PHP 5.6. |
|
237 | + FluidXmlShadowTrait, // For compatibility with PHP 5.6. |
|
238 | + FluidContextShadowTrait; // For compatibility with PHP 5.6. |
|
239 | 239 | |
240 | 240 | const ROOT_NODE = 'doc'; |
241 | 241 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | |
244 | 244 | public static function load($document) |
245 | 245 | { |
246 | - if (\is_string($document) && ! \FluidXml\is_an_xml_string($document)) { |
|
246 | + if (\is_string($document) && !\FluidXml\is_an_xml_string($document)) { |
|
247 | 247 | // Removes any empty new line at the beginning, |
248 | 248 | // otherwise the first character check fails. |
249 | 249 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | $document = \file_get_contents($file); |
256 | 256 | } |
257 | 257 | |
258 | - if (! $is_file || ! $is_readable || ! $document) { |
|
258 | + if (!$is_file || !$is_readable || !$document) { |
|
259 | 259 | throw new \Exception("File '$file' not accessible."); |
260 | 260 | } |
261 | 261 | } |
@@ -265,10 +265,10 @@ discard block |
||
265 | 265 | |
266 | 266 | public function __construct($root = null, $options = []) |
267 | 267 | { |
268 | - $defaults = [ 'root' => self::ROOT_NODE, |
|
268 | + $defaults = ['root' => self::ROOT_NODE, |
|
269 | 269 | 'version' => '1.0', |
270 | 270 | 'encoding' => 'UTF-8', |
271 | - 'stylesheet' => null ]; |
|
271 | + 'stylesheet' => null]; |
|
272 | 272 | |
273 | 273 | if (\is_string($root)) { |
274 | 274 | // The root option can be specified as first argument |
@@ -462,14 +462,14 @@ discard block |
||
462 | 462 | |
463 | 463 | protected function newContext($context = null) |
464 | 464 | { |
465 | - if (! $context) { |
|
465 | + if (!$context) { |
|
466 | 466 | $context = $this->dom->documentElement; |
467 | 467 | } |
468 | 468 | |
469 | 469 | // If the user has requested ['root' => null] at construction time |
470 | 470 | // the 'documentElement' property is null because we have not created |
471 | 471 | // a root node yet. |
472 | - if (! $context) { |
|
472 | + if (!$context) { |
|
473 | 473 | // Whether there is not a root node, the DOMDocument is |
474 | 474 | // promoted as root node. |
475 | 475 | $context = $this->dom; |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | class FluidContext implements FluidInterface, \ArrayAccess, \Iterator |
494 | 494 | { |
495 | 495 | use FluidNamespaceTrait, |
496 | - FluidContextShadowTrait; // For compatibility with PHP 5.6. |
|
496 | + FluidContextShadowTrait; // For compatibility with PHP 5.6. |
|
497 | 497 | |
498 | 498 | private $dom; |
499 | 499 | private $nodes = []; |
@@ -501,8 +501,8 @@ discard block |
||
501 | 501 | |
502 | 502 | public function __construct($context, array $namespaces = []) |
503 | 503 | { |
504 | - if (! \is_array($context)) { |
|
505 | - $context = [ $context ]; |
|
504 | + if (!\is_array($context)) { |
|
505 | + $context = [$context]; |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | foreach ($context as $n) { |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | } |
524 | 524 | } |
525 | 525 | |
526 | - if (! empty($namespaces)) { |
|
526 | + if (!empty($namespaces)) { |
|
527 | 527 | $this->namespace(...\array_values($namespaces)); |
528 | 528 | } |
529 | 529 | } |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | } |
653 | 653 | } |
654 | 654 | |
655 | - if (! $found) { |
|
655 | + if (!$found) { |
|
656 | 656 | $unique_results[] = $r; |
657 | 657 | } |
658 | 658 | } |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | // the user has passed two arguments: |
755 | 755 | // 1. is the attribute name |
756 | 756 | // 2. is the attribute value |
757 | - if (! \is_array($arguments[0])) { |
|
757 | + if (!\is_array($arguments[0])) { |
|
758 | 758 | $attrs = [$arguments[0] => $arguments[1]]; |
759 | 759 | } |
760 | 760 | |
@@ -938,11 +938,11 @@ discard block |
||
938 | 938 | |
939 | 939 | return []; |
940 | 940 | } else { |
941 | - return [ $fn($parent, $this->createElement($k, $v)) ]; |
|
941 | + return [$fn($parent, $this->createElement($k, $v))]; |
|
942 | 942 | } |
943 | 943 | } |
944 | 944 | |
945 | - $v_isnt_string = ! $v_is_string; |
|
945 | + $v_isnt_string = !$v_is_string; |
|
946 | 946 | |
947 | 947 | if ($k_is_string && $v_isnt_string) { |
948 | 948 | // The user has passed one of these two cases: |
@@ -955,7 +955,7 @@ discard block |
||
955 | 955 | // they are supplied, so 'appendChild' is the perfect operation. |
956 | 956 | $this->newContext($el)->appendChild($v, ...$optionals); |
957 | 957 | |
958 | - return [ $el ]; |
|
958 | + return [$el]; |
|
959 | 959 | } |
960 | 960 | |
961 | 961 | $k_is_int = \is_int($k); |
@@ -977,13 +977,13 @@ discard block |
||
977 | 977 | } |
978 | 978 | |
979 | 979 | $v_is_xml = $v_is_string && is_an_xml_string($v); |
980 | - $v_isnt_xml = ! $v_is_xml; |
|
980 | + $v_isnt_xml = !$v_is_xml; |
|
981 | 981 | |
982 | 982 | if ($k_is_int && $v_is_string && $v_isnt_xml) { |
983 | 983 | // The user has passed a node name without a node value: |
984 | 984 | // [ 'element', ... ] |
985 | 985 | |
986 | - return [ $fn($parent, $this->createElement($v)) ]; |
|
986 | + return [$fn($parent, $this->createElement($v))]; |
|
987 | 987 | } |
988 | 988 | |
989 | 989 | // The user has passed an XML document instance: |
@@ -1046,19 +1046,19 @@ discard block |
||
1046 | 1046 | $v_is_domnode = $v instanceof \DOMNode; |
1047 | 1047 | |
1048 | 1048 | if ($k_is_int && $v_is_domnode) { |
1049 | - return $attach_nodes([ $v ]); |
|
1049 | + return $attach_nodes([$v]); |
|
1050 | 1050 | } |
1051 | 1051 | |
1052 | 1052 | $v_is_simplexml = $v instanceof \SimpleXMLElement; |
1053 | 1053 | |
1054 | 1054 | if ($k_is_int && $v_is_simplexml) { |
1055 | - return $attach_nodes([ dom_import_simplexml($v) ]); |
|
1055 | + return $attach_nodes([dom_import_simplexml($v)]); |
|
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | $v_is_fluidxml = $v instanceof FluidXml; |
1059 | 1059 | |
1060 | 1060 | if ($k_is_int && $v_is_fluidxml) { |
1061 | - return $attach_nodes([ $v->dom()->documentElement ]); |
|
1061 | + return $attach_nodes([$v->dom()->documentElement]); |
|
1062 | 1062 | } |
1063 | 1063 | |
1064 | 1064 | $v_is_fluidcontext = $v instanceof FluidContext; |
@@ -1080,8 +1080,8 @@ discard block |
||
1080 | 1080 | |
1081 | 1081 | protected function insertElement(\Closure $fn, $element, ...$optionals) |
1082 | 1082 | { |
1083 | - if (! \is_array($element)) { |
|
1084 | - $element = [ $element ]; |
|
1083 | + if (!\is_array($element)) { |
|
1084 | + $element = [$element]; |
|
1085 | 1085 | } |
1086 | 1086 | |
1087 | 1087 | $switchContext = false; |
@@ -1091,7 +1091,7 @@ discard block |
||
1091 | 1091 | if (\is_array($opt)) { |
1092 | 1092 | $attributes = $opt; |
1093 | 1093 | |
1094 | - } else if (\is_bool($opt)){ |
|
1094 | + } else if (\is_bool($opt)) { |
|
1095 | 1095 | $switchContext = $opt; |
1096 | 1096 | |
1097 | 1097 | } else if (\is_string($opt)) { |
@@ -1134,16 +1134,16 @@ discard block |
||
1134 | 1134 | |
1135 | 1135 | class FluidNamespace |
1136 | 1136 | { |
1137 | - const ID = 'id' ; |
|
1138 | - const URI = 'uri' ; |
|
1137 | + const ID = 'id'; |
|
1138 | + const URI = 'uri'; |
|
1139 | 1139 | const MODE = 'mode'; |
1140 | 1140 | |
1141 | 1141 | const MODE_IMPLICIT = 0; |
1142 | 1142 | const MODE_EXPLICIT = 1; |
1143 | 1143 | |
1144 | - private $config = [ self::ID => '', |
|
1144 | + private $config = [self::ID => '', |
|
1145 | 1145 | self::URI => '', |
1146 | - self::MODE => self::MODE_EXPLICIT ]; |
|
1146 | + self::MODE => self::MODE_EXPLICIT]; |
|
1147 | 1147 | |
1148 | 1148 | public function __construct($id, $uri, $mode = 1) |
1149 | 1149 | { |
@@ -1091,7 +1091,7 @@ |
||
1091 | 1091 | if (\is_array($opt)) { |
1092 | 1092 | $attributes = $opt; |
1093 | 1093 | |
1094 | - } else if (\is_bool($opt)){ |
|
1094 | + } else if (\is_bool($opt)) { |
|
1095 | 1095 | $switchContext = $opt; |
1096 | 1096 | |
1097 | 1097 | } else if (\is_string($opt)) { |