Passed
Branch main (14e4e9)
by Sammy
06:12
created
hopper.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -188,8 +188,8 @@
 block discarded – undo
188 188
 
189 189
   public function hop_url($url)
190 190
   {
191
-  	header('Cache-Control: no-cache, must-revalidate');
192
-  	header('Expires: Mon, 01 Jan 1970 00:00:00 GMT');
191
+    header('Cache-Control: no-cache, must-revalidate');
192
+    header('Expires: Mon, 01 Jan 1970 00:00:00 GMT');
193 193
     header('Location: '.$url);
194 194
     exit();
195 195
   }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -8,14 +8,14 @@  discard block
 block discarded – undo
8 8
 
9 9
 class hopper extends \AltoRouter implements RouterInterface
10 10
 {
11
-  private $match=null;
12
-  private $file_root=null;
11
+  private $match = null;
12
+  private $file_root = null;
13 13
   private $controller_namespaces = null;
14 14
 
15 15
   //----------------------------------------------------------- INITIALISATION
16 16
   public function __construct($settings)
17 17
   {
18
-    if(!isset($settings['route_home']))
18
+    if (!isset($settings['route_home']))
19 19
       throw new RouterException('ROUTE_HOME_UNDEFINED');
20 20
 
21 21
     parent::__construct();
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
   {
43 43
     $this->match = parent::match($requestUrl, $requestMethod);
44 44
 
45
-    if($this->match === false)
45
+    if ($this->match === false)
46 46
       throw new RouterException('ROUTE_MATCH_FALSE');
47 47
 
48 48
     $res = explode('::', self::target());
49 49
 
50
-    if($res === false || !isset($res[1]) || isset($ret[2]))
50
+    if ($res === false || !isset($res[1]) || isset($ret[2]))
51 51
       throw new RouterException('INVALID_TARGET');
52 52
 
53 53
     // if($this->match['name'] === 'akadok_controller_method')
@@ -58,11 +58,11 @@  discard block
 block discarded – undo
58 58
     $target_method = $res[1];
59 59
     $found = false;
60 60
 
61
-    foreach($this->controller_namespaces as $controller_ns)
62
-      if($found = class_exists($controller_class_name = "$controller_ns$target_controller"))
61
+    foreach ($this->controller_namespaces as $controller_ns)
62
+      if ($found = class_exists($controller_class_name = "$controller_ns$target_controller"))
63 63
         break;
64 64
 
65
-    if($found === false)
65
+    if ($found === false)
66 66
       throw new RouterException('INVALID_CONTROLLER_NAME');
67 67
 
68 68
     $this->match['target_controller'] = $controller_class_name;
@@ -71,29 +71,29 @@  discard block
 block discarded – undo
71 71
     return [$controller_class_name, $target_method];
72 72
   }
73 73
 
74
-  public function params($param_name=null)
74
+  public function params($param_name = null)
75 75
   {
76 76
     return $this->extract_request($this->match['params'] ?? [], $param_name);
77 77
   }
78 78
 
79
-  public function submitted($param_name=null)
79
+  public function submitted($param_name = null)
80 80
   {
81 81
     return $this->extract_request($_POST, $param_name);
82 82
   }
83 83
 
84
-  private function extract_request($dat_ass, $key=null)
84
+  private function extract_request($dat_ass, $key = null)
85 85
   {
86 86
 
87 87
     // $key is null, returns $dat_ass or empty array
88
-    if(is_null($key))
88
+    if (is_null($key))
89 89
       return $dat_ass ?? [];
90 90
 
91 91
     // $dat_ass[$key] not set, returns null
92
-    if(!isset($dat_ass[$key]))
92
+    if (!isset($dat_ass[$key]))
93 93
       return null;
94 94
 
95 95
     // $dat_ass[$key] is a string, returns decoded value
96
-    if(is_string($dat_ass[$key]))
96
+    if (is_string($dat_ass[$key]))
97 97
       return urldecode($dat_ass[$key]);
98 98
 
99 99
     // $dat_ass[$key] is not a string, return match[$key]
@@ -140,18 +140,18 @@  discard block
 block discarded – undo
140 140
    *  - an assoc_array of url params (strongly AltoRouter-based)
141 141
    * returns: something to put in a href="", action="" or header('Location:');
142 142
    */
143
-  public function prehop($route, $route_params=[])
143
+  public function prehop($route, $route_params = [])
144 144
   {
145
-    try{
145
+    try {
146 146
       $url = $this->generate($route, $route_params);
147
-    }catch(\Exception $e){
147
+    }catch (\Exception $e) {
148 148
       $url = $this->prehop(self::ROUTE_HOME_NAME);
149 149
     }
150 150
 
151 151
     return $url;
152 152
   }
153 153
 
154
-  public function prehop_here($url=null)
154
+  public function prehop_here($url = null)
155 155
   {
156 156
     return $url ?? $_SERVER['REQUEST_URI'];
157 157
   }
@@ -163,13 +163,13 @@  discard block
 block discarded – undo
163 163
    *    - a url, go there
164 164
    * @params $route_params, assoc_data for url creation (i:id, a:format, ..)
165 165
    */
166
-  public function hop($route=null, $route_params=[])
166
+  public function hop($route = null, $route_params = [])
167 167
   {
168 168
     $url = null;
169 169
 
170
-    if(is_null($route))
170
+    if (is_null($route))
171 171
       $url = $this->prehop(self::ROUTE_HOME_NAME, $route_params);
172
-    elseif(is_string($route) && $this->route_exists($route))
172
+    elseif (is_string($route) && $this->route_exists($route))
173 173
       $url = $this->prehop($route, $route_params);
174 174
     else
175 175
       $url = $route;
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
   // hops back to previous page (referer()), or home if no referer
181 181
   public function hop_back()
182 182
   {
183
-    if(!is_null($back = $this->referer()))
183
+    if (!is_null($back = $this->referer()))
184 184
       $this->hop_url($back);
185 185
 
186 186
     $this->hop();
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
   // returns null if same as current URL (prevents endless redirection loop)
199 199
   public function referer()
200 200
   {
201
-    if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host() .$_SERVER['REQUEST_URI'])
201
+    if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host().$_SERVER['REQUEST_URI'])
202 202
       return $_SERVER['HTTP_REFERER'];
203 203
 
204 204
     return null;
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 
207 207
   public function send_file($file_path)
208 208
   {
209
-    if(!file_exists($file_path))
209
+    if (!file_exists($file_path))
210 210
       throw new RouterException('SENDING_NON_EXISTING_FILE');
211 211
 
212 212
     $file_name = basename($file_path);
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
     //Get file type and set it as Content Type
215 215
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
216 216
 
217
-    header('Content-Type: ' . finfo_file($finfo, $file_path));
217
+    header('Content-Type: '.finfo_file($finfo, $file_path));
218 218
 
219 219
     finfo_close($finfo);
220 220
 
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
     header('Pragma: public');
228 228
 
229 229
     //Define file size
230
-    header('Content-Length: ' . filesize($file_path));
230
+    header('Content-Length: '.filesize($file_path));
231 231
 
232 232
     ob_clean();
233 233
     flush();
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 
254 254
   public function web_root() : string
255 255
   {
256
-    return $this->web_host() . $this->web_base();
256
+    return $this->web_host().$this->web_base();
257 257
   }
258 258
 
259 259
   public function web_base() : string
Please login to merge, or discard this patch.
Braces   +41 added lines, -29 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
   //----------------------------------------------------------- INITIALISATION
16 16
   public function __construct($settings)
17 17
   {
18
-    if(!isset($settings['route_home']))
19
-      throw new RouterException('ROUTE_HOME_UNDEFINED');
18
+    if(!isset($settings['route_home'])) {
19
+          throw new RouterException('ROUTE_HOME_UNDEFINED');
20
+    }
20 21
 
21 22
     parent::__construct();
22 23
 
@@ -42,13 +43,15 @@  discard block
 block discarded – undo
42 43
   {
43 44
     $this->match = parent::match($requestUrl, $requestMethod);
44 45
 
45
-    if($this->match === false)
46
-      throw new RouterException('ROUTE_MATCH_FALSE');
46
+    if($this->match === false) {
47
+          throw new RouterException('ROUTE_MATCH_FALSE');
48
+    }
47 49
 
48 50
     $res = explode('::', self::target());
49 51
 
50
-    if($res === false || !isset($res[1]) || isset($ret[2]))
51
-      throw new RouterException('INVALID_TARGET');
52
+    if($res === false || !isset($res[1]) || isset($ret[2])) {
53
+          throw new RouterException('INVALID_TARGET');
54
+    }
52 55
 
53 56
     // if($this->match['name'] === 'akadok_controller_method')
54 57
     //   $res = [ucfirst(self::params('controller')).'Controller', ucfirst(self::params('method'))];
@@ -58,12 +61,14 @@  discard block
 block discarded – undo
58 61
     $target_method = $res[1];
59 62
     $found = false;
60 63
 
61
-    foreach($this->controller_namespaces as $controller_ns)
62
-      if($found = class_exists($controller_class_name = "$controller_ns$target_controller"))
64
+    foreach($this->controller_namespaces as $controller_ns) {
65
+          if($found = class_exists($controller_class_name = "$controller_ns$target_controller"))
63 66
         break;
67
+    }
64 68
 
65
-    if($found === false)
66
-      throw new RouterException('INVALID_CONTROLLER_NAME');
69
+    if($found === false) {
70
+          throw new RouterException('INVALID_CONTROLLER_NAME');
71
+    }
67 72
 
68 73
     $this->match['target_controller'] = $controller_class_name;
69 74
     $this->match['target_method'] = $target_method;
@@ -85,16 +90,19 @@  discard block
 block discarded – undo
85 90
   {
86 91
 
87 92
     // $key is null, returns $dat_ass or empty array
88
-    if(is_null($key))
89
-      return $dat_ass ?? [];
93
+    if(is_null($key)) {
94
+          return $dat_ass ?? [];
95
+    }
90 96
 
91 97
     // $dat_ass[$key] not set, returns null
92
-    if(!isset($dat_ass[$key]))
93
-      return null;
98
+    if(!isset($dat_ass[$key])) {
99
+          return null;
100
+    }
94 101
 
95 102
     // $dat_ass[$key] is a string, returns decoded value
96
-    if(is_string($dat_ass[$key]))
97
-      return urldecode($dat_ass[$key]);
103
+    if(is_string($dat_ass[$key])) {
104
+          return urldecode($dat_ass[$key]);
105
+    }
98 106
 
99 107
     // $dat_ass[$key] is not a string, return match[$key]
100 108
     return $dat_ass[$key];
@@ -144,7 +152,7 @@  discard block
 block discarded – undo
144 152
   {
145 153
     try{
146 154
       $url = $this->generate($route, $route_params);
147
-    }catch(\Exception $e){
155
+    } catch(\Exception $e){
148 156
       $url = $this->prehop(self::ROUTE_HOME_NAME);
149 157
     }
150 158
 
@@ -167,12 +175,13 @@  discard block
 block discarded – undo
167 175
   {
168 176
     $url = null;
169 177
 
170
-    if(is_null($route))
171
-      $url = $this->prehop(self::ROUTE_HOME_NAME, $route_params);
172
-    elseif(is_string($route) && $this->route_exists($route))
173
-      $url = $this->prehop($route, $route_params);
174
-    else
175
-      $url = $route;
178
+    if(is_null($route)) {
179
+          $url = $this->prehop(self::ROUTE_HOME_NAME, $route_params);
180
+    } elseif(is_string($route) && $this->route_exists($route)) {
181
+          $url = $this->prehop($route, $route_params);
182
+    } else {
183
+          $url = $route;
184
+    }
176 185
 
177 186
     $this->hop_url($url);
178 187
   }
@@ -180,8 +189,9 @@  discard block
 block discarded – undo
180 189
   // hops back to previous page (referer()), or home if no referer
181 190
   public function hop_back()
182 191
   {
183
-    if(!is_null($back = $this->referer()))
184
-      $this->hop_url($back);
192
+    if(!is_null($back = $this->referer())) {
193
+          $this->hop_url($back);
194
+    }
185 195
 
186 196
     $this->hop();
187 197
   }
@@ -198,16 +208,18 @@  discard block
 block discarded – undo
198 208
   // returns null if same as current URL (prevents endless redirection loop)
199 209
   public function referer()
200 210
   {
201
-    if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host() .$_SERVER['REQUEST_URI'])
202
-      return $_SERVER['HTTP_REFERER'];
211
+    if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host() .$_SERVER['REQUEST_URI']) {
212
+          return $_SERVER['HTTP_REFERER'];
213
+    }
203 214
 
204 215
     return null;
205 216
   }
206 217
 
207 218
   public function send_file($file_path)
208 219
   {
209
-    if(!file_exists($file_path))
210
-      throw new RouterException('SENDING_NON_EXISTING_FILE');
220
+    if(!file_exists($file_path)) {
221
+          throw new RouterException('SENDING_NON_EXISTING_FILE');
222
+    }
211 223
 
212 224
     $file_name = basename($file_path);
213 225
 
Please login to merge, or discard this patch.
RouterInterface.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@
 block discarded – undo
13 13
   public function match($requestUrl = null, $requestMethod = null);
14 14
 
15 15
   // generates URL for href and location
16
-  public function prehop($route, $route_params=[]);
16
+  public function prehop($route, $route_params = []);
17 17
 
18 18
   // heads to another location
19
-  public function hop($route, $route_params=[]);
19
+  public function hop($route, $route_params = []);
20 20
 
21 21
   // do you GET it ?
22 22
   public function requests() : bool;
23 23
 
24 24
   // have you POSTed it ?
25 25
   public function submits() : bool;
26
-  public function submitted($param_name=null);
26
+  public function submitted($param_name = null);
27 27
 
28 28
   public function send_file($file_path);
29 29
 
Please login to merge, or discard this patch.