Passed
Push — master ( 1a4459...3c70c1 )
by Fran
05:00
created
src/base/Router.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
     }
180 180
 
181 181
     /**
182
-     * @param $route
182
+     * @param string|null $route
183 183
      * @throws AccessDeniedException
184 184
      * @throws AdminCredentialsException
185 185
      * @throws RouterException
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
     /**
536 536
      * @param bool $hydrateRoute
537 537
      * @param $modulePath
538
-     * @param $externalModulePath
538
+     * @param string $externalModulePath
539 539
      */
540 540
     private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath)
541 541
     {
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
     }
551 551
 
552 552
     /**
553
-     * @param $hydrateRoute
553
+     * @param boolean $hydrateRoute
554 554
      * @param $module
555 555
      * @return mixed
556 556
      */
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
      */
76 76
     public function init()
77 77
     {
78
-        list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', $this->cacheType, TRUE);
78
+        list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', $this->cacheType, TRUE);
79 79
         if (empty($this->routing) || Config::getInstance()->getDebugMode()) {
80 80
             $this->debugLoad();
81
-        } else {
82
-            $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->cacheType, TRUE);
81
+        }else {
82
+            $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->cacheType, TRUE);
83 83
         }
84 84
         $this->checkExternalModules(false);
85 85
         $this->setLoaded();
@@ -117,9 +117,9 @@  discard block
 block discarded – undo
117 117
         }
118 118
 
119 119
         $not_found_route = Config::getParam('route.404');
120
-        if(null !== $not_found_route) {
120
+        if (null !== $not_found_route) {
121 121
             Request::getInstance()->redirect($this->getRoute($not_found_route, true));
122
-        } else {
122
+        }else {
123 123
             return $template->render('error.html.twig', array(
124 124
                 'exception' => $e,
125 125
                 'trace' => $e->getTraceAsString(),
@@ -170,12 +170,12 @@  discard block
 block discarded – undo
170 170
         try {
171 171
             //Search action and execute
172 172
             $this->searchAction($route);
173
-        } catch (AccessDeniedException $e) {
174
-            Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile() . '[' . $e->getLine() . ']']);
173
+        }catch (AccessDeniedException $e) {
174
+            Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile().'['.$e->getLine().']']);
175 175
             return Admin::staticAdminLogon($route);
176
-        } catch (RouterException $r) {
176
+        }catch (RouterException $r) {
177 177
             Logger::log($r->getMessage(), LOG_WARNING);
178
-        } catch (\Exception $e) {
178
+        }catch (\Exception $e) {
179 179
             Logger::log($e->getMessage(), LOG_ERR);
180 180
             throw $e;
181 181
         }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      */
193 193
     protected function searchAction($route)
