Passed
Push — master ( 62fbb4...6eecf2 )
by Akpé Aurelle Emmanuel Moïse
02:00
created
tests/NamedArgsTest.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
                         'subject'=>'gris|gros|gras|grue'
19 19
                     ]
20 20
                 )
21
-         ),
21
+            ),
22 22
             preg_match_all('#a|o|i|u|e#', 'gris|gros|gras|grue', $matches1)
23 23
         );
24 24
         
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 use PHPUnit\Framework\TestCase;
3 3
 
4
-require($dir=dirname(__DIR__)).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'NamedArgs.php';
4
+require($dir = dirname(__DIR__)).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'NamedArgs.php';
5 5
 require $dir.DIRECTORY_SEPARATOR.'Args.php';
6 6
 use EZAMA\NamedArgs;
7 7
 
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
         $this->assertEquals($matches0, $matches1);
26 26
         
27 27
         $this->assertTrue(
28
-            (bool)NamedArgs::preg_match(
28
+            (bool) NamedArgs::preg_match(
29 29
                 [
30 30
                             'subpatterns'=>&$match,
31 31
                             'pattern'=>'#a|o|i|u|e#',
Please login to merge, or discard this patch.
testNamedArgs.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -5,56 +5,56 @@
 block discarded – undo
5 5
 
6 6
 function codeWithoutRef(NamedArgs $mandatory)
7 7
 {
8
-    $required=['first','fourth'];//specify required parameters here
9
-    $default=['first'=>0,'second'=>1,'third'=>2,'fourth'=>9,'fifth'=>7];//define all parameters required and optional with their default values here
8
+    $required = ['first', 'fourth']; //specify required parameters here
9
+    $default = ['first'=>0, 'second'=>1, 'third'=>2, 'fourth'=>9, 'fifth'=>7]; //define all parameters required and optional with their default values here
10 10
     extract($mandatory->getParams($required, $default));
11 11
     unset($mandatory);
12
-    return $first+$second+$third+$fourth+$fifth;
12
+    return $first + $second + $third + $fourth + $fifth;
13 13
 }
14 14
 
15 15
 
16 16
 function codeWithRef(NamedArgs $mandatory)
17 17
 {
18
-    $required=['first'];
19
-    $default=['first'=>0,'second'=>1,'third'=>2];
20
-    extract($mandatory->getParams($required, $default), EXTR_OVERWRITE|EXTR_REFS);
18
+    $required = ['first'];
19
+    $default = ['first'=>0, 'second'=>1, 'third'=>2];
20
+    extract($mandatory->getParams($required, $default), EXTR_OVERWRITE | EXTR_REFS);
21 21
     unset($mandatory);
22
-    $first=$first+$second+$third;
22
+    $first = $first + $second + $third;
23 23
 }
24 24
 
25 25
 
26
-function test(&$tada, &$tada2, &$test=6)
26
+function test(&$tada, &$tada2, &$test = 6)
27 27
 {
28
-    $tada=1;
29
-    $tada2=2;
30
-    return  $tada+$tada2+$test;
28
+    $tada = 1;
29
+    $tada2 = 2;
30
+    return  $tada + $tada2 + $test;
31 31
 }
32 32
 
33 33
 
34 34
 echo "<pre>";
35
-var_dump(codeWithoutRef(Args(['fourth'=>9,'first'=>3,'third'=>79])));
36
-var_dump(codeWithoutRef(Args([1,2,3,0])));
35
+var_dump(codeWithoutRef(Args(['fourth'=>9, 'first'=>3, 'third'=>79])));
36
+var_dump(codeWithoutRef(Args([1, 2, 3, 0])));
37 37
 
38 38
 
39
-$first=3;
40
-codeWithRef(Args(['third'=>79,'first'=>&$first]));
39
+$first = 3;
40
+codeWithRef(Args(['third'=>79, 'first'=>&$first]));
41 41
 var_dump($first);
42
-$first2=3;
43
-codeWithRef(Args([&$first2,79]));
42
+$first2 = 3;
43
+codeWithRef(Args([&$first2, 79]));
44 44
 var_dump($first2);
45 45
 
46
-$tada=$tada2=null;
47
-var_dump(NamedArgs::test(args(['tada'=>&$tada,'tada2'=>&$tada2])), $tada, $tada2);
46
+$tada = $tada2 = null;
47
+var_dump(NamedArgs::test(args(['tada'=>&$tada, 'tada2'=>&$tada2])), $tada, $tada2);
48 48
 
49
-$tada=$tada2=null;
50
-var_dump(NamedArgs::test(args([&$tada,&$tada2])), $tada, $tada2);
49
+$tada = $tada2 = null;
50
+var_dump(NamedArgs::test(args([&$tada, &$tada2])), $tada, $tada2);
51 51
 
52 52
 
53
-NamedArgs::preg_match_all(args(['subpatterns'=>&$matches,'pattern'=>'#a|o|i|u|e#','subject'=>'gris|gros|gras|grue']));
53
+NamedArgs::preg_match_all(args(['subpatterns'=>&$matches, 'pattern'=>'#a|o|i|u|e#', 'subject'=>'gris|gros|gras|grue']));
54 54
 
55 55
 var_dump($matches);
56
-var_dump($x=NamedArgs::strtoupper(args(['str'=>'gris|gros|gras|grue'])), NamedArgs::strtolower(args(['str'=>$x])));//just for  funny example.
57
-NamedArgs::preg_match(['subpatterns'=>&$match,'pattern'=>'#a|o|i|u|e#','subject'=>'gris|gros|gras|grue']);
56
+var_dump($x = NamedArgs::strtoupper(args(['str'=>'gris|gros|gras|grue'])), NamedArgs::strtolower(args(['str'=>$x]))); //just for  funny example.
57
+NamedArgs::preg_match(['subpatterns'=>&$match, 'pattern'=>'#a|o|i|u|e#', 'subject'=>'gris|gros|gras|grue']);
58 58
 var_dump($match);
59 59
 
60 60
 highlight_string('
Please login to merge, or discard this patch.
src/NamedArgs.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -2,21 +2,21 @@  discard block
 block discarded – undo
2 2
 namespace EZAMA{
3 3
     class NamedArgs
4 4
     {
5
-        protected $parameters=array();
5
+        protected $parameters = array();
6 6
         
7 7
         public function __construct($mandatory)
8 8
         {
9 9
             if (!\is_array($mandatory)) {
10 10
                 throw new InvalidArgumentException(\sprintf('parameter type must be array, %s given', \gettype($mandatory)));
11 11
             }
12
-            $this->parameters=$mandatory;
12
+            $this->parameters = $mandatory;
13 13
         }
14 14
         
15 15
         protected static function merge(&$arr1, &$arr2)
16 16
         {
17 17
             foreach ($arr1 as $k=>$v) {
18 18
                 if (array_key_exists($k, $arr2)) {
19
-                    $arr1[$k]=&$arr2[$k];
19
+                    $arr1[$k] = &$arr2[$k];
20 20
                 }
21 21
             }
22 22
         }
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
             if (!\is_array($OneDarray)) {
27 27
                 return '';
28 28
             }
29
-            if (\count($OneDarray)>1) {
30
-                $end=array_pop($OneDarray);
29
+            if (\count($OneDarray) > 1) {
30
+                $end = array_pop($OneDarray);
31 31
                 return \join(',', $OneDarray)." and $end ";
32 32
             } else {
33 33
                 return array_pop($OneDarray);
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
         
37 37
         protected static function throwError($error)
38 38
         {
39
-            $error=(string)($error);
39
+            $error = (string) ($error);
40 40
             if (\version_compare(\PHP_VERSION, '7.0.0') < 0) {
41 41
                 \trigger_error($error, \E_USER_ERROR);
42 42
             } else {
@@ -47,29 +47,29 @@  discard block
 block discarded – undo
47 47
         
48 48
         protected static function &ProcessParams(&$argument, $required, $default)
49 49
         {
50
-            $missing=array();
50
+            $missing = array();
51 51
             if (!\is_array($argument)) {
52 52
                 return \false;
53 53
             }
54
-            $argument=array_intersect_key($argument, $default);//keep only predefined names
54
+            $argument = array_intersect_key($argument, $default); //keep only predefined names
55 55
             //check for missing required parameters
56 56
             foreach ($required as $k=>$v) {
57 57
                 if (!array_key_exists($v, $argument)) {
58
-                    $missing[]=$v;
58
+                    $missing[] = $v;
59 59
                 }
60 60
             }
61 61
 
62 62
             if (!empty($missing)) {
63
-                $function=\debug_backtrace();
64
-                $function=\end($function);
65
-                $function=$function['function'];
66
-                $cm=\count($missing);
67
-                $error=\call_user_func_array('sprintf', array('Function  %s\'s  Required '.(($cm>1)?'parameters ':'parameter ').'%s '.(($cm>1)?'are':'is').' missing',$function,NamedArgs::format($missing)));
63
+                $function = \debug_backtrace();
64
+                $function = \end($function);
65
+                $function = $function['function'];
66
+                $cm = \count($missing);
67
+                $error = \call_user_func_array('sprintf', array('Function  %s\'s  Required '.(($cm > 1) ? 'parameters ' : 'parameter ').'%s '.(($cm > 1) ? 'are' : 'is').' missing', $function, NamedArgs::format($missing)));
68 68
                 self::throwError($error);
69 69
             }
70 70
             
71 71
             
72
-            self::merge($default, $argument);//assign given values to parameters while keeping references
72
+            self::merge($default, $argument); //assign given values to parameters while keeping references
73 73
             return $default;
74 74
         }
75 75
         
@@ -78,19 +78,19 @@  discard block
 block discarded – undo
78 78
             if (self::is_valid_associative($this->parameters)) {
79 79
                 return self::ProcessParams($this->parameters, $required, $default);
80 80
             } else {
81
-                $cp=\count($this->parameters);
82
-                if ($cp>=\count($required)) {
81
+                $cp = \count($this->parameters);
82
+                if ($cp >= \count($required)) {
83 83
                     foreach (array_keys($default) as $k=>$v) {
84
-                        if ($k===$cp) {
84
+                        if ($k === $cp) {
85 85
                             break;
86 86
                         }
87
-                        $default[$v]=&$this->parameters[$k];
87
+                        $default[$v] = &$this->parameters[$k];
88 88
                     }
89 89
                     return self::ProcessParams($default, $required, $default);
90 90
                 } else {
91
-                    $function=\debug_backtrace();
92
-                    $function=\end($function);
93
-                    $function=$function['function'];
91
+                    $function = \debug_backtrace();
92
+                    $function = \end($function);
93
+                    $function = $function['function'];
94 94
 
95 95
                     self::throwError(\sprintf('Function  %s : Two few parameters supplied', $function));
96 96
                 }
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
                 return \false;
104 104
             }
105 105
             foreach ($array as $k=>$v) {
106
-                if (!\preg_match('#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$#', (string)$k)) {
106
+                if (!\preg_match('#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$#', (string) $k)) {
107 107
                     return \false;
108 108
                 }
109 109
             }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         public static function __callStatic($name, $mandatory)
114 114
         {
115 115
             if (empty($mandatory)) {
116
-                $mandatory[0]=[];
116
+                $mandatory[0] = [];
117 117
             }
118 118
             
119 119
             if ($mandatory[0] instanceof NamedArgs) {
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         
128 128
         protected static function func($func, NamedArgs $mandatory)
129 129
         {
130
-            $args=&$mandatory->parameters;
130
+            $args = &$mandatory->parameters;
131 131
             return self::processParamsAndArgs($func, $args);
132 132
         }
133 133
         
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
         
146 146
         protected static function getValues(&$func, &$params, $paramsArgs, &$args, $associative)
147 147
         {
148
-            foreach ((array)$params as $k=> $param) {
149
-                $key=$associative?$param->name:$k;
148
+            foreach ((array) $params as $k=> $param) {
149
+                $key = $associative ? $param->name : $k;
150 150
                 if (array_key_exists($key, $args)) {
151
-                    $paramsArgs[]=&$args[$key];
151
+                    $paramsArgs[] = &$args[$key];
152 152
                 } else {
153 153
                     self::elseifGetValues($func, $param, $paramsArgs);
154 154
                 }
@@ -165,12 +165,12 @@  discard block
 block discarded – undo
165 165
         
166 166
         protected static function getParamDefaultValue(\reflectionParameter $param)
167 167
         {
168
-            return $param->getDefaultValueConstantName()?\constant($param->getDefaultValueConstantName()):$param->getDefaultValue();
168
+            return $param->getDefaultValueConstantName() ?\constant($param->getDefaultValueConstantName()) : $param->getDefaultValue();
169 169
         }
170 170
         
171 171
         protected static function canGetParamDefaultValue(\reflectionFunction $func, \reflectionParameter $param)
172 172
         {
173
-            return !$func->isInternal()&&($param->isDefaultValueAvailable()||$param->isDefaultValueConstant());
173
+            return !$func->isInternal() && ($param->isDefaultValueAvailable() || $param->isDefaultValueConstant());
174 174
         }
175 175
         
176 176
         
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
             if (self::canGetParamDefaultValue($func, $param)) {
180 180
                 $paramsArgs[] = self::getParamDefaultValue($param);
181 181
             } elseif ($param->allowsNull()) {
182
-                $paramsArgs[]=null;
182
+                $paramsArgs[] = null;
183 183
             } else {
184
-                self::handleOptional(!$param->isOptional(), (string)$func->name, (string)$param->name);
184
+                self::handleOptional(!$param->isOptional(), (string) $func->name, (string) $param->name);
185 185
             }
186 186
         }
187 187
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         {
190 190
             self::getReflection($func);
191 191
             $paramsArgs = array();
192
-            $params =$func->getParameters();
192
+            $params = $func->getParameters();
193 193
             return $func->invokeArgs(self::getValues($func, $params, $paramsArgs, $args, self::is_valid_associative($args)));
194 194
         }
195 195
     }
Please login to merge, or discard this patch.