Passed
Push — master ( 8507f0...24256b )
by Henri
01:40
created
src/CheckWhere.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -4,18 +4,18 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 
7
-trait CheckWhere{
7
+trait CheckWhere {
8 8
         
9 9
     protected function checkWhereParam($data)
10 10
     {
11
-        if(count($data) === 0){
11
+        if (count($data) === 0) {
12 12
             throw new Exception('It is necessary to define a condition to be tested.');
13 13
         }
14 14
     }
15 15
 
16 16
     protected function checkWhereParams($params)
17 17
     {
18
-        if(count($params) === 0){
18
+        if (count($params) === 0) {
19 19
             throw new Exception('The route in question has no parameters to be tested.');
20 20
         }
21 21
     }
@@ -24,24 +24,24 @@  discard block
 block discarded – undo
24 24
     {
25 25
         $pass = true;
26 26
 
27
-        if(!is_array($route['where'])){
27
+        if (!is_array($route['where'])) {
28 28
             return $pass;
29 29
         }
30 30
 
31
-        $routeURI = explode('/',$route['url']);
31
+        $routeURI = explode('/', $route['url']);
32 32
         $params = [];
33
-        foreach($routeURI as $p => $part){
34
-            if(!$this->isWhered($part,$request[$p])){
33
+        foreach ($routeURI as $p => $part) {
34
+            if (!$this->isWhered($part, $request[$p])) {
35 35
                 continue;
36 36
             }
37 37
                 
38
-            $param = substr(str_replace('?','',$part),1,-1);
38
+            $param = substr(str_replace('?', '', $part), 1, -1);
39 39
 
40
-            if(array_key_exists($param,$route['where'])){
40
+            if (array_key_exists($param, $route['where'])) {
41 41
                     
42 42
                 $params[$param] = $route['where'][$param];
43 43
 
44
-                if(!preg_match("/^{$params[$param]}$/",$request[$p])){
44
+                if (!preg_match("/^{$params[$param]}$/", $request[$p])) {
45 45
                     $pass = false;
46 46
                 }
47 47
             }
@@ -52,17 +52,17 @@  discard block
 block discarded – undo
52 52
 
53 53
     private function isWhered(string $part, string $value): bool
54 54
     {
55
-        return $this->isParameter($part) && !$this->checkParameterOptional($part,$value);
55
+        return $this->isParameter($part) && !$this->checkParameterOptional($part, $value);
56 56
     }
57 57
 
58 58
     private function checkParameterOptional(string $part, string $value): bool
59 59
     {
60
-        return substr($part,0,2) === '{?' && empty($value);
60
+        return substr($part, 0, 2) === '{?' && empty($value);
61 61
     }
62 62
 
63 63
     protected function isParameter(string $part): bool
64 64
     {
65
-        return (substr($part,0,1) === '{' && substr($part,-1) === '}');
65
+        return (substr($part, 0, 1) === '{' && substr($part, -1) === '}');
66 66
     }
67 67
 
68 68
     protected function callWhereAdd($data)
@@ -72,16 +72,16 @@  discard block
 block discarded – undo
72 72
         $data = (count($data) > 1) ? [$data[0] => $data[1]] : $data[0];
73 73
         
74 74
         $route = end($this->routers);
75
-        $routeURI = explode('/',$route['url']);
75
+        $routeURI = explode('/', $route['url']);
76 76
         $params = [];
77
-        foreach($routeURI as $part){
78
-            if(!$this->isParameter($part)){
77
+        foreach ($routeURI as $part) {
78
+            if (!$this->isParameter($part)) {
79 79
                 continue;
80 80
             }
81 81
             
82
-            $param = substr(str_replace('?','',$part),1,-1);
82
+            $param = substr(str_replace('?', '', $part), 1, -1);
83 83
 
84
-            if(array_key_exists($param,$data)){
84
+            if (array_key_exists($param, $data)) {
85 85
                 $params[$param] = $data[$param];
86 86
             }
87 87
                 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 
90 90
         $this->checkWhereParams($params);
91 91
 
92
-        $route['where'] = (is_array($route['where'])) ? array_merge($route['where'],$params) : $params;
92
+        $route['where'] = (is_array($route['where'])) ? array_merge($route['where'], $params) : $params;
93 93
 
94 94
         $this->routers[count($this->routers)-1] = $route;
95 95
     }
Please login to merge, or discard this patch.