194 194
     {
195
-        Logger::log('Searching action to execute: ' . $route, LOG_INFO);
195
+        Logger::log('Searching action to execute: '.$route, LOG_INFO);
196 196
         //Revisamos si tenemos la ruta registrada
197 197
         $parts = parse_url($route);
198 198
         $path = array_key_exists('path', $parts) ? $parts['path'] : $route;
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
                 /** @var $class \PSFS\base\types\Controller */
208 208
                 $class = RouterHelper::getClassToCall($action);
209 209
                 try {
210
-                    if($this->checkRequirements($action, $get)) {
210
+                    if ($this->checkRequirements($action, $get)) {
211 211
                         $this->executeCachedRoute($route, $action, $class, $get);
212
-                    } else {
212
+                    }else {
213 213
                         throw new RouterException(_('La ruta no es válida'), 400);
214 214
                     }
215
-                } catch (\Exception $e) {
215
+                }catch (\Exception $e) {
216 216
                     Logger::log($e->getMessage(), LOG_ERR);
217 217
                     throw $e;
218 218
                 }
@@ -227,15 +227,15 @@  discard block
 block discarded – undo
227 227
      * @return bool
228 228
      */
229 229
     private function checkRequirements(array $action, $params = []) {
230
-        if(!empty($params) && !empty($action['requirements'])) {
230
+        if (!empty($params) && !empty($action['requirements'])) {
231 231
             $checked = 0;
232
-            foreach(array_keys($params) as $key) {
233
-                if(in_array($key, $action['requirements'], true)) {
232
+            foreach (array_keys($params) as $key) {
233
+                if (in_array($key, $action['requirements'], true)) {
234 234
                     $checked++;
235 235
                 }
236 236
             }
237 237
             $valid = count($action['requirements']) === $checked;
238
-        } else {
238
+        }else {
239 239
             $valid = true;
240 240
         }
241 241
         return $valid;
@@ -285,14 +285,14 @@  discard block
 block discarded – undo
285 285
         $this->checkExternalModules();
286 286
         if (file_exists($modulesPath)) {
287 287
             $modules = $this->finder->directories()->in($modulesPath)->depth(0);
288
-            if($modules->hasResults()) {
288
+            if ($modules->hasResults()) {
289 289
                 foreach ($modules->getIterator() as $modulePath) {
290 290
                     $module = $modulePath->getBasename();
291
-                    $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing);
291
+                    $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing);
292 292
                 }
293 293
             }
294 294
         }
295
-        $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->domains, Cache::JSON, TRUE);
295
+        $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->domains, Cache::JSON, TRUE);
296 296
     }
297 297
 
298 298
     /**
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
             $home_params = NULL;
309 309
             foreach ($this->routing as $pattern => $params) {
310 310
                 list($method, $route) = RouterHelper::extractHttpRoute($pattern);
311
-                if (preg_match('/' . preg_quote($route, '/') . '$/i', '/' . $home)) {
311
+                if (preg_match('/'.preg_quote($route, '/').'$/i', '/'.$home)) {
312 312
                     $home_params = $params;
313 313
                 }
314 314
             }
@@ -329,14 +329,14 @@  discard block
 block discarded – undo
329 329
     private function inspectDir($origen, $namespace = 'PSFS', $routing = [])
330 330
     {
331 331
         $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name('*.php');
332
-        if($files->hasResults()) {
332
+        if ($files->hasResults()) {
333 333
             foreach ($files->getIterator() as $file) {
334
-                if(method_exists($file, 'getRelativePathname') && $namespace !== 'PSFS') {
335
-                    $filename = '\\' . str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname()));
336
-                } else {
334
+                if (method_exists($file, 'getRelativePathname') && $namespace !== 'PSFS') {
335
+                    $filename = '\\'.str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname()));
336
+                }else {
337 337
                     $filename = str_replace('/', '\\', str_replace($origen, '', $file->getPathname()));
338 338
                 }
339
-                $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace);
339
+                $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace);
340 340
             }
341 341
         }
342 342
         $this->finder = new Finder();
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
     private function addRouting($namespace, &$routing, $module = 'PSFS')
366 366
     {
367 367
         if (self::exists($namespace)) {
368
-            if(I18nHelper::checkI18Class($namespace)) {
368
+            if (I18nHelper::checkI18Class($namespace)) {
369 369
                 return $routing;
370 370
             }
371 371
             $reflection = new \ReflectionClass($namespace);
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
             if (!$this->domains) {
408 408
                 $this->domains = [];
409 409
             }
410
-            $domain = '@' . $class->getConstant('DOMAIN') . '/';
410
+            $domain = '@'.$class->getConstant('DOMAIN').'/';
411 411
             if (!array_key_exists($domain, $this->domains)) {
412 412
                 $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain);
413 413
             }
@@ -423,11 +423,11 @@  discard block
 block discarded – undo
423 423
      */
424 424
     public function simpatize()
425 425
     {
426
-        $translationFileName = 'translations' . DIRECTORY_SEPARATOR . 'routes_translations.php';
427
-        $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName;
426
+        $translationFileName = 'translations'.DIRECTORY_SEPARATOR.'routes_translations.php';
427
+        $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName;
428 428
         $this->generateSlugs($absoluteTranslationFileName);
429 429
         GeneratorHelper::createDir(CONFIG_DIR);
430
-        Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE);
430
+        Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE);
431 431
 
432 432
         return $this;
433 433
     }
@@ -443,18 +443,18 @@  discard block
 block discarded – undo
443 443
     public function getRoute($slug = '', $absolute = FALSE, array $params = [])
444 444
     {
445 445
         if ('' === $slug) {
446
-            return $absolute ? Request::getInstance()->getRootUrl() . '/' : '/';
446
+            return $absolute ? Request::getInstance()->getRootUrl().'/' : '/';
447 447
         }
448 448
         if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) {
449 449
             throw new RouterException(_('No existe la ruta especificada'));
450 450
         }
451
-        $url = $absolute ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug];
451
+        $url = $absolute ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug];
452 452
         if (!empty($params)) {
453 453
             foreach ($params as $key => $value) {
454
-                $url = str_replace('{' . $key . '}', $value, $url);
454
+                $url = str_replace('{'.$key.'}', $value, $url);
455 455
             }
456 456
         } elseif (!empty($this->routing[$this->slugs[$slug]]['default'])) {
457
-            $url = $absolute ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default'];
457
+            $url = $absolute ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default'];
458 458
         }
459 459
 
460 460
         return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url);
@@ -496,17 +496,17 @@  discard block
 block discarded – undo
496 496
      */
497 497
     protected function executeCachedRoute($route, $action, $class, $params = NULL)
