Passed
Push — main ( 891daf...960f59 )
by Sammy
05:56 queued 03:50
created
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.
hopper.php 1 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();
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
   {
42 42
     $this->match = parent::match($requestUrl, $requestMethod);
43 43
 
44
-    if($this->match === false)
44
+    if ($this->match === false)
45 45
       throw new RouterException('ROUTE_MATCH_FALSE');
46 46
 
47 47
     $res = explode('::', $this->target());
48 48
 
49
-    if($res === false || !isset($res[1]) || isset($res[2]))
49
+    if ($res === false || !isset($res[1]) || isset($res[2]))
50 50
       throw new RouterException('INVALID_TARGET');
51 51
 
52 52
     $target_controller = $res[0];
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
     $found = false;
55 55
 
56 56
     $controller_class_name = null;
57
-    foreach($this->controller_namespaces as $controller_ns)
58
-      if($found = class_exists($controller_class_name = "$controller_ns$target_controller"))
57
+    foreach ($this->controller_namespaces as $controller_ns)
58
+      if ($found = class_exists($controller_class_name = "$controller_ns$target_controller"))
59 59
         break;
60 60
 
61
-    if($found === false)
61
+    if ($found === false)
62 62
       throw new RouterException('INVALID_CONTROLLER_NAME');
63 63
 
64 64
     $this->match['target_controller'] = $controller_class_name;
@@ -67,29 +67,29 @@  discard block
 block discarded – undo
67 67
     return [$controller_class_name, $target_method];
68 68
   }
69 69
 
70
-  public function params($param_name=null)
70
+  public function params($param_name = null)
71 71
   {
72 72
     return $this->extract_request($this->match['params'] ?? [], $param_name);
73 73
   }
74 74
 
75
-  public function submitted($param_name=null)
75
+  public function submitted($param_name = null)
76 76
   {
77 77
     return $this->extract_request($_POST, $param_name);
78 78
   }
79 79
 
80
-  private function extract_request($dat_ass, $key=null)
80
+  private function extract_request($dat_ass, $key = null)
81 81
   {
82 82
 
83 83
     // $key is null, returns $dat_ass or empty array
84
-    if(is_null($key))
84
+    if (is_null($key))
85 85
       return $dat_ass ?? [];
86 86
 
87 87
     // $dat_ass[$key] not set, returns null
88
-    if(!isset($dat_ass[$key]))
88
+    if (!isset($dat_ass[$key]))
89 89
       return null;
90 90
 
91 91
     // $dat_ass[$key] is a string, returns decoded value
92
-    if(is_string($dat_ass[$key]))
92
+    if (is_string($dat_ass[$key]))
93 93
       return urldecode($dat_ass[$key]);
94 94
 
95 95
     // $dat_ass[$key] is not a string, return match[$key]
@@ -136,18 +136,18 @@  discard block
 block discarded – undo
136 136
    *  - an assoc_array of url params (strongly AltoRouter-based)
137 137
    * returns: something to put in a href="", action="" or header('Location:');
138 138
    */
139
-  public function prehop($route, $route_params=[])
139
+  public function prehop($route, $route_params = [])
140 140
   {
141
-    try{
141
+    try {
142 142
       $url = $this->generate($route, $route_params);
143
-    }catch(\Exception $e){
143
+    }catch (\Exception $e) {
144 144
       $url = $this->prehop(self::ROUTE_HOME_NAME);
145 145
     }
146 146
 
147 147
     return $url;
148 148
   }
149 149
 
150
-  public function prehop_here($url=null)
150
+  public function prehop_here($url = null)
151 151
   {
152 152
     return $url ?? $_SERVER['REQUEST_URI'];
153 153
   }
@@ -159,13 +159,13 @@  discard block
 block discarded – undo
159 159
    *    - a url, go there
160 160
    * @params $route_params, assoc_data for url creation (i:id, a:format, ..)
161 161
    */
162
-  public function hop($route=null, $route_params=[])
162
+  public function hop($route = null, $route_params = [])
163 163
   {
164 164
     $url = null;
165 165
 
166
-    if(is_null($route))
166
+    if (is_null($route))
167 167
       $url = $this->prehop(self::ROUTE_HOME_NAME, $route_params);
168
-    elseif(is_string($route) && $this->route_exists($route))
168
+    elseif (is_string($route) && $this->route_exists($route))
169 169
       $url = $this->prehop($route, $route_params);
170 170
     else
171 171
       $url = $route;
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
   // hops back to previous page (referer()), or home if no referer
177 177
   public function hop_back()
178 178
   {
179
-    if(!is_null($back = $this->referer()))
179
+    if (!is_null($back = $this->referer()))
180 180
       $this->hop_url($back);
181 181
 
182 182
     $this->hop();
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
   // returns null if same as current URL (prevents endless redirection loop)
195 195
   public function referer()
196 196
   {
197
-    if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host() .$_SERVER['REQUEST_URI'])
197
+    if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host().$_SERVER['REQUEST_URI'])
198 198
       return $_SERVER['HTTP_REFERER'];
199 199
 
200 200
     return null;
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 
203 203
   public function send_file($file_path)
204 204
   {
205
-    if(!file_exists($file_path))
205
+    if (!file_exists($file_path))
206 206
       throw new RouterException('SENDING_NON_EXISTING_FILE');
207 207
 
208 208
     $file_name = basename($file_path);
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
     //Get file type and set it as Content Type
211 211
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
212 212
 
213
-    header('Content-Type: ' . finfo_file($finfo, $file_path));
213
+    header('Content-Type: '.finfo_file($finfo, $file_path));
214 214
 
215 215
     finfo_close($finfo);
216 216
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
     header('Pragma: public');
224 224
 
225 225
     //Define file size
226
-    header('Content-Length: ' . filesize($file_path));
226
+    header('Content-Length: '.filesize($file_path));
227 227
 
228 228
     ob_clean();
229 229
     flush();
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 
250 250
   public function web_root() : string
251 251
   {
252
-    return $this->web_host() . $this->web_base();
252
+    return $this->web_host().$this->web_base();
253 253
   }
254 254
 
255 255
   public function web_base() : string
Please login to merge, or discard this patch.