Completed
Push — master ( 5213ea...b697ca )
by Daniele
04:53
created
source/FluidXml.php 3 patches
Indentation   +12 added lines, -14 removed lines patch added patch discarded remove patch
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 = [];
Please login to merge, or discard this patch.
Doc Comments   +68 added lines, -5 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,
@@ -543,7 +546,7 @@  discard block
 block discarded – undo
543 546
          * $xml->query("/doc")->query("book[@id='123']");
544 547
          * ```
545 548
          *
546
-         * @param string $xpath The XPath to execute.
549
+         * @param string[] $xpath The XPath to execute.
547 550
          *
548 551
          * @return FluidContext The context associated to the DOMNodeList.
549 552
          */
@@ -565,9 +568,6 @@  discard block
 block discarded – undo
565 568
          * ```
566 569
          *
567 570
          * @param string|array $child The child/children to add.
568
-         * @param string $value The child text content.
569
-         * @param bool $switchContext Whether to return the current context
570
-         *                            or the context of the created node.
571 571
          *
572 572
          * @return FluidContext The context associated to the DOMNodeList.
573 573
          */
@@ -582,6 +582,10 @@  discard block
 block discarded – undo
582 582
         public function remove(...$xpath);
583 583
         public function xml($strip = false);
584 584
         // Aliases:
585
+
586
+        /**
587
+         * @return FluidContext
588
+         */
585 589
         public function add($child, ...$optionals);
586 590
         public function prepend($sibling, ...$optionals);
587 591
         public function insertSiblingBefore($sibling, ...$optionals);
@@ -645,6 +649,9 @@  discard block
 block discarded – undo
645 649
         private $context;
646 650
         private $times;
647 651
 
652
+        /**
653
+         * @param FluidContext $context
654
+         */
648 655
         public function __construct($document, $handler, $context, $times)
