Passed
Push — master ( de7fea...aefa78 )
by Akpé Aurelle Emmanuel Moïse
01:50
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   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  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.'namedArgsHelper.php';
5
-require ($dir=dirname(__DIR__)).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'namedArgs.php';
4
+require ($dir = dirname(__DIR__)).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'namedArgsHelper.php';
5
+require ($dir = dirname(__DIR__)).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'namedArgs.php';
6 6
 require $dir.DIRECTORY_SEPARATOR.'Args.php';
7 7
 use EZAMA\NamedArgs;
8 8
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         $this->assertEquals($matches0, $matches1);
27 27
         
28 28
         $this->assertTrue(
29
-            (bool)NamedArgs::preg_match(
29
+            (bool) NamedArgs::preg_match(
30 30
                 [
31 31
                             'subpatterns'=>&$match,
32 32
                             '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/namedArgsHelper.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
         {
8 8
             foreach ($arr1 as $k=>$v) {
9 9
                 if (array_key_exists($k, $arr2)) {
10
-                    $arr1[$k]=&$arr2[$k];
10
+                    $arr1[$k] = &$arr2[$k];
11 11
                 }
12 12
             }
13 13
         }
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
             if (!\is_array($OneDarray)) {
18 18
                 return '';
19 19
             }
20
-            if (\count($OneDarray)>1) {
21
-                $end=array_pop($OneDarray);
20
+            if (\count($OneDarray) > 1) {
21
+                $end = array_pop($OneDarray);
22 22
                 return \join(',', $OneDarray)." and $end ";
23 23
             } else {
24 24
                 return array_pop($OneDarray);
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
         
28 28
         protected static function throwError($error)
29 29
         {
30
-            $error=(string)($error);
30
+            $error = (string) ($error);
31 31
             if (\version_compare(\PHP_VERSION, '7.0.0') < 0) {
32 32
                 \trigger_error($error, \E_USER_ERROR);
33 33
             } else {
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
                 return \false;
42 42
             }
43 43
             foreach ($array as $k=>$v) {
44
-                if (!\preg_match('#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$#', (string)$k)) {
44
+                if (!\preg_match('#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$#', (string) $k)) {
45 45
                     return \false;
46 46
                 }
47 47
             }
Please login to merge, or discard this patch.
src/namedArgs.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -3,41 +3,41 @@  discard block
 block discarded – undo
3 3
 
4 4
     class namedArgs extends namedArgsHelper
5 5
     {
6
-        protected $parameters=array();
6
+        protected $parameters = array();
7 7
         
8 8
         public function __construct($mandatory)
9 9
         {
10 10
             if (!\is_array($mandatory)) {
11 11
                 throw new \InvalidArgumentException(\sprintf('parameter type must be array, %s given', \gettype($mandatory)));
12 12
             }
13
-            $this->parameters=$mandatory;
13
+            $this->parameters = $mandatory;
14 14
         }
15 15
         
16 16
         protected static function &ProcessParams(&$argument, $required, $default)
17 17
         {
18
-            $missing=array();
18
+            $missing = array();
19 19
             if (!\is_array($argument)) {
20 20
                 return \false;
21 21
             }
22
-            $argument=array_intersect_key($argument, $default);//keep only predefined names
22
+            $argument = array_intersect_key($argument, $default); //keep only predefined names
23 23
             //check for missing required parameters
24 24
             foreach ($required as $k=>$v) {
25 25
                 if (!array_key_exists($v, $argument)) {
26
-                    $missing[]=$v;
26
+                    $missing[] = $v;
27 27
                 }
28 28
             }
29 29
 
30 30
             if (!empty($missing)) {
31
-                $function=\debug_backtrace();
32
-                $function=\end($function);
33
-                $function=$function['function'];
34
-                $cm=\count($missing);
35
-                $error=\call_user_func_array('sprintf', array('Function  %s\'s  Required '.($cm>1?'parameters %s are':'parameter %s is').' missing',$function,NamedArgs::format($missing)));
31
+                $function = \debug_backtrace();
32
+                $function = \end($function);
33
+                $function = $function['function'];
34
+                $cm = \count($missing);
35
+                $error = \call_user_func_array('sprintf', array('Function  %s\'s  Required '.($cm > 1 ? 'parameters %s are' : 'parameter %s is').' missing', $function, NamedArgs::format($missing)));
36 36
                 self::throwError($error);
37 37
             }
38 38
             
39 39
             
40
-            self::merge($default, $argument);//assign given values to parameters while keeping references
40
+            self::merge($default, $argument); //assign given values to parameters while keeping references
41 41
             return $default;
42 42
         }
43 43
         
@@ -46,19 +46,19 @@  discard block
 block discarded – undo
46 46
             if (self::is_valid_associative($this->parameters)) {
47 47
                 return self::ProcessParams($this->parameters, $required, $default);
48 48
             } else {
49
-                $cp=\count($this->parameters);
50
-                if ($cp>=\count($required)) {
49
+                $cp = \count($this->parameters);
50
+                if ($cp >= \count($required)) {
51 51
                     foreach (array_keys($default) as $k=>$v) {
52
-                        if ($k===$cp) {
52
+                        if ($k === $cp) {
53 53
                             break;
54 54
                         }
55
-                        $default[$v]=&$this->parameters[$k];
55
+                        $default[$v] = &$this->parameters[$k];
56 56
                     }
57 57
                     return self::ProcessParams($default, $required, $default);
58 58
                 } else {
59
-                    $function=\debug_backtrace();
60
-                    $function=\end($function);
61
-                    $function=$function['function'];
59
+                    $function = \debug_backtrace();
60
+                    $function = \end($function);
61
+                    $function = $function['function'];
62 62
 
63 63
                     self::throwError(\sprintf('Function  %s : Two few parameters supplied', $function));
64 64
                 }
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
         public static function __callStatic($name, $mandatory)
71 71
         {
72 72
             if (empty($mandatory)) {
73
-                $mandatory[0]=[];
73
+                $mandatory[0] = [];
74 74
             }
75 75
             
76 76
             if ($mandatory[0] instanceof NamedArgs) {
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         
85 85
         protected static function func($func, NamedArgs $mandatory)
86 86
         {
87
-            $args=&$mandatory->parameters;
87
+            $args = &$mandatory->parameters;
88 88
             return self::processParamsAndArgs($func, $args);
89 89
         }
90 90
         
@@ -92,10 +92,10 @@  discard block
 block discarded – undo
92 92
         
93 93
         protected static function getValues(&$func, &$params, $paramsArgs, &$args, $associative)
94 94
         {
95
-            foreach ((array)$params as $k=> $param) {
96
-                $key=$associative?$param->name:$k;
95
+            foreach ((array) $params as $k=> $param) {
96
+                $key = $associative ? $param->name : $k;
97 97
                 if (array_key_exists($key, $args)) {
98
-                    $paramsArgs[]=&$args[$key];
98
+                    $paramsArgs[] = &$args[$key];
99 99
                 } else {
100 100
                     self::elseifGetValues($func, $param, $paramsArgs);
101 101
                 }
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
         
113 113
         protected static function getParamDefaultValue(\reflectionParameter $param)
114 114
         {
115
-            return $param->getDefaultValueConstantName()?\constant($param->getDefaultValueConstantName()):$param->getDefaultValue();
115
+            return $param->getDefaultValueConstantName() ?\constant($param->getDefaultValueConstantName()) : $param->getDefaultValue();
116 116
         }
117 117
         
118 118
         protected static function canGetParamDefaultValue(\reflectionFunction $func, \reflectionParameter $param)
119 119
         {
120
-            return !$func->isInternal()&&($param->isDefaultValueAvailable()||$param->isDefaultValueConstant());
120
+            return !$func->isInternal() && ($param->isDefaultValueAvailable() || $param->isDefaultValueConstant());
121 121
         }
122 122
         
123 123
         
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
             if (self::canGetParamDefaultValue($func, $param)) {
127 127
                 $paramsArgs[] = self::getParamDefaultValue($param);
128 128
             } elseif ($param->allowsNull()) {
129
-                $paramsArgs[]=null;
129
+                $paramsArgs[] = null;
130 130
             } else {
131
-                self::handleOptional(!$param->isOptional(), (string)$func->name, (string)$param->name);
131
+                self::handleOptional(!$param->isOptional(), (string) $func->name, (string) $param->name);
132 132
             }
133 133
         }
134 134
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         {
137 137
             self::getReflection($func);
138 138
             $paramsArgs = array();
139
-            $params =$func->getParameters();
139
+            $params = $func->getParameters();
140 140
             return $func->invokeArgs(self::getValues($func, $params, $paramsArgs, $args, self::is_valid_associative($args)));
141 141
         }
142 142
     }
Please login to merge, or discard this patch.