498 498
     {
499
-        Logger::log('Executing route ' . $route, LOG_INFO);
499
+        Logger::log('Executing route '.$route, LOG_INFO);
500 500
         $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams());
501 501
         Security::getInstance()->setSessionKey(Cache::CACHE_SESSION_VAR, $action);
502 502
         $cache = Cache::needCache();
503 503
         $execute = TRUE;
504 504
         if (FALSE !== $cache && $action['http'] === 'GET' && Config::getParam('debug') === FALSE) {
505 505
             list($path, $cacheDataName) = $this->cache->getRequestCacheHash();
506
-            $cachedData = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName,
506
+            $cachedData = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName,
507 507
                 $cache);
508 508
             if (NULL !== $cachedData) {
509
-                $headers = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName . '.headers',
509
+                $headers = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName.'.headers',
510 510
                     $cache, null, Cache::JSON);
511 511
                 Template::getInstance()->renderCache($cachedData, $headers);
512 512
                 $execute = FALSE;
@@ -549,11 +549,11 @@  discard block
 block discarded – undo
549 549
     private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath)
550 550
     {
551 551
         $extModule = $modulePath->getBasename();
552
-        $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php');
553
-        if(file_exists($moduleAutoloader)) {
552
+        $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php');
553
+        if (file_exists($moduleAutoloader)) {
554 554
             include_once $moduleAutoloader;
555 555
             if ($hydrateRoute) {
556
-                $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing);
556
+                $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing);
557 557
             }
558 558
         }
559 559
     }
@@ -567,16 +567,16 @@  discard block
 block discarded – undo
567 567
     {
568 568
         try {
569 569
             $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module);
570
-            $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src';
571
-            if(file_exists($externalModulePath)) {
570
+            $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src';
571
+            if (file_exists($externalModulePath)) {
572 572
                 $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0);
573
-                if($externalModule->hasResults()) {
573
+                if ($externalModule->hasResults()) {
574 574
                     foreach ($externalModule->getIterator() as $modulePath) {
575 575
                         $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath);
576 576
                     }
577 577
                 }
578 578
             }
579
-        } catch (\Exception $e) {
579
+        }catch (\Exception $e) {
580 580
             Logger::log($e->getMessage(), LOG_WARNING);
581 581
             $module = null;
582 582
         }
Please login to merge, or discard this patch.
src/base/types/helpers/FileHelper.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      */
24 24
     public static function readFile($path) {
25 25
         $data = false;
26
-        if(file_exists($path)) {
26
+        if (file_exists($path)) {
27 27
             $data = @file_get_contents($path);
28 28
         }
29 29
         return $data;
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      * @return string
37 37
      */
38 38
     public static function generateHashFilename($verb, $slug, array $query = []) {
39
-        return sha1(strtolower($verb) . ' ' . $slug . ' ' . strtolower(http_build_query($query)));
39
+        return sha1(strtolower($verb).' '.$slug.' '.strtolower(http_build_query($query)));
40 40
     }
41 41
 
42 42
     /**
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
     public static function generateCachePath(array $action, array $query = []) {
48 48
         $class = GeneratorHelper::extractClassFromNamespace($action['class']);
49 49
         $filename = self::generateHashFilename($action['http'], $action['slug'], $query);
50
-        $subPath = substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2);
51
-        return $action['module'] . DIRECTORY_SEPARATOR . $class . DIRECTORY_SEPARATOR . $action['method'] . DIRECTORY_SEPARATOR . $subPath . DIRECTORY_SEPARATOR;
50
+        $subPath = substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2);
51
+        return $action['module'].DIRECTORY_SEPARATOR.$class.DIRECTORY_SEPARATOR.$action['method'].DIRECTORY_SEPARATOR.$subPath.DIRECTORY_SEPARATOR;
52 52
     }
53 53
 
54 54
     /**
Please login to merge, or discard this patch.
src/base/Singleton.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      */
23 23
     public function __construct()
24 24
     {
25
-        Logger::log(get_class($this) . ' constructor invoked');
25
+        Logger::log(get_class($this).' constructor invoked');
26 26
         $this->init();
27 27
     }
28 28
 
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
         $calledClass = static::class;
81 81
         try {
82 82
             $instance = InjectorHelper::constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass);
83
-            $setter = 'set' . ucfirst($variable);
83
+            $setter = 'set'.ucfirst($variable);
84 84
             if (method_exists($calledClass, $setter)) {
85 85
                 $this->$setter($instance);
86
-            } else {
86
+            }else {
87 87
                 $this->$variable = $instance;
88 88
             }
89
-        } catch (\Exception $e) {
90
-            Logger::log($e->getMessage() . ': ' . $e->getFile() . ' [' . $e->getLine() . ']', LOG_ERR);
89
+        }catch (\Exception $e) {
90
+            Logger::log($e->getMessage().': '.$e->getFile().' ['.$e->getLine().']', LOG_ERR);
91 91
             throw $e;
92 92
         }
93 93
         return $this;
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
     {
103 103
         if (!$this->isLoaded()) {
104 104
             $filename = sha1(get_class($this));
105
-            $cacheFilename = 'reflections' . DIRECTORY_SEPARATOR . substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2) . DIRECTORY_SEPARATOR . $filename . ".json";
105
+            $cacheFilename = 'reflections'.DIRECTORY_SEPARATOR.substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2).DIRECTORY_SEPARATOR.$filename.".json";
106 106
             /** @var \PSFS\base\Cache $cacheService */
107 107
             $cacheService = Cache::getInstance();
108 108
             /** @var \PSFS\base\config\Config $configService */
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
                 }
