Passed
Push — master ( 137834...e941dd )
by Fran
03:36
created
src/base/Router.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,6 @@
 block discarded – undo
4 4
 use PSFS\base\config\Config;
5 5
 use PSFS\base\dto\JsonResponse;
6 6
 use PSFS\base\exception\AccessDeniedException;
7
-use PSFS\base\exception\ApiException;
8 7
 use PSFS\base\exception\ConfigException;
9 8
 use PSFS\base\exception\RouterException;
10 9
 use PSFS\base\types\helpers\AdminHelper;
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
      */
64 64
     public function init()
65 65
     {
66
-        list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", $this->cacheType, TRUE);
66
+        list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", $this->cacheType, TRUE);
67 67
         if (empty($this->routing) || Config::getInstance()->getDebugMode()) {
68 68
             $this->debugLoad();
69
-        } else {
70
-            $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->cacheType, TRUE);
69
+        }else {
70
+            $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->cacheType, TRUE);
71 71
         }
72 72
         $this->checkExternalModules(false);
73 73
         $this->setLoaded(true);
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
         if (preg_match('/json/i', Request::getInstance()->getServer('CONTENT_TYPE')) || $isJson) {
103 103
             $response = new JsonResponse(null, false, 0, 0, $e->getMessage());
104 104
             return $template->output(json_encode($response), 'application/json');
105
-        } else {
105
+        }else {
106 106
             $not_found_route = Config::getParam('route.404');
107
-            if(null !== $not_found_route) {
107
+            if (null !== $not_found_route) {
108 108
                 Request::getInstance()->redirect($this->getRoute($not_found_route, true));
109
-            } else {
109
+            }else {
110 110
                 return $template->render('error.html.twig', array(
111 111
                     'exception' => $e,
112 112
                     'trace' => $e->getTraceAsString(),
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
         try {
162 162
             //Search action and execute
163 163
             $this->searchAction($route);
164
-        } catch (AccessDeniedException $e) {
164
+        }catch (AccessDeniedException $e) {
165 165
             Logger::log(_('Solicitamos credenciales de acceso a zona restringida'));
166 166
             return Admin::staticAdminLogon($route);
167
-        } catch (RouterException $r) {
167
+        }catch (RouterException $r) {
168 168
             Logger::log($r->getMessage(), LOG_WARNING);
169
-        } catch (\Exception $e) {
169
+        }catch (\Exception $e) {
170 170
             Logger::log($e->getMessage(), LOG_ERR);
171 171
             throw $e;
172 172
         }
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
      */
184 184
     protected function searchAction($route)
185 185
     {
186
-        Logger::log('Searching action to execute: ' . $route, LOG_INFO);
186
+        Logger::log('Searching action to execute: '.$route, LOG_INFO);
187 187
         //Revisamos si tenemos la ruta registrada
188 188
         $parts = parse_url($route);
189 189
         $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route;
@@ -198,12 +198,12 @@  discard block
 block discarded – undo
198 198
                 /** @var $class \PSFS\base\types\Controller */
199 199
                 $class = RouterHelper::getClassToCall($action);
200 200
                 try {
201
-                    if($this->checkRequirements($action, $get)) {
201
+                    if ($this->checkRequirements($action, $get)) {
202 202
                         $this->executeCachedRoute($route, $action, $class, $get);
203
-                    } else {
203
+                    }else {
204 204
                         throw new RouterException(_('La ruta no es válida'), 400);
205 205
                     }
206
-                } catch (\Exception $e) {
206
+                }catch (\Exception $e) {
207 207
                     Logger::log($e->getMessage(), LOG_ERR);
208 208
                     throw $e;
209 209
                 }
@@ -218,15 +218,15 @@  discard block
 block discarded – undo
218 218
      * @return bool
219 219
      */
220 220
     private function checkRequirements(array $action, array $params = []) {
221
-        if(!empty($action['requirements']) && !empty($params)) {
221
+        if (!empty($action['requirements']) && !empty($params)) {
222 222
             $checked = 0;
223
-            foreach(array_keys($params) as $key) {
224
-                if(in_array($key, $action['requirements'])) {
223
+            foreach (array_keys($params) as $key) {
224
+                if (in_array($key, $action['requirements'])) {
225 225
                     $checked++;
226 226
                 }
227 227
             }
228 228
             $valid = count($action['requirements']) == $checked;
229
-        } else {
229
+        }else {
230 230
             $valid = true;
231 231
         }
232 232
         return $valid;
@@ -278,10 +278,10 @@  discard block
 block discarded – undo
278 278
             $modules = $this->finder->directories()->in($modulesPath)->depth(0);
279 279
             foreach ($modules as $modulePath) {
280 280
                 $module = $modulePath->getBasename();
281
-                $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing);
281
+                $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing);
282 282
             }
283 283
         }
284
-        $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE);
284
+        $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE);
285 285
     }
286 286
 
287 287
     /**
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
             $home_params = NULL;
297 297
             foreach ($this->routing as $pattern => $params) {
298 298
                 list($method, $route) = RouterHelper::extractHttpRoute($pattern);
299
-                if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) {
299
+                if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) {
300 300
                     $home_params = $params;
301 301
                 }
302 302
             }
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
         $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php");
322 322
         foreach ($files as $file) {
323 323
             $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname()));
324
-            $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace);
324
+            $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace);
325 325
         }
326 326
         $this->finder = new Finder();
327 327
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
     private function addRouting($namespace, &$routing, $module = 'PSFS')
352 352
     {
353 353
         if (self::exists($namespace)) {
354
-            if(I18nHelper::checkI18Class($namespace)) {
354
+            if (I18nHelper::checkI18Class($namespace)) {
355 355
                 return $routing;
356 356
             }
357 357
             $reflection = new \ReflectionClass($namespace);
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
             if (!$this->domains) {
395 395
                 $this->domains = [];
396 396
             }
397
-            $domain = "@" . $class->getConstant("DOMAIN") . "/";
397
+            $domain = "@".$class->getConstant("DOMAIN")."/";
398 398
             if (!array_key_exists($domain, $this->domains)) {
399 399
                 $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain);
400 400
             }
@@ -409,11 +409,11 @@  discard block
 block discarded – undo
409 409
      */
410 410
     public function simpatize()
411 411
     {
412
-        $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php";
413
-        $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName;
412
+        $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php";
413
+        $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName;
414 414
         $this->generateSlugs($absoluteTranslationFileName);
415 415
         GeneratorHelper::createDir(CONFIG_DIR);
416
-        Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE);
416
+        Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE);
417 417
 
418 418
         return $this;
419 419
     }
@@ -431,16 +431,16 @@  discard block
 block discarded – undo
431 431
     public function getRoute($slug = '', $absolute = FALSE, $params = [])
432 432
     {
433 433
         if (strlen($slug) === 0) {
434
-            return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/';
434
+            return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/';
435 435
         }
436 436
         if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) {
437 437
             throw new RouterException(_("No existe la ruta especificada"));
438 438
         }
439
-        $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug];
439
+        $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug];
440 440
         if (!empty($params)) foreach ($params as $key => $value) {
441
-            $url = str_replace("{" . $key . "}", $value, $url);
441
+            $url = str_replace("{".$key."}", $value, $url);
442 442
         } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) {
443
-            $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"];
443
+            $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"];
444 444
         }
