Passed
Push — master ( 16f022...ac76b4 )
by Henri
01:51
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/WhereTrait.php 1 patch
Spacing   +15 added lines, -15 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
 
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
         $excepts = (is_array($excepts)) ? $excepts : [];
24 24
         
25 25
         $group = self::getInstance()->inSave()['group'];
26
-        foreach(self::getInstance()->getRoutes() as $r => $route){
27
-            if($route['group'] !== $group || in_array($route['name'], $excepts)) {
26
+        foreach (self::getInstance()->getRoutes() as $r => $route) {
27
+            if ($route['group'] !== $group || in_array($route['name'], $excepts)) {
28 28
                 continue;
29 29
             }
30 30
 
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
         unset($uriPath[0]);
50 50
 
51 51
         $corretRoute = true;
52
-        foreach ($routePath as $r => $routeFrag){
52
+        foreach ($routePath as $r => $routeFrag) {
53 53
             $where = is_array($route['where']) ? $route['where'] : [];
54 54
             $routeFrag = $this->replaceParam($where, $routeFrag, $uriPath[$r]);
55 55
 
56
-            if($routeFrag !== $uriPath[$r]) {
56
+            if ($routeFrag !== $uriPath[$r]) {
57 57
                 $corretRoute = false;
58 58
             }
59 59
         }
60 60
 
61
-        if(!$corretRoute) {
61
+        if (!$corretRoute) {
62 62
             throw new \Exception('continue');
63 63
         }
64 64
 
@@ -67,12 +67,12 @@  discard block
 block discarded – undo
67 67
 
68 68
     private function replaceParam(array $where, string $ref, string $value): string
69 69
     {
70
-        if(((substr($ref, 0, 1) === '{') && (substr($ref, strlen($ref)-1) === '}'))) {
71
-            $this->parameters[str_replace(['{?','{','}'], '', $ref)] = $value;
70
+        if (((substr($ref, 0, 1) === '{') && (substr($ref, strlen($ref)-1) === '}'))) {
71
+            $this->parameters[str_replace(['{?', '{', '}'], '', $ref)] = $value;
72 72
 
73 73
             $this->checkValueRequire($ref, $value);
74 74
 
75
-            if(array_key_exists(str_replace(['{?','{','}'], '', $ref), $where)) {
75
+            if (array_key_exists(str_replace(['{?', '{', '}'], '', $ref), $where)) {
76 76
                 $this->matchParam($where, $ref, $value);
77 77
             }
78 78
 
@@ -83,25 +83,25 @@  discard block
 block discarded – undo
83 83
 
84 84
     private function checkValueRequire(string $ref, string $value): void
85 85
     {
86
-        if(substr($ref, 0, 2) !== '{?' && strlen($value) === 0) {
86
+        if (substr($ref, 0, 2) !== '{?' && strlen($value) === 0) {
87 87
             throw new \Exception('continue');
88 88
         }
89 89
     }
90 90
 
91 91
     private function checkCount(string $routePath, string $uriPath): void
92 92
     {
93
-        $countRequest = substr_count($uriPath, '/') - substr_count($routePath, '{?');
94
-        $countRoute = substr_count($routePath, '/') - substr_count($routePath, '{?');
93
+        $countRequest = substr_count($uriPath, '/')-substr_count($routePath, '{?');
94
+        $countRoute = substr_count($routePath, '/')-substr_count($routePath, '{?');
95 95
 
96
-        if($countRequest !== $countRoute) {
96
+        if ($countRequest !== $countRoute) {
97 97
             throw new \Exception('continue');
98 98
         }
99 99
     }
100 100
 
101 101
     private function matchParam(array $where, string $ref, string $value): void
102 102
     {
103
-        if(substr($ref, 0, 2) === '{' || $value !== '') {
104
-            if(!preg_match("/^{$where[str_replace(['{?','{','}'],'',$ref)]}$/", $value)) {
103
+        if (substr($ref, 0, 2) === '{' || $value !== '') {
104
+            if (!preg_match("/^{$where[str_replace(['{?', '{', '}'], '', $ref)]}$/", $value)) {
105 105
                 throw new \Exception('continue');
106 106
             }
107 107
         }
Please login to merge, or discard this patch.
src/DefinitionsTrait.php 1 patch
Spacing   +5 added lines, -5 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
 
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 
57 57
     private static function set(string $method, string $uri, $closure): RouterInterface
58 58
     {   
59
-        $uri = (substr($uri, 0, 1) !=='/' and strlen($uri) > 0) ? "/{$uri}" : $uri;
59
+        $uri = (substr($uri, 0, 1) !== '/' and strlen($uri) > 0) ? "/{$uri}" : $uri;
60 60
         
61 61
         self::checkDuplicity($uri, $method);
62 62
         
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 
65 65
         $index = count($routes);
66 66
 
67
-        while(array_key_exists($index, $routes)){
67
+        while (array_key_exists($index, $routes)) {
68 68
             $index++;
69 69
         }
70 70
 
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
 
90 90
     private static function checkDuplicity(string $uri, string $method): void
91 91
     {
92
-        foreach(self::getInstance()->getRoutes() as $route){
93
-            if(md5(strtoupper(unserialize($route['uri'])->getPath().$route['method'])) === md5(strtoupper($uri.$method)) ) {
92
+        foreach (self::getInstance()->getRoutes() as $route) {
93
+            if (md5(strtoupper(unserialize($route['uri'])->getPath().$route['method'])) === md5(strtoupper($uri.$method))) {
94 94
                 throw new \RuntimeException("There is already a route with the URI {$uri} and with the {$method} METHOD configured.");
95 95
             }
96 96
         }
Please login to merge, or discard this patch.
src/MiddlewareTrait.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
 
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
 
23 23
     public static function globalMiddlewares(?array $middlewares = null): array
24 24
     {
25
-        if(null !== $middlewares) {
26
-            foreach($middlewares as $middleware){
27
-                if(!class_exists($middleware)) {
25
+        if (null !== $middlewares) {
26
+            foreach ($middlewares as $middleware) {
27
+                if (!class_exists($middleware)) {
28 28
                     throw new \RuntimeException("Middleware class {$middleware} not exists");
29 29
                 }
30 30
             }
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
     {
56 56
         $excepts = (is_array($excepts)) ? $excepts : [];
57 57
         $group = self::getInstance()->inSave()['group'];
58
-        foreach(self::getInstance()->getRoutes() as $r => $route){
59
-            if($route['group'] !== $group || in_array($route['name'], $excepts)) {
58
+        foreach (self::getInstance()->getRoutes() as $r => $route) {
59
+            if ($route['group'] !== $group || in_array($route['name'], $excepts)) {
60 60
                 continue;
61 61
             }
62 62
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 
69 69
     private static function existMiddleware(string $name): void
70 70
     {
71
-        if(!class_exists($name) && !array_key_exists($name, self::$globalMiddlewares)) {
71
+        if (!class_exists($name) && !array_key_exists($name, self::$globalMiddlewares)) {
72 72
             throw new \RuntimeException("Middleware {$name} does not exist");
73 73
         }
74 74
     }
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 
82 82
         $this->serverRequest = (!isset($this->serverRequest)) ? $factory->createServerRequest($requestMethod, unserialize($this->current()['uri']), ['route' => $this->current()]) : $this->serverRequest;
83 83
         
84
-        foreach ($this->current()['middlewares'] as $middleware){
84
+        foreach ($this->current()['middlewares'] as $middleware) {
85 85
             $this->currentMiddlewares[] = (class_exists($middleware)) ? new $middleware() : new $this->globalMiddlewares[$middleware]();
86 86
         }
87 87
 
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
 
99 99
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
100 100
     {
101
-        if(!$this->getInstance()->loaded()) {
101
+        if (!$this->getInstance()->loaded()) {
102 102
             $this->getInstance()->load();
103 103
         }
104 104
 
105 105
         $route = $this->getInstance()->current();
106
-        if(!empty($route)) {
106
+        if (!empty($route)) {
107 107
 
108
-            $route['action'] = function () {
108
+            $route['action'] = function() {
109 109
                 $this->getInstance()->executeBefore();
110 110
                 $this->getInstance()->executeRouteAction(unserialize($this->getInstance()->current()['action']));
111 111
                 $this->getInstance()->executeAfter();
Please login to merge, or discard this patch.