649 656
         {
650 657
                 $this->document = $document;
@@ -677,6 +684,9 @@  discard block
 block discarded – undo
677 684
         private $dom;
678 685
         private $namespaces;
679 686
 
687
+        /**
688
+         * @param FluidDocument $document
689
+         */
680 690
         public function __construct($document)
681 691
         {
682 692
                 $this->document   = $document;
@@ -923,6 +933,10 @@  discard block
 block discarded – undo
923 933
                 return $context;
924 934
         }
925 935
 
936
+        /**
937
+         * @param string $k
938
+         * @param string $v
939
+         */
926 940
         protected function insertSpecialContent($parent, $k, $v)
927 941
         {
928 942
                 // The user has passed an element text content:
@@ -940,6 +954,10 @@  discard block
 block discarded – undo
940 954
                 return [];
941 955
         }
942 956
 
957
+        /**
958
+         * @param string $k
959
+         * @param string $v
960
+         */
943 961
         protected function insertSpecialAttribute($parent, $k, $v)
944 962
         {
945 963
                 // The user has passed an attribute name and an attribute value:
@@ -951,6 +969,10 @@  discard block
 block discarded – undo
951 969
                 return [];
952 970
         }
953 971
 
972
+        /**
973
+         * @param string $k
974
+         * @param string $v
975
+         */
954 976
         protected function insertStringString($parent, $k, $v, $fn)
955 977
         {
956 978
                 // The user has passed an element name and an element value:
@@ -962,6 +984,9 @@  discard block
 block discarded – undo
962 984
                 return [ $el ];
963 985
         }
964 986
 
987
+        /**
988
+         * @param string $k
989
+         */
965 990
         protected function insertStringMixed($parent, $k, $v, $fn, &$optionals)
966 991
         {
967 992
                 // The user has passed one of these two cases:
@@ -978,6 +1003,9 @@  discard block
 block discarded – undo
978 1003
                 return [ $el ];
979 1004
         }
980 1005
 
1006
+        /**
1007
+         * @param integer $k
1008
+         */
981 1009
         protected function insertIntegerArray($parent, $k, $v, $fn, &$optionals)
982 1010
         {
983 1011
                 // The user has passed a wrapper array:
@@ -994,6 +1022,10 @@  discard block
 block discarded – undo
994 1022
                 return $context;
995 1023
         }
996 1024
 
1025
+        /**
1026
+         * @param integer $k
1027
+         * @param string $v
1028
+         */
997 1029
         protected function insertIntegerString($parent, $k, $v, $fn)
998 1030
         {
999 1031
                 // The user has passed a node name without a node value:
@@ -1005,6 +1037,10 @@  discard block
 block discarded – undo
1005 1037
                 return [ $el ];
1006 1038
         }
1007 1039
 
1040
+        /**
1041
+         * @param integer $k
1042
+         * @param string $v
1043
+         */
1008 1044
         protected function insertIntegerXml($parent, $k, $v, $fn)
1009 1045
         {
1010 1046
                 // The user has passed an XML document instance:
@@ -1034,6 +1070,10 @@  discard block
 block discarded – undo
1034 1070
                 return $this->attachNodes($parent, $nodes, $fn);
1035 1071
         }
1036 1072
 
1073
+        /**
1074
+         * @param integer $k
1075
+         * @param \DOMDocument $v
1076
+         */
1037 1077
         protected function insertIntegerDomdocument($parent, $k, $v, $fn)
1038 1078
         {
1039 1079
                 // A DOMDocument can have multiple root nodes.
@@ -1045,26 +1085,46 @@  discard block
 block discarded – undo
1045 1085
                 // return $this->attachNodes($parent, $v->documentElement, $fn);
1046 1086
         }
1047 1087
 
1088
+        /**
1089
+         * @param integer $k
1090
+         * @param \DOMNodeList $v
1091
+         */
1048 1092
         protected function insertIntegerDomnodelist($parent, $k, $v, $fn)
1049 1093
         {
1050 1094
                 return $this->attachNodes($parent, $v, $fn);
1051 1095
         }
1052 1096
 
1097
+        /**
1098
+         * @param integer $k
1099
+         * @param \DOMNode $v
1100
+         */
1053 1101
         protected function insertIntegerDomnode($parent, $k, $v, $fn)
1054 1102
         {
1055 1103
                 return $this->attachNodes($parent, $v, $fn);
1056 1104
         }
1057 1105
 
1106
+        /**
1107
+         * @param integer $k
1108
+         * @param \SimpleXMLElement $v
1109
+         */
1058 1110
         protected function insertIntegerSimplexml($parent, $k, $v, $fn)
1059 1111
         {
1060 1112
                 return $this->attachNodes($parent, \dom_import_simplexml($v), $fn);
1061 1113
         }
1062 1114
 
1115
+        /**
1116
+         * @param integer $k
1117
+         * @param FluidXml $v
1118
+         */
1063 1119
         protected function insertIntegerFluidxml($parent, $k, $v, $fn)
1064 1120
         {
1065 1121
                 return $this->attachNodes($parent, $v->dom()->documentElement, $fn);
1066 1122
         }
1067 1123
 
1124
+        /**
1125
+         * @param integer $k
1126
+         * @param FluidContext $v
1127
+         */
1068 1128
         protected function insertIntegerFluidcontext($parent, $k, $v, $fn)
1069 1129
         {
1070 1130
                 return $this->attachNodes($parent, $v->asArray(), $fn);
@@ -1450,6 +1510,9 @@  discard block
 block discarded – undo
1450 1510
                 return $set;
1451 1511
         }
1452 1512
 
1513
+        /**
1514
+         * @param callable $fn
1515
+         */
1453 1516
         protected function callfn($fn, $args)
1454 1517
         {
1455 1518
                 if ($fn instanceof \Closure) {
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
1422 1422
                                 $found = ($r === $u) || $found;
1423 1423
                         }
1424 1424
 
1425
-                        if (! $found) {
1425
+                        if (!$found) {
1426 1426
                                 $set[] = $r;
1427 1427
                         }
1428 1428
                 }
Please login to merge, or discard this patch.