121 121
             }
122 122
             $this->setLoaded();
123
-        } else {
124
-            Logger::log(get_class($this) . ' already loaded', LOG_INFO);
123
+        }else {
124
+            Logger::log(get_class($this).' already loaded', LOG_INFO);
125 125
         }
126 126
     }
127 127
 }
Please login to merge, or discard this patch.
src/base/Security.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
             session_start();
74 74
         }
75 75
         // Fix for phpunits
76
-        if(!isset($_SESSION)) {
76
+        if (!isset($_SESSION)) {
77 77
             $_SESSION = [];
78 78
         }
79 79
     }
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
     public static function save($user)
128 128
     {
129 129
         $saved = true;
130
-        $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true) ?: [];
131
-        $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']);
130
+        $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true) ?: [];
131
+        $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']);
132 132
         $admins[$user['username']]['profile'] = $user['profile'];
133 133
 
134
-        Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', $admins, Cache::JSONGZ, true);
134
+        Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', $admins, Cache::JSONGZ, true);
135 135
         return $saved;
136 136
     }
137 137
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      */
175 175
     public function getAdmins()
176 176
     {
177
-        return Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true);
177
+        return Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true);
178 178
     }
179 179
 
180 180
     /**
@@ -199,9 +199,9 @@  discard block
 block discarded – undo
199 199
                 }
200 200
                 if (!empty($user) && !empty($admins[$user])) {
201 201
                     $auth = $admins[$user]['hash'];
202
-                    $this->authorized = ($auth === sha1($user . $pass));
202
+                    $this->authorized = ($auth === sha1($user.$pass));
203 203
                     if ($this->authorized) {
204
-                        $this->updateAdmin($user , $admins[$user]['profile']);
204
+                        $this->updateAdmin($user, $admins[$user]['profile']);
205 205
                         ResponseHelper::setCookieHeaders([
206 206
                             [
207 207
                                 'name' => $this->getHash(),
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
                         ]);
213 213
                         $this->setSessionKey(self::LOGGED_USER_TOKEN, base64_encode("{$user}:{$pass}"));
214 214
                     }
215
-                } else {
215
+                }else {
216 216
                     $this->admin = null;
217 217
                     $this->setSessionKey(self::ADMIN_ID_TOKEN, null);
218 218
                 }
Please login to merge, or discard this patch.
src/base/types/helpers/ApiFormHelper.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@  discard block
 block discarded – undo
17 17
     public static function checkApiActions($namespace, $domain, $api) {
18 18
         $actions = [];
19 19
         $reflector = new \ReflectionClass($namespace);
20
-        if(null !== $reflector) {
21
-            foreach($reflector->getMethods(\ReflectionMethod::IS_PUBLIC) as $apiAction) {
20
+        if (null !== $reflector) {
21
+            foreach ($reflector->getMethods(\ReflectionMethod::IS_PUBLIC) as $apiAction) {
22 22
                 $docComments = $apiAction->getDocComment();
23 23
                 $action = self::extractAction($docComments);
24
-                if(null !== $action) {
24
+                if (null !== $action) {
25 25
                     list($route, $info) = RouterHelper::extractRouteInfo($apiAction, $api, $domain);
26 26
                     list($method, $cleanRoute) = RouterHelper::extractHttpRoute($route);
27 27
                     $formAction = new FormAction();
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     {
45 45
         $action = null;
46 46
         if (false !== preg_match('/@action\s+([^\s]+)/', $doc, $matches)) {
47
-            if(count($matches) > 1) {
47
+            if (count($matches) > 1) {
48 48
                 list(, $action) = $matches;
49 49
             }
50 50
         }
Please login to merge, or discard this patch.
src/base/types/helpers/I18nHelper.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
 
20 20
     /**
21 21
      * @param string $default
22
-     * @return array|mixed|string
22
+     * @return string
23 23
      */
