Passed
Push — main ( b5303f...532590 )
by Sammy
01:25
created
Router/hopper.class.php 1 patch
Braces   +41 added lines, -29 removed lines patch added patch discarded remove patch
@@ -17,8 +17,9 @@  discard block
 block discarded – undo
17 17
   //----------------------------------------------------------- INITIALISATION
18 18
   public function __construct($settings)
19 19
   {
20
-    if(!isset($settings['route_home']))
21
-      throw new RouterException('ROUTE_HOME_UNDEFINED');
20
+    if(!isset($settings['route_home'])) {
21
+          throw new RouterException('ROUTE_HOME_UNDEFINED');
22
+    }
22 23
 
23 24
     parent::__construct();
24 25
 
@@ -44,13 +45,15 @@  discard block
 block discarded – undo
44 45
   {
45 46
     $this->match = parent::match($requestUrl, $requestMethod);
46 47
 
47
-    if($this->match === false)
48
-      throw new RouterException('ROUTE_MATCH_FALSE');
48
+    if($this->match === false) {
49
+          throw new RouterException('ROUTE_MATCH_FALSE');
50
+    }
49 51
 
50 52
     $res = explode('::', self::target());
51 53
 
52
-    if($res === false || !isset($res[1]) || isset($ret[2]))
53
-      throw new RouterException('INVALID_TARGET');
54
+    if($res === false || !isset($res[1]) || isset($ret[2])) {
55
+          throw new RouterException('INVALID_TARGET');
56
+    }
54 57
 
55 58
     // if($this->match['name'] === 'akadok_controller_method')
56 59
     //   $res = [ucfirst(self::params('controller')).'Controller', ucfirst(self::params('method'))];
@@ -60,12 +63,14 @@  discard block
 block discarded – undo
60 63
     $target_method = $res[1];
61 64
     $found = false;
62 65
 
63
-    foreach($this->controller_namespaces as $controller_ns)
64
-      if($found = class_exists($controller_class_name = "$controller_ns$target_controller"))
66
+    foreach($this->controller_namespaces as $controller_ns) {
67
+          if($found = class_exists($controller_class_name = "$controller_ns$target_controller"))
65 68
         break;
69
+    }
66 70
 
67
-    if($found === false)
68
-      throw new RouterException('INVALID_CONTROLLER_NAME');
71
+    if($found === false) {
72
+          throw new RouterException('INVALID_CONTROLLER_NAME');
73
+    }
69 74
 
70 75
     $this->match['target_controller'] = $controller_class_name;
71 76
     $this->match['target_method'] = $target_method;
@@ -87,16 +92,19 @@  discard block
 block discarded – undo
87 92
   {
88 93
 
89 94
     // $key is null, returns $dat_ass or empty array
90
-    if(is_null($key))
91
-      return $dat_ass ?? [];
95
+    if(is_null($key)) {
96
+          return $dat_ass ?? [];
97
+    }
92 98
 
93 99
     // $dat_ass[$key] not set, returns null
94
-    if(!isset($dat_ass[$key]))
95
-      return null;
100
+    if(!isset($dat_ass[$key])) {
101
+          return null;
102
+    }
96 103
 
97 104
     // $dat_ass[$key] is a string, returns decoded value
98
-    if(is_string($dat_ass[$key]))
99
-      return urldecode($dat_ass[$key]);
105
+    if(is_string($dat_ass[$key])) {
106
+          return urldecode($dat_ass[$key]);
107
+    }
100 108
 
101 109
     // $dat_ass[$key] is not a string, return match[$key]
102 110
     return $dat_ass[$key];
@@ -146,7 +154,7 @@  discard block
 block discarded – undo
146 154
   {
147 155
     try{
148 156
       $url = $this->generate($route, $route_params);
149
-    }catch(\Exception $e){
157
+    } catch(\Exception $e){
150 158
       $url = $this->prehop(self::ROUTE_HOME_NAME);
151 159
     }
152 160
 
@@ -169,12 +177,13 @@  discard block
 block discarded – undo
169 177
   {
170 178
     $url = null;
171 179
 
172
-    if(is_null($route))
173
-      $url = $this->prehop(self::ROUTE_HOME_NAME, $route_params);
174
-    elseif(is_string($route) && $this->route_exists($route))
175
-      $url = $this->prehop($route, $route_params);
176
-    else
177
-      $url = $route;
180
+    if(is_null($route)) {
181
+          $url = $this->prehop(self::ROUTE_HOME_NAME, $route_params);
182
+    } elseif(is_string($route) && $this->route_exists($route)) {
183
+          $url = $this->prehop($route, $route_params);
184
+    } else {
185
+          $url = $route;
186
+    }
178 187
 
179 188
     $this->hop_url($url);
180 189
   }
@@ -182,8 +191,9 @@  discard block
 block discarded – undo
182 191
   // hops back to previous page (referer()), or home if no referer
183 192
   public function hop_back()
184 193
   {
185
-    if(!is_null($back = $this->referer()))
186
-      $this->hop_url($back);
194
+    if(!is_null($back = $this->referer())) {
195
+          $this->hop_url($back);
196
+    }
187 197
 
188 198
     $this->hop();
189 199
   }
@@ -200,16 +210,18 @@  discard block
 block discarded – undo
200 210
   // returns null if same as current URL (prevents endless redirection loop)
201 211
   public function referer()
202 212
   {
203
-    if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host() .$_SERVER['REQUEST_URI'])
204
-      return $_SERVER['HTTP_REFERER'];
213
+    if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host() .$_SERVER['REQUEST_URI']) {
214
+          return $_SERVER['HTTP_REFERER'];
215
+    }
205 216
 
206 217
     return null;
207 218
   }
208 219
 
209 220
   public function send_file($file_path)
210 221
   {
211
-    if(!file_exists($file_path))
212
-      throw new RouterException('SENDING_NON_EXISTING_FILE');
222
+    if(!file_exists($file_path)) {
223
+          throw new RouterException('SENDING_NON_EXISTING_FILE');
224
+    }
213 225
 
214 226
     $file_name = basename($file_path);
215 227
 
Please login to merge, or discard this patch.