445 445
 
446 446
         return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url);
@@ -485,17 +485,17 @@  discard block
 block discarded – undo
485 485
      */
486 486
     protected function executeCachedRoute($route, $action, $class, $params = NULL)
487 487
     {
488
-        Logger::log('Executing route ' . $route, LOG_INFO);
488
+        Logger::log('Executing route '.$route, LOG_INFO);
489 489
         $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams());
490 490
         Security::getInstance()->setSessionKey("__CACHE__", $action);
491 491
         $cache = Cache::needCache();
492 492
         $execute = TRUE;
493 493
         if (FALSE !== $cache && Config::getParam('debug') === FALSE && $action['http'] === 'GET') {
494 494
             list($path, $cacheDataName) = $this->cache->getRequestCacheHash();
495
-            $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName,
495
+            $cachedData = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName,
496 496
                 $cache, null);
497 497
             if (NULL !== $cachedData) {
498
-                $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName . ".headers",
498
+                $headers = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName.".headers",
499 499
                     $cache, null, Cache::JSON);
500 500
                 Template::getInstance()->renderCache($cachedData, $headers);
501 501
                 $execute = FALSE;
@@ -538,10 +538,10 @@  discard block
 block discarded – undo
538 538
     private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath)
539 539
     {
540 540
         $extModule = $modulePath->getBasename();
541
-        $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php');
541
+        $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php');
542 542
         @include $moduleAutoloader;
543 543
         if ($hydrateRoute) {
544
-            $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing);
544
+            $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing);
545 545
         }
546 546
     }
547 547
 
@@ -554,12 +554,12 @@  discard block
 block discarded – undo
554 554
     {
555 555
         try {
556 556
             $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module);
557
-            $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src';
557
+            $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src';
558 558
             $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0);
559 559
             foreach ($externalModule as $modulePath) {
560 560
                 $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath);
561 561
             }
562
-        } catch (\Exception $e) {
562
+        }catch (\Exception $e) {
563 563
             Logger::log($e->getMessage(), LOG_WARNING);
564 564
             $module = null;
565 565
         }
Please login to merge, or discard this patch.
src/Dispatcher.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -73,18 +73,18 @@
 block discarded – undo
73 73
                 if (!Request::getInstance()->isFile()) {
74 74
                     return $this->router->execute($this->actualUri);
75 75
                 }
76
-            } else {
76
+            }else {
77 77
                 return ConfigController::getInstance()->config();
78 78
             }
79
-        } catch (AdminCredentialsException $a) {
79
+        }catch (AdminCredentialsException $a) {
80 80
             return UserController::showAdminManager();
81
-        } catch (SecurityException $s) {
81
+        }catch (SecurityException $s) {
82 82
             return $this->security->notAuthorized($this->actualUri);
83
-        } catch (RouterException $r) {
83
+        }catch (RouterException $r) {
84 84
             return $this->router->httpNotFound($r);
85
-        } catch(ApiException $a) {
85
+        }catch (ApiException $a) {
86 86
             return $this->router->httpNotFound($a, true);
87
-        } catch (\Exception $e) {
87
+        }catch (\Exception $e) {
88 88
             return $this->dumpException($e);
89 89
         }
90 90
     }
Please login to merge, or discard this patch.