24 24
     public static function extractLocale($default = null)
25 25
     {
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
         $locale = Request::header('X-API-LANG');
29 29
         if (empty($locale)) {
30 30
             $locale = Security::getInstance()->getSessionKey(self::PSFS_SESSION_LANGUAGE_KEY);
31
-            if(empty($locale) && array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
31
+            if (empty($locale) && array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
32 32
                 $BrowserLocales = explode(",", str_replace("-", "_", $_SERVER["HTTP_ACCEPT_LANGUAGE"])); // brosers use en-US, Linux uses en_US
33 33
                 for ($i = 0; $i < count($BrowserLocales); $i++) {
34 34
                     list($BrowserLocales[$i]) = explode(";", $BrowserLocales[$i]); //trick for "en;q=0.8"
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
         if (false !== strpos($locale, '_')) {
41 41
             $locale = explode('_', $locale);
42 42
             if ($locale[0] == 'en') {
43
-                $locale = $locale[0] . '_GB';
44
-            } else {
45
-                $locale = $locale[0] . '_' . strtoupper($locale[1]);
43
+                $locale = $locale[0].'_GB';
44
+            }else {
45
+                $locale = $locale[0].'_'.strtoupper($locale[1]);
46 46
             }
47
-        } else {
47
+        }else {
48 48
             if (strtolower($locale) === 'en') {
49 49
                 $locale = 'en_GB';
50
-            } else {
51
-                $locale = $locale . '_' . strtoupper($locale);
50
+            }else {
51
+                $locale = $locale.'_'.strtoupper($locale);
52 52
             }
53 53
         }
54 54
         $default_locales = explode(',', Config::getParam('i18n.locales', ''));
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
         $translations = array();
71 71
         if (file_exists($absoluteTranslationFileName)) {
72 72
             @include($absoluteTranslationFileName);
73
-        } else {
73
+        }else {
74 74
             Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE);
75 75
         }
76 76
 
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
     public static function setLocale()
84 84
     {
85 85
         $locale = self::extractLocale('es_ES');
86
-        Logger::log('Set locale to project [' . $locale . ']');
86
+        Logger::log('Set locale to project ['.$locale.']');
87 87
         // Load translations
88
-        putenv("LC_ALL=" . $locale);
88
+        putenv("LC_ALL=".$locale);
89 89
         setlocale(LC_ALL, $locale);
90 90
         // Load the locale path
91
-        $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale';
92
-        Logger::log('Set locale dir ' . $locale_path);
91
+        $locale_path = BASE_DIR.DIRECTORY_SEPARATOR.'locale';
92
+        Logger::log('Set locale dir '.$locale_path);
93 93
         GeneratorHelper::createDir($locale_path);
94 94
         bindtextdomain('translations', $locale_path);
95 95
         textdomain('translations');
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public static function checkI18Class($namespace) {
126 126
         $isI18n = false;
127
-        if(preg_match('/I18n$/i', $namespace)) {
127
+        if (preg_match('/I18n$/i', $namespace)) {
128 128
             $parentClass = preg_replace('/I18n$/i', '', $namespace);
129
-            if(Router::exists($parentClass)) {
129
+            if (Router::exists($parentClass)) {
130 130
                 $isI18n = true;
131 131
             }
132 132
         }
Please login to merge, or discard this patch.
src/base/extension/CustomTranslateExtension.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
      * @param bool $force_reload
24 24
      */
25 25
     protected static function checkLoad($custom_key = null, $force_reload = false) {
26
-        if($force_reload) self::dropInstance();
26
+        if ($force_reload) self::dropInstance();
27 27
         self::$locale = I18nHelper::extractLocale('es_ES');
28 28
         $custom_key = $custom_key ?: Security::getInstance()->getSessionKey(self::CUSTOM_LOCALE_SESSION_KEY);
29
-        if(null !== $custom_key) {
30
-            Logger::log('[' . self::class . '] Custom key detected: ' . $custom_key, LOG_INFO);
31
-            $filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $custom_key, self::$locale . '.json']);
32
-            if(file_exists($filename)) {
33
-                Logger::log('[' . self::class . '] Custom locale detected: ' . $custom_key . ' [' . self::$locale . ']', LOG_INFO);
29
+        if (null !== $custom_key) {
30
+            Logger::log('['.self::class.'] Custom key detected: '.$custom_key, LOG_INFO);
31
+            $filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $custom_key, self::$locale.'.json']);
32
+            if (file_exists($filename)) {
33
+                Logger::log('['.self::class.'] Custom locale detected: '.$custom_key.' ['.self::$locale.']', LOG_INFO);
34 34
                 self::$translations = json_decode(file_get_contents($filename), true);
35 35
             }
36 36
         }
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public static function _($message, $custom_key = null, $force_reload = false) {
74 74
         self::checkLoad($custom_key, $force_reload);
75
-        if(array_key_exists($message, self::$translations)) {
75
+        if (array_key_exists($message, self::$translations)) {
76 76
             return self::$translations[$message];
77
-        } else {
77
+        }else {
78 78
             return gettext($message);
79 79
         }
80 80
     }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,9 @@
 block discarded – undo
23 23
      * @param bool $force_reload
24 24
      */
25 25
     protected static function checkLoad($custom_key = null, $force_reload = false) {
26
-        if($force_reload) self::dropInstance();
26
+        if($force_reload) {
27
+            self::dropInstance();
28
+        }
27 29
         self::$locale = I18nHelper::extractLocale('es_ES');
28 30
         $custom_key = $custom_key ?: Security::getInstance()->getSessionKey(self::CUSTOM_LOCALE_SESSION_KEY);
29 31
         if(null !== $custom_key) {
Please login to merge, or discard this patch.
src/base/types/Api.php 2 patches
Unused Use Statements   -7 removed lines patch added patch discarded remove patch
@@ -1,13 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace PSFS\base\types;
3 3
 
4
-use CORE\Models\Customer;
5 4
 use CORE\Models\Map\CustomerTableMap;
6 5
 use Propel\Runtime\ActiveQuery\ModelCriteria;
7
-use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
8
-use Propel\Runtime\DataFetcher\ArrayDataFetcher;
9
-use Propel\Runtime\Formatter\ObjectFormatter;
10
-use Propel\Runtime\Map\ColumnMap;
11 6
 use Propel\Runtime\Map\TableMap;
12 7
 use Propel\Runtime\Propel;
13 8
 use Propel\Runtime\Util\PropelModelPager;
@@ -16,10 +11,8 @@  discard block
 block discarded – undo
16 11
 use PSFS\base\dto\Order;
17 12
 use PSFS\base\Logger;
18 13
 use PSFS\base\Request;
19
-use PSFS\base\Security;
20 14
 use PSFS\base\Singleton;
21 15
 use PSFS\base\types\helpers\ApiHelper;
22
-use PSFS\base\types\helpers\Inspector;
23 16
 use PSFS\base\types\traits\Api\ManagerTrait;
24 17
 
25 18
 /**
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -81,15 +81,15 @@  discard block
 block discarded – undo
81 81
     public function init()
82 82
     {
83 83
         parent::init();
84
-        Logger::log(get_called_class() . ' init', LOG_DEBUG);
84
+        Logger::log(get_called_class().' init', LOG_DEBUG);
85 85
         $this->domain = $this->getDomain();
86 86
         $this->hydrateRequestData();
87 87
         $this->hydrateOrders();
88
-        if($this instanceof CustomApi === false) {
88
+        if ($this instanceof CustomApi === false) {
89 89
             $this->createConnection($this->getTableMap());
90 90
         }
91 91
         $this->setLoaded(true);
92
-        Logger::log(get_called_class() . ' loaded', LOG_DEBUG);
92
+        Logger::log(get_called_class().' loaded', LOG_DEBUG);
93 93
     }
94 94
 
95 95
     /**
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
     protected function hydrateOrders()
99 99
     {
100 100
         if (count($this->query)) {
101
-            Logger::log(get_called_class() . ' gathering query string', LOG_DEBUG);
101
+            Logger::log(get_called_class().' gathering query string', LOG_DEBUG);
102 102
             foreach ($this->query as $key => $value) {
103 103
                 if ($key === self::API_ORDER_FIELD && is_array($value)) {
104 104
                     foreach ($value as $field => $direction) {
@@ -115,10 +115,10 @@  discard block
 block discarded – undo
115 115
      */
116 116
     protected function extractPagination()
117 117
     {
118
-        Logger::log(get_called_class() . ' extract pagination start', LOG_DEBUG);
118
+        Logger::log(get_called_class().' extract pagination start', LOG_DEBUG);
119 119
         $page = (array_key_exists(self::API_PAGE_FIELD, $this->query)) ? $this->query[self::API_PAGE_FIELD] : 1;
120 120
         $limit = (array_key_exists(self::API_LIMIT_FIELD, $this->query)) ? $this->query[self::API_LIMIT_FIELD] : 100;
121
-        Logger::log(get_called_class() . ' extract pagination end', LOG_DEBUG);
121
+        Logger::log(get_called_class().' extract pagination end', LOG_DEBUG);
122 122
         return array($page, $limit);
123 123
     }
124 124
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
     private function addOrders(ModelCriteria &$query)
131 131
     {
132
-        Logger::log(get_called_class() . ' extract orders start ', LOG_DEBUG);
132
+        Logger::log(get_called_class().' extract orders start ', LOG_DEBUG);
133 133
         $orderAdded = FALSE;
134 134
         $tableMap = $this->getTableMap();
135 135
         foreach ($this->order->getOrders() as $field => $direction) {
@@ -137,17 +137,17 @@  discard block
 block discarded – undo
137 137
                 $orderAdded = TRUE;
138 138
                 if ($direction === Order::ASC) {
139 139
                     $query->addAscendingOrderByColumn($column->getPhpName());
140
-                } else {
140
+                }else {
141 141
                     $query->addDescendingOrderByColumn($column->getPhpName());
142 142
                 }
143 143
             }
144 144
         }
145 145
         if (!$orderAdded) {
146
-            foreach($this->getPkDbName() as $pk => $phpName) {
146
+            foreach ($this->getPkDbName() as $pk => $phpName) {
147 147
                 $query->addAscendingOrderByColumn($pk);
148 148
             }
149 149
         }
150
-        Logger::log(get_called_class() . ' extract orders end', LOG_DEBUG);
150
+        Logger::log(get_called_class().' extract orders end', LOG_DEBUG);
151 151
     }
152 152
 
153 153
     /**
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             foreach ($this->query as $field => $value) {
163 163
                 if (self::API_COMBO_FIELD === $field) {
164 164
                     ApiHelper::composerComboField($tableMap, $query, $this->extraColumns, $value);
165
-                } elseif(!preg_match('/^__/', $field)) {
165
+                } elseif (!preg_match('/^__/', $field)) {
166 166
                     ApiHelper::addModelField($tableMap, $query, $field, $value);
167 167
                 }
168 168
             }
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
             list($page, $limit) = $this->extractPagination();
184 184
             if ($limit == -1) {
185 185
                 $this->list = $query->find($this->con);
186
-            } else {
186
+            }else {
187 187
                 $this->list = $query->paginate($page, $limit, $this->con);
188 188
             }
189
-        } catch (\Exception $e) {
189
+        }catch (\Exception $e) {
190 190
             Logger::log($e->getMessage(), LOG_ERR);
191 191
         }
192 192
     }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         $code = 200;
206 206
         list($return, $total, $pages) = $this->getList();
207 207
         $message = null;
208
-        if(!$total) {
208
+        if (!$total) {
209 209
             $message = _('No se han encontrado elementos para la búsqueda');
210 210
         }
211 211
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
         $pages = 1;
232 232
         $message = null;
233 233
         list($code, $return) = $this->getSingleResult($pk);
234
-        if($code !== 200) {
234
+        if ($code !== 200) {
235 235
             $message = _('No se ha encontrado el elemento solicitado');
236 236
         }
237 237
 
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
                 $status = 200;
261 261
                 $saved = TRUE;
262 262
                 $model = $this->model->toArray();
263
-            } else {
263
+            }else {
264 264
                 $message = _('No se ha podido guardar el modelo seleccionado');
265 265
             }
266
-        } catch (\Exception $e) {
267
-            $message = _('Ha ocurrido un error intentando guardar el elemento: ') .'<br>'. $e->getMessage();
266
+        }catch (\Exception $e) {
267
+            $message = _('Ha ocurrido un error intentando guardar el elemento: ').'<br>'.$e->getMessage();
268 268
             Logger::log($e->getMessage(), LOG_ERR);
269 269
         }
270 270
 
@@ -298,14 +298,14 @@  discard block
 block discarded – undo
298 298
                     $updated = TRUE;
299 299
                     $status = 200;
300 300
                     $model = $this->model->toArray();
301
-                } else {
301
+                }else {
302 302
                     $message = _('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs');
303 303
                 }
304
-            } catch (\Exception $e) {
304
+            }catch (\Exception $e) {
305 305
                 $message = $e->getMessage();
306 306
                 Logger::getInstance(get_class($this->model))->errorLog($e->getMessage());
307 307
             }
308
-        } else {
308
+        }else {
309 309
             $message = _('No se ha encontrado el modelo al que se hace referencia para actualizar');
310 310
         }
311 311
 
@@ -333,13 +333,13 @@  discard block
 block discarded – undo
333 333
                 $this->con->beginTransaction();
334 334
                 $this->hydrateModel($pk);
335 335
                 if (NULL !== $this->model) {
336
-                    if(method_exists('clearAllReferences', $this->model)) {
336
+                    if (method_exists('clearAllReferences', $this->model)) {
337 337
                         $this->model->clearAllReferences(true);
338 338
                     }
339 339
                     $this->model->delete($this->con);
340 340
                     $deleted = TRUE;
341 341
                 }
342
-            } catch (\Exception $e) {
342
+            }catch (\Exception $e) {
343 343
                 $message = _('Ha ocurrido un error intentando eliminar el elemento, por favor verifica que no tenga otros elementos relacionados');
344 344
                 Logger::getInstance(get_class($this->model))->errorLog($e->getMessage());
345 345
             }
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
             $this->saveBulk();
368 368
             $saved = true;
369 369
             $status = 200;
370
-        } catch(\Exception $e) {
370
+        }catch (\Exception $e) {
371 371
             Logger::log($e->getMessage(), LOG_ERR, $this->getRequest()->getData());
372 372
             $message = _('Bulk insert rolled back');
373 373
         }
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 
390 390
         /** @var CustomerTableMap $tableMap */
391 391
         $modelPk = ApiHelper::extractPrimaryKeyColumnName($this->getTableMap());
392
-        foreach($this->list->getData() as $data) {
392
+        foreach ($this->list->getData() as $data) {
393 393
             $return[] = ApiHelper::mapArrayObject($this->getModelNamespace(), $modelPk, $this->query, $data);
394 394
         }
395 395
         return $return;
@@ -406,20 +406,20 @@  discard block
 block discarded – undo
406 406
         try {
407 407
             $this->paginate();
408 408
             if (null !== $this->list) {
409
-                if(array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) {
409
+                if (array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) {
410 410
                     $return = $this->extractDataWithFormat();
411
-                } else {
411
+                }else {
412 412
                     $return = $this->list->toArray(null, false, TableMap::TYPE_PHPNAME, false);
413 413
                 }
414 414
                 $total = 0;
415 415
                 $pages = 0;
416
-                if($this->list instanceof PropelModelPager) {
416
+                if ($this->list instanceof PropelModelPager) {
417 417
                     $total = $this->list->getNbResults();
418 418
                     $pages = $this->list->getLastPage();
419 419
                 }
420 420
             }
421
-        } catch (\Exception $e) {
422
-            Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR);
421
+        }catch (\Exception $e) {
422
+            Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR);
423 423
         }
424 424
 
425 425
         return array($return, $total, $pages);
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
         $return = array();
438 438
         if (NULL === $model || !method_exists($model, 'toArray')) {
439 439
             $code = 404;
440
-        } else {
440
+        }else {
441 441
             $return = $model->toArray();
442 442
         }
443 443
 
Please login to merge, or discard this patch.
src/base/types/traits/SystemTrait.php 2 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,6 @@
 block discarded – undo
3 3
 
4 4
 use PSFS\base\config\Config;
5 5
 use PSFS\base\Logger;
6
-use PSFS\base\Request;
7
-use PSFS\base\Router;
8 6
 
9 7
 /**
10 8
  * Class SystemTrait
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
                 $use /= 1024;
38 38
                 break;
39 39
             case "MBytes":
40
-                $use /= (1024 * 1024);
40
+                $use /= (1024*1024);
41 41
                 break;
42 42
             case "Bytes":
43 43
             default:
@@ -61,20 +61,20 @@  discard block
 block discarded – undo
61 61
     protected function bindWarningAsExceptions()
62 62
     {
63 63
         Logger::log('Added handlers for errors');
64
-        if(Config::getParam('debug')) {
64
+        if (Config::getParam('debug')) {
65 65
             Logger::log('Setting error_reporting as E_ALL');
66 66
             ini_set('error_reporting', E_ALL);
67 67
             ini_set('display_errors', 1);
68 68
         }
69 69
         //Warning & Notice handler
70
-        set_error_handler(function ($errno, $errstr, $errfile, $errline) {
70
+        set_error_handler(function($errno, $errstr, $errfile, $errline) {
71 71
             Logger::log($errstr, LOG_CRIT, ['file' => $errfile, 'line' => $errline, 'errno' => $errno]);
72 72
             return true;
73 73
         }, E_ALL | E_STRICT | E_DEPRECATED | E_USER_DEPRECATED);
74 74
 
75
-        register_shutdown_function(function () {
75
+        register_shutdown_function(function() {
76 76
             $error = error_get_last();
77
-            if( $error !== NULL) {
77
+            if ($error !== NULL) {
78 78
                 $errno   = $error["type"];
79 79
                 $errfile = $error["file"];
80 80
                 $errline = $error["line"];
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
         Logger::log('Initializing stats (mem + ts)');
95 95
         if (null !== $_SERVER && array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) {
96 96
             $this->ts = (float)$_SERVER['REQUEST_TIME_FLOAT'];
97
-        } else {
97
+        }else {
98 98
             $this->ts = PSFS_START_TS;
99 99
         }
100 100
         $this->mem = PSFS_START_MEM;
Please login to merge, or discard this patch.