Passed
Push — master ( 18e951...67611c )
by Henri
01:38
created
examples/Middleware/Middleware.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -8,23 +8,23 @@
 block discarded – undo
8 8
 use Psr\Http\Server\MiddlewareInterface;
9 9
 use Psr\Http\Server\RequestHandlerInterface;
10 10
 
11
-class Middleware implements MiddlewareInterface{
11
+class Middleware implements MiddlewareInterface {
12 12
     protected static array $data = [];
13 13
     protected static Response $response;
14 14
 
15 15
     public function __get($key)
16 16
     {
17
-        return (array_key_exists($key,self::$data)) ? self::$data[$key] : null;
17
+        return (array_key_exists($key, self::$data)) ? self::$data[$key] : null;
18 18
     }
19 19
 
20
-    public function __set($key,$value)
20
+    public function __set($key, $value)
21 21
     {
22 22
         self::$data[$key] = $value;
23 23
     }
24 24
 
25 25
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
26 26
     {
27
-        if(!isset(self::$response)){
27
+        if (!isset(self::$response)) {
28 28
             self::$response = new Response();
29 29
         }
30 30
         return self::$response;
Please login to merge, or discard this patch.
examples/Middleware/Lasted.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,11 +10,11 @@
 block discarded – undo
10 10
 /** 
11 11
   * @property string $error
12 12
   */ 
13
-class Lasted extends Middleware{
13
+class Lasted extends Middleware {
14 14
 
15 15
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
16 16
     {
17
-        if(!isset($this->error)){
17
+        if (!isset($this->error)) {
18 18
             throw new Exception("Access not belonged: {$this->error}");
19 19
         }
20 20
 
Please login to merge, or discard this patch.
examples/Middleware/Auth.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,11 +9,11 @@
 block discarded – undo
9 9
 /** 
10 10
   * @property string $error
11 11
   */ 
12
-class Auth extends Middleware{
12
+class Auth extends Middleware {
13 13
 
14 14
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
15 15
     {
16
-        if(!array_key_exists('user',$_SESSION)){
16
+        if (!array_key_exists('user', $_SESSION)) {
17 17
             $this->error = 'The user must be logged in to the system';
18 18
         }
19 19
 
Please login to merge, or discard this patch.
examples/DefaultUseExample.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 use HnrAzevedo\Router\Router;
9 9
 
10
-try{
10
+try {
11 11
 
12 12
     Router::defineHost('https://localhost');
13 13
     
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      */ 
29 29
     $action = Router::currentAction();
30 30
 
31
-}catch(Exception $er){
31
+}catch (Exception $er) {
32 32
 
33 33
     die("Code Error: {$er->getCode()}<br>Line: {$er->getLine()}<br>File: {$er->getFile()}<br>Message: {$er->getMessage()}.");
34 34
 
Please login to merge, or discard this patch.
src/Helper.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace HnrAzevedo\Router;
6 6
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 
55 55
     protected function setRoutes(array $routes): void
56 56
     {
57
-        $this->routes =  $routes;
57
+        $this->routes = $routes;
58 58
     }
59 59
 
60 60
     protected function getGroup(): ?string
Please login to merge, or discard this patch.
src/CurrentTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace HnrAzevedo\Router;
6 6
 
Please login to merge, or discard this patch.
src/OwnerTrait.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace HnrAzevedo\Router;
6 6
 
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     {
20 20
         $this->hasRouteName($name);
21 21
 
22
-        if(!$this->loaded()){
22
+        if (!$this->loaded()) {
23 23
             $this->loadIn($name);
24 24
         }
25 25
         
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 
29 29
     public function hasCurrentRoute(): void
30 30
     {
31
-        if(!isset($this->currentRoute)){
31
+        if (!isset($this->currentRoute)) {
32 32
             throw new \RuntimeException('Route not yet loaded');
33 33
         }
34 34
     }
Please login to merge, or discard this patch.
src/PrioritizeTrait.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace HnrAzevedo\Router;
6 6
 
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
     protected function sorted(?bool $sorted = null): bool
14 14
     {
15
-        if(null !== $sorted){
15
+        if (null !== $sorted) {
16 16
             $this->sorted = $sorted;
17 17
         }
18 18
         return $this->sorted;
@@ -20,35 +20,35 @@  discard block
 block discarded – undo
20 20
     
21 21
     protected function sortRoutes(): bool
22 22
     {
23
-        if($this->sorted()){
23
+        if ($this->sorted()) {
24 24
             return true;
25 25
         }
26 26
 
27 27
         $staticRoutes = [];
28 28
         $paramRoutes = [];
29 29
 
30
-        foreach($this->getRoutes() as $r => $route){
30
+        foreach ($this->getRoutes() as $r => $route) {
31 31
 
32 32
             $path = urldecode(unserialize($route['uri'])->getPath());
33 33
 
34
-            if(strstr($path,'{')){
35
-                $paramRoutes[$this->getKeyArray(substr_count($path,'/') + substr_count($path,'{'),$paramRoutes)] = $route;
34
+            if (strstr($path, '{')) {
35
+                $paramRoutes[$this->getKeyArray(substr_count($path, '/')+substr_count($path, '{'), $paramRoutes)] = $route;
36 36
                 continue;    
37 37
             }
38 38
 
39
-            $staticRoutes[$this->getKeyArray(substr_count($path,'/'),$staticRoutes)] = $route;
39
+            $staticRoutes[$this->getKeyArray(substr_count($path, '/'), $staticRoutes)] = $route;
40 40
         }
41 41
 
42 42
         rsort($paramRoutes);
43 43
         rsort($staticRoutes);
44 44
 
45
-        $this->orderRoutes(array_merge($staticRoutes,$paramRoutes));
45
+        $this->orderRoutes(array_merge($staticRoutes, $paramRoutes));
46 46
         return $this->sorted(true);
47 47
     }
48 48
 
49 49
     private function getKeyArray(int $index, array $array): int
50 50
     {
51
-        while(array_key_exists($index,$array)){
51
+        while (array_key_exists($index, $array)) {
52 52
             $index++;
53 53
         }
54 54
         return $index;
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
     private function orderRoutes(array $routes):void
58 58
     {
59 59
         $kRoutes = $routes;
60
-        foreach($routes as $r => $route){
61
-            if(array_key_exists('name',$route)){
60
+        foreach ($routes as $r => $route) {
61
+            if (array_key_exists('name', $route)) {
62 62
                 unset($kRoutes[$r]);
63 63
                 $kRoutes["'{$route['name']}'"] = $route;
64 64
             }
Please login to merge, or discard this patch.
src/CheckTrait.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace HnrAzevedo\Router;
6 6
 
@@ -12,28 +12,28 @@  discard block
 block discarded – undo
12 12
     
13 13
     protected function hasRouteName(string $name): void
14 14
     {
15
-        if(!isset($this->routesName[$name])){
15
+        if (!isset($this->routesName[$name])) {
16 16
             throw new \RuntimeException("There is no route named with {$name}");
17 17
         }
18 18
     }
19 19
 
20 20
     protected function isInNameGroup(): void
21 21
     {
22
-        if(!is_null($this->getGroup())){
22
+        if (!is_null($this->getGroup())) {
23 23
             throw new \RuntimeException("It is not allowed to assign names to groups");
24 24
         }
25 25
     }
26 26
 
27 27
     protected function isInPseudGroup(): void
28 28
     {
29
-        if(!is_null($this->getGroup())){
29
+        if (!is_null($this->getGroup())) {
30 30
             throw new \RuntimeException("To assign actions before or after the execution of the route, use beforeGroup or afterGroup");
31 31
         }
32 32
     }
33 33
 
34 34
     protected function existRouteName(string $name): void
35 35
     {
36
-        if(isset($this->routesName[$name])){
36
+        if (isset($this->routesName[$name])) {
37 37
             throw new \RuntimeException("There is already a route named with {$name}");
38 38
         }
39 39
     }
@@ -41,19 +41,19 @@  discard block
 block discarded – undo
41 41
     protected function checkMethod(array $route, $method): void
42 42
     {
43 43
         $hasMethod = false;
44
-        foreach(explode('|',$route['method']) as $routeMethod){
45
-            if(@preg_match("/{$routeMethod}/",$method) !== 0 || $method === '*'){
44
+        foreach (explode('|', $route['method']) as $routeMethod) {
45
+            if (@preg_match("/{$routeMethod}/", $method) !== 0 || $method === '*') {
46 46
                 $hasMethod = true;
47 47
             }
48 48
         }
49
-        if(!$hasMethod){
49
+        if (!$hasMethod) {
50 50
             throw new \Exception('This route is not released for the accessed method');
51 51
         } 
52 52
     }
53 53
 
54 54
     protected function throwCallable($value): void
55 55
     {
56
-        if(is_callable($value)){
56
+        if (is_callable($value)) {
57 57
             throw new \Exception('Passing functions as attributes is not allowed');
58 58
         }
59 59
     }
Please login to merge, or discard this patch.