Completed
Push — master ( 3ca83b...f04eb9 )
by Daniele
03:06
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.
Spacing   +36 added lines, -36 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,7 +147,7 @@  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
                         // Removes any empty new line at the beginning,
152 152
                         // otherwise the first character check fails.
153 153
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
                                 $document = \file_get_contents($file);
160 160
                         }
161 161
 
162
-                        if (! $is_file || ! $is_readable || ! $document) {
162
+                        if (!$is_file || !$is_readable || !$document) {
163 163
                                 throw new \Exception("File '$file' not accessible.");
164 164
                         }
165 165
                 }
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
 
170 170
         public function __construct($root = null, $options = [])
171 171
         {
172
-                $defaults = [ 'root'       => self::ROOT_NODE,
172
+                $defaults = ['root'       => self::ROOT_NODE,
173 173
                               'version'    => '1.0',
174 174
                               'encoding'   => 'UTF-8',
175
-                              'stylesheet' => null ];
175
+                              'stylesheet' => null];
176 176
 
177 177
                 if (\is_string($root)) {
178 178
                         // The root option can be specified as first argument
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
 
198 198
                 $this->handler = new FluidInsertionHandler($doc);
199 199
 
200
-                if (! empty($opts['root'])) {
200
+                if (!empty($opts['root'])) {
201 201
                         $this->appendSibling($opts['root']);
202 202
                 }
203 203
 
204
-                if (! empty($opts['stylesheet'])) {
204
+                if (!empty($opts['stylesheet'])) {
205 205
                         $attrs = 'type="text/xsl" '
206 206
                                . "encoding=\"{$opts['encoding']}\" "
207 207
                                . 'indent="yes" '
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
                 $namespaces = [];
240 240
 
241 241
                 if (\is_string($arguments[0])) {
242
-                        $args = [ $arguments[0], $arguments[1] ];
242
+                        $args = [$arguments[0], $arguments[1]];
243 243
 
244 244
                         if (isset($arguments[2])) {
245 245
                                 $args[] = $arguments[2];
@@ -446,16 +446,16 @@  discard block
 block discarded – undo
446 446
 
447 447
 class FluidNamespace
448 448
 {
449
-        const ID   = 'id'  ;
450
-        const URI  = 'uri' ;
449
+        const ID   = 'id';
450
+        const URI  = 'uri';
451 451
         const MODE = 'mode';
452 452
 
453 453
         const MODE_IMPLICIT = 0;
454 454
         const MODE_EXPLICIT = 1;
455 455
 
456
-        private $config = [ self::ID   => '',
456
+        private $config = [self::ID   => '',
457 457
                             self::URI  => '',
458
-                            self::MODE => self::MODE_EXPLICIT ];
458
+                            self::MODE => self::MODE_EXPLICIT];
459 459
 
460 460
         public function __construct($id, $uri, $mode = 1)
461 461
         {
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
         {
494 494
                 $id = $this->id();
495 495
 
496
-                if (! empty($id)) {
496
+                if (!empty($id)) {
497 497
                         $id .= ':';
498 498
                 }
499 499
 
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
         {
682 682
                 $this->document   = $document;
683 683
                 $this->dom        = $document->dom;
684
-                $this->namespaces =& $document->namespaces;
684
+                $this->namespaces = & $document->namespaces;
685 685
         }
686 686
 
687 687
         public function insertElement(&$nodes, $element, &$optionals, $fn, $orig_context)
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
                 // offers to the user and is the same of:
705 705
                 // 1. appending a child switching the context
706 706
                 // 2. setting the attributes over the new context.
707
-                if (! empty($attributes)) {
707
+                if (!empty($attributes)) {
708 708
                         $new_context->setAttribute($attributes);
709 709
                 }
710 710
 
@@ -722,8 +722,8 @@  discard block
 block discarded – undo
722 722
 
723 723
         protected function handleOptionals($element, &$optionals)
724 724
         {
725
-                if (! \is_array($element)) {
726
-                        $element = [ $element ];
725
+                if (!\is_array($element)) {
726
+                        $element = [$element];
727 727
                 }
728 728
 
729 729
                 $switch_context = false;
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
                         }
747 747
                 }
748 748
 
749
-                return [ $element, $attributes, $switch_context ];
749
+                return [$element, $attributes, $switch_context];
750 750
         }
751 751
 
752 752
 
@@ -767,9 +767,9 @@  discard block
 block discarded – undo
767 767
                 $v_is_string    = \is_string($v);
768 768
                 $v_is_xml       = $v_is_string && is_an_xml_string($v);
769 769
                 $k_is_special   = $k_is_string && $k[0] === '@';
770
-                $k_isnt_special = ! $k_is_special;
771
-                $v_isnt_string  = ! $v_is_string;
772
-                $v_isnt_xml     = ! $v_is_xml;
770
+                $k_isnt_special = !$k_is_special;
771
+                $v_isnt_string  = !$v_is_string;
772
+                $v_isnt_xml     = !$v_is_xml;
773 773
                 ///////////////////////////////////////////////////////
774 774
 
775 775
                 if ($k_is_string && $k_isnt_special && $v_is_string && $v_isnt_xml) {
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
                 }
790 790
 
791 791
                 /////////////////////////////////////////////////////
792
-                $k_is_special_a = $k_is_special && ! $k_is_special_c;
792
+                $k_is_special_a = $k_is_special && !$k_is_special_c;
793 793
                 /////////////////////////////////////////////////////
794 794
 
795 795
                 if ($k_is_special_a && $v_is_string) {
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
                 $v_is_domnode = $v instanceof \DOMNode;
842 842
                 ///////////////////////////////////////
843 843
 
844
-                if ($k_is_integer && ! $v_is_domdoc && $v_is_domnode) {
844
+                if ($k_is_integer && !$v_is_domdoc && $v_is_domnode) {
845 845
                         return $this->insertIntegerDomnode($parent, $k, $v, $fn, $optionals);
846 846
                 }
847 847
 
@@ -909,8 +909,8 @@  discard block
 block discarded – undo
909 909
 
910 910
         protected function attachNodes($parent, $nodes, $fn)
911 911
         {
912
-                if (! \is_array($nodes) && ! $nodes instanceof \Traversable) {
913
-                        $nodes = [ $nodes ];
912
+                if (!\is_array($nodes) && !$nodes instanceof \Traversable) {
913
+                        $nodes = [$nodes];
914 914
                 }
915 915
 
916 916
                 $context = [];
@@ -959,7 +959,7 @@  discard block
 block discarded – undo
959 959
                 $el = $this->createElement($k, $v);
960 960
                 $el = $fn($parent, $el);
961 961
 
962
-                return [ $el ];
962
+                return [$el];
963 963
         }
964 964
 
965 965
         protected function insertStringMixed($parent, $k, $v, $fn, &$optionals)
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
                 // they are supplied, so 'appendChild' is the perfect operation.
976 976
                 $this->newContext($el)->appendChild($v, ...$optionals);
977 977
 
978
-                return [ $el ];
978
+                return [$el];
979 979
         }
980 980
 
981 981
         protected function insertIntegerArray($parent, $k, $v, $fn, &$optionals)
@@ -1002,7 +1002,7 @@  discard block
 block discarded – undo
1002 1002
                 $el = $this->createElement($v);
1003 1003
                 $el = $fn($parent, $el);
1004 1004
 
1005
-                return [ $el ];
1005
+                return [$el];
1006 1006
         }
1007 1007
 
1008 1008
         protected function insertIntegerXml($parent, $k, $v, $fn)
@@ -1074,8 +1074,8 @@  discard block
 block discarded – undo
1074 1074
 class FluidContext implements FluidInterface, \ArrayAccess, \Iterator
1075 1075
 {
1076 1076
         use NewableTrait,
1077
-            ReservedCallTrait,          // For compatibility with PHP 5.6.
1078
-            ReservedCallStaticTrait;    // For compatibility with PHP 5.6.
1077
+            ReservedCallTrait, // For compatibility with PHP 5.6.
1078
+            ReservedCallStaticTrait; // For compatibility with PHP 5.6.
1079 1079
 
1080 1080
         private $document;
1081 1081
         private $handler;
@@ -1087,14 +1087,14 @@  discard block
 block discarded – undo
1087 1087
                 $this->document = $document;
1088 1088
                 $this->handler  = $handler;
1089 1089
 
1090
-                if (! \is_array($context) && ! $context instanceof \Traversable) {
1090
+                if (!\is_array($context) && !$context instanceof \Traversable) {
1091 1091
                         // DOMDocument, DOMElement and DOMNode are not iterable.
1092 1092
                         // DOMNodeList and FluidContext are iterable.
1093
-                        $context = [ $context ];
1093
+                        $context = [$context];
1094 1094
                 }
1095 1095
 
1096 1096
                 foreach ($context as $n) {
1097
-                        if (! $n instanceof \DOMNode) {
1097
+                        if (!$n instanceof \DOMNode) {
1098 1098
                                 throw new \Exception('Node type not recognized.');
1099 1099
                         }
1100 1100
 
@@ -1328,7 +1328,7 @@  discard block
 block discarded – undo
1328 1328
                 // the user has passed two arguments:
1329 1329
                 // 1. is the attribute name
1330 1330
                 // 2. is the attribute value
1331
-                if (! \is_array($arguments[0])) {
1331
+                if (!\is_array($arguments[0])) {
1332 1332
                         $attrs = [$arguments[0] => $arguments[1]];
1333 1333
                 }
1334 1334
 
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
                                 }
1464 1464
                         }
1465 1465
 
1466
-                        if (! $found) {
1466
+                        if (!$found) {
1467 1467
                                 $set[] = $r;
1468 1468
                         }
1469 1469
                 }
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.