Passed
Push — master ( 75e36f...df0cda )
by Henri
01:14
created
examples/index.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,11 +7,11 @@
 block discarded – undo
7 7
 
8 8
 /* NOTE: in case of error an exception is thrown */
9 9
 
10
-try{
10
+try {
11 11
     
12 12
     Router::create()->dispatch();
13 13
 
14
-}catch(Exception $er){
14
+}catch (Exception $er) {
15 15
 
16 16
     die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}.");
17 17
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
     
12 12
     Router::create()->dispatch();
13 13
 
14
-}catch(Exception $er){
14
+} catch(Exception $er){
15 15
 
16 16
     die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}.");
17 17
 
Please login to merge, or discard this patch.
src/Helper.php 3 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
 
71 71
         if( ( $this->getProtocol() == 'form') ){
72 72
             $this->ControllerForm($controller, $method, $data['POST']);
73
-        }else {
73
+        } else {
74 74
             $controller->$method($data);
75 75
         }
76 76
     }    
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
     }
34 34
 
35 35
     protected function ControllerForm($controller, string $method, array $values){
36
-		$this->check_role();
36
+        $this->check_role();
37 37
         $role = ($method !== 'method') ? $method : $this->getData()['POST']['role'];
38 38
         $data = (!is_null($values)) ? json_decode($values['data']) : null;
39 39
         $controller->$role($data);
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -2,13 +2,13 @@  discard block
 block discarded – undo
2 2
 
3 3
 namespace HnrAzevedo\Router;
4 4
 
5
-trait Helper{
5
+trait Helper {
6 6
     use CheckTrait, ControllerTrait;
7 7
     
8 8
     protected function getProtocol(): string
9 9
     {
10 10
         $protocol = ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')) ? 'ajax' : 'get';
11
-        $protocol = (array_key_existS('REQUEST_METHOD',$_SESSION)) ? strtolower($_SERVER['REQUEST_METHOD']) : $protocol;
11
+        $protocol = (array_key_existS('REQUEST_METHOD', $_SESSION)) ? strtolower($_SERVER['REQUEST_METHOD']) : $protocol;
12 12
             
13 13
         return $protocol;
14 14
     }
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
26 26
     protected function import(string $path)
27 27
     {
28 28
         foreach (scandir($path) as $routeFile) {
29
-            if(pathinfo($path.DIRECTORY_SEPARATOR.$routeFile, PATHINFO_EXTENSION) === 'php'){
30
-                require_once($path. DIRECTORY_SEPARATOR .$routeFile);
29
+            if (pathinfo($path.DIRECTORY_SEPARATOR.$routeFile, PATHINFO_EXTENSION) === 'php') {
30
+                require_once($path.DIRECTORY_SEPARATOR.$routeFile);
31 31
             }
32 32
         }
33 33
     }
34 34
 
35
-    protected function ControllerForm($controller, string $method, array $values){
35
+    protected function ControllerForm($controller, string $method, array $values) {
36 36
 		$this->check_role();
37 37
         $role = ($method !== 'method') ? $method : $this->getData()['POST']['role'];
38 38
         $data = (!is_null($values)) ? json_decode($values['data']) : null;
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
         $data = $this->getData();
45 45
 
46 46
         foreach ($data['GET'] as $name => $value) {
47
-            $controll = str_replace('{'.$name.'}',$value,$controll);
47
+            $controll = str_replace('{'.$name.'}', $value, $controll);
48 48
         }
49 49
 
50 50
         $this->check_controllsettable($controll);
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 
54 54
         $this->check_controllmethod($controll);
55 55
 
56
-        $controller = ROUTER_CONFIG['controller.namespace'].'\\'. ucfirst(explode(':',$controll)[0]);
56
+        $controller = ROUTER_CONFIG['controller.namespace'].'\\'.ucfirst(explode(':', $controll)[0]);
57 57
         $controller = new $controller();
58
-        $method = explode(':',$controll)[1];
58
+        $method = explode(':', $controll)[1];
59 59
 
60
-        if( ( $this->getProtocol() == 'form') ){
60
+        if (($this->getProtocol() == 'form')) {
61 61
             $this->ControllerForm($controller, $method, $data['POST']);
62 62
         }else {
63 63
             $controller->$method($data);
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 
67 67
     protected function explodeRoute(bool $bar, string $url): array
68 68
     {   
69
-        return explode( '/', $bar ? substr($url, 0, -1) : $url );
69
+        return explode('/', $bar ? substr($url, 0, -1) : $url);
70 70
     }
71 71
 
72 72
     protected function toHiking($walking)
73 73
     {
74
-        if(is_string($walking)){
74
+        if (is_string($walking)) {
75 75
             $this->Controller($walking);
76 76
             return true;
77 77
         }
Please login to merge, or discard this patch.
src/Router.php 3 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -217,7 +217,7 @@
 block discarded – undo
217 217
             foreach ($route['filters'] as $key => $value) {
218 218
                 $filters[] = $value;
219 219
             }
220
-        }else{
220
+        } else{
221 221
             $filters[] = $route['filters'];
222 222
         }
223 223
 
Please login to merge, or discard this patch.
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -61,25 +61,25 @@  discard block
 block discarded – undo
61 61
 
62 62
     public function set($url ,$walking , string $protocol): Router
63 63
     {
64
-		$url = (substr($url,0,1) !=='/' and strlen($url) > 0) ? "/{$url}" : $url;
64
+        $url = (substr($url,0,1) !=='/' and strlen($url) > 0) ? "/{$url}" : $url;
65 65
 
66
-    	foreach($this->routers as $key => $value){
67
-    		if( md5($this->prefix . $value['url'] . $value['protocol'] ) === md5( $url . $protocol ) ){
66
+        foreach($this->routers as $key => $value){
67
+            if( md5($this->prefix . $value['url'] . $value['protocol'] ) === md5( $url . $protocol ) ){
68 68
                 throw new Exception("There is already a route with the url {$url} and with the {$protocol} protocol configured.");
69 69
             }
70 70
         }
71 71
         
72 72
         $this->check_typeRole($walking);
73 73
 
74
-		$route = [
75
-			'url' => $this->prefix.$url,
76
-			'role' => $walking,
77
-			'protocol' => $protocol,
78
-			'filters' => null,
74
+        $route = [
75
+            'url' => $this->prefix.$url,
76
+            'role' => $walking,
77
+            'protocol' => $protocol,
78
+            'filters' => null,
79 79
             'group' => self::getInstance()->group
80
-		];
80
+        ];
81 81
 
82
-		$this->routers[] = $route;		
82
+        $this->routers[] = $route;		
83 83
         
84 84
         return self::getInstance();
85 85
     }
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
     {
141 141
         $this->byName($route_name);
142 142
 
143
-		$currentProtocol = $this->getProtocol();
143
+        $currentProtocol = $this->getProtocol();
144 144
 
145 145
         foreach(array_reverse($this->routers) as $r => $route){
146 146
 
@@ -156,19 +156,19 @@  discard block
 block discarded – undo
156 156
 
157 157
             $route_request = $this->explodeRoute((substr($_SERVER['REQUEST_URI'],strlen($_SERVER['REQUEST_URI'])-1,1) === '/') , $_SERVER['REQUEST_URI']);
158 158
 
159
-	        if($this->check_numparams($route_loop, $route_request) || !$this->check_parameters($route_loop, $route_request)){
159
+            if($this->check_numparams($route_loop, $route_request) || !$this->check_parameters($route_loop, $route_request)){
160 160
                 continue;
161 161
             }
162 162
             
163 163
             $this->check_filtering($route);
164 164
 
165 165
             $this->toHiking($route['role']);
166
-	        return true;
166
+            return true;
167 167
         }
168 168
         
169 169
         unset($_SESSION['route']);
170 170
 
171
-	    throw new Exception('Page not found.',404);
171
+        throw new Exception('Page not found.',404);
172 172
     }
173 173
 
174 174
     public static function filter($filters): Router
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 
7
-class Router{
7
+class Router {
8 8
     use Helper, CheckTrait;
9 9
 
10 10
     private static $instance = null;
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
         return self::getInstance()->set($uri, $walking, $protocol);
60 60
     }
61 61
 
62
-    public function set($url ,$walking , string $protocol): Router
62
+    public function set($url, $walking, string $protocol): Router
63 63
     {
64
-		$url = (substr($url,0,1) !=='/' and strlen($url) > 0) ? "/{$url}" : $url;
64
+		$url = (substr($url, 0, 1) !== '/' and strlen($url) > 0) ? "/{$url}" : $url;
65 65
 
66
-    	foreach($this->routers as $key => $value){
67
-    		if( md5($this->prefix . $value['url'] . $value['protocol'] ) === md5( $url . $protocol ) ){
66
+    	foreach ($this->routers as $key => $value) {
67
+    		if (md5($this->prefix.$value['url'].$value['protocol']) === md5($url.$protocol)) {
68 68
                 throw new Exception("There is already a route with the url {$url} and with the {$protocol} protocol configured.");
69 69
             }
70 70
         }
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
         return self::getInstance();
85 85
     }
86 86
 
87
-    public static function group(string $prefix,$callback): Router
87
+    public static function group(string $prefix, $callback): Router
88 88
     {
89
-        self::getInstance()->prefix = (substr($prefix,0,1) !== '/') ? "/{$prefix}" : $prefix;
89
+        self::getInstance()->prefix = (substr($prefix, 0, 1) !== '/') ? "/{$prefix}" : $prefix;
90 90
         self::getInstance()->group = sha1(date('d/m/Y h:m:i'));
91 91
         $callback();
92 92
         self::getInstance()->group = null;
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
 
98 98
     public static function name(string $name): Router
99 99
     {
100
-        if(self::getInstance()->lastReturn){
100
+        if (self::getInstance()->lastReturn) {
101 101
             throw new Exception("There is no reason to call a {$name} route group.");
102 102
         }
103 103
 
104 104
         $currentRoute = end(self::getInstance()->routers);
105 105
 
106
-        foreach(self::getInstance()->routers as $key => $value){
107
-            if(array_key_exists($name, self::getInstance()->routers)){
106
+        foreach (self::getInstance()->routers as $key => $value) {
107
+            if (array_key_exists($name, self::getInstance()->routers)) {
108 108
                 throw new Exception("There is already a route with the name {$name} configured.");
109 109
             }
110 110
         }
@@ -120,15 +120,15 @@  discard block
 block discarded – undo
120 120
 
121 121
     private function byName(?string $route_name)
122 122
     {
123
-        if(!is_null($route_name)){
123
+        if (!is_null($route_name)) {
124 124
             $currentProtocol = $this->getProtocol();
125 125
 
126 126
             $this->check_name($route_name);
127 127
     
128 128
             $route = $this->routers[$route_name];
129 129
     
130
-            if(!$this->check_protocol($route['protocol'], $currentProtocol)){
131
-                throw new Exception('Page not found.',404);
130
+            if (!$this->check_protocol($route['protocol'], $currentProtocol)) {
131
+                throw new Exception('Page not found.', 404);
132 132
             }
133 133
     
134 134
             $this->check_filtering($route);
@@ -144,23 +144,23 @@  discard block
 block discarded – undo
144 144
 
145 145
 		$currentProtocol = $this->getProtocol();
146 146
 
147
-        foreach(array_reverse($this->routers) as $r => $route){
147
+        foreach (array_reverse($this->routers) as $r => $route) {
148 148
 
149 149
             $_SESSION['route'] = serialize($route);
150 150
 
151
-            if(!$this->check_protocol($route['protocol'], $currentProtocol)){
151
+            if (!$this->check_protocol($route['protocol'], $currentProtocol)) {
152 152
                 continue;
153 153
             }
154 154
 
155 155
             $this->hasProtocol($route, $currentProtocol);
156 156
 
157
-            $route_loop = $this->explodeRoute( (substr($route['url'],strlen($route['url'])-1,1) === '/') , $route['url']);
157
+            $route_loop = $this->explodeRoute((substr($route['url'], strlen($route['url'])-1, 1) === '/'), $route['url']);
158 158
             
159 159
             $_SERVER['REQUEST_URI'] = (array_key_exists('REQUEST_URI', $_SERVER)) ? $_SERVER['REQUEST_URI'] : '';
160 160
 
161
-            $route_request = $this->explodeRoute((substr($_SERVER['REQUEST_URI'],strlen($_SERVER['REQUEST_URI'])-1,1) === '/') , $_SERVER['REQUEST_URI']);
161
+            $route_request = $this->explodeRoute((substr($_SERVER['REQUEST_URI'], strlen($_SERVER['REQUEST_URI'])-1, 1) === '/'), $_SERVER['REQUEST_URI']);
162 162
 
163
-	        if($this->check_numparams($route_loop, $route_request) || !$this->check_parameters($route_loop, $route_request)){
163
+	        if ($this->check_numparams($route_loop, $route_request) || !$this->check_parameters($route_loop, $route_request)) {
164 164
                 continue;
165 165
             }
166 166
             
@@ -172,18 +172,18 @@  discard block
 block discarded – undo
172 172
         
173 173
         unset($_SESSION['route']);
174 174
 
175
-	    throw new Exception('Page not found.',404);
175
+	    throw new Exception('Page not found.', 404);
176 176
     }
177 177
 
178 178
     public static function filter($filters): Router
179 179
     {
180
-        if(self::getInstance()->lastReturn !== null){
180
+        if (self::getInstance()->lastReturn !== null) {
181 181
             $currentGroup = end(self::getInstance()->routers)['group'];
182 182
 
183 183
             foreach (self::getInstance()->routers as $key => $value) {
184 184
 
185
-                if($value['group'] === $currentGroup){
186
-                    $currentRoute = self::getInstance()->addFilter(self::getInstance()->routers[$key],$filters);
185
+                if ($value['group'] === $currentGroup) {
186
+                    $currentRoute = self::getInstance()->addFilter(self::getInstance()->routers[$key], $filters);
187 187
                     self::getInstance()->routers[$key] = $currentRoute;
188 188
                 }
189 189
 
@@ -194,24 +194,24 @@  discard block
 block discarded – undo
194 194
             return self::getInstance();
195 195
         }
196 196
         
197
-        self::getInstance()->routers[count(self::getInstance()->routers)-1] = self::getInstance()->addFilter(end(self::getInstance()->routers),$filters);
197
+        self::getInstance()->routers[count(self::getInstance()->routers)-1] = self::getInstance()->addFilter(end(self::getInstance()->routers), $filters);
198 198
         return self::getInstance();
199 199
     }
200 200
 
201 201
     public static function addFilter(array $route, $filter): array
202 202
     {
203
-        if(is_null($route['filters'])){
203
+        if (is_null($route['filters'])) {
204 204
             $route['filters'] = $filter;
205 205
             return $route;
206 206
         }
207 207
 
208 208
         $filters = (is_array($filter)) ? $filter : [0 => $filter];
209 209
 
210
-        if(is_array($route['filters'])){
210
+        if (is_array($route['filters'])) {
211 211
             foreach ($route['filters'] as $key => $value) {
212 212
                 $filters[] = $value;
213 213
             }
214
-        }else{
214
+        }else {
215 215
             $filters[] = $route['filters'];
216 216
         }
217 217
 
Please login to merge, or discard this patch.
examples/Filters/User.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,15 +2,15 @@
 block discarded – undo
2 2
 
3 3
 namespace HnrAzevedo\Filter;
4 4
 
5
-class User extends Filter{
5
+class User extends Filter {
6 6
 
7 7
     public function user_in(): bool
8 8
     {
9
-        $this->addMessage('user_in','User required to be logged in.');
9
+        $this->addMessage('user_in', 'User required to be logged in.');
10 10
 
11
-        $this->addTreat('user_in','report_notLogged');
11
+        $this->addTreat('user_in', 'report_notLogged');
12 12
 
13
-        return (array_key_exists('user',$_SESSION));
13
+        return (array_key_exists('user', $_SESSION));
14 14
     }
15 15
 
16 16
     public function report_notLogged(): void
Please login to merge, or discard this patch.
src/ControllerTrait.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -4,28 +4,28 @@
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 
7
-trait ControllerTrait{
7
+trait ControllerTrait {
8 8
 
9 9
     protected function check_controllsettable(string $controll)
10 10
     {
11
-        if(count(explode(':',$controll)) != 2){
11
+        if (count(explode(':', $controll)) != 2) {
12 12
             throw new Exception("Controller {$controll} badly set.");
13 13
         }
14 14
     }
15 15
 
16 16
     protected function check_controllexist(string $controll)
17 17
     {
18
-        $controllname = ROUTER_CONFIG['controller.namespace'].'\\'.ucfirst(explode(':',$controll)[0]);
19
-        if(!class_exists($controllname)){
18
+        $controllname = ROUTER_CONFIG['controller.namespace'].'\\'.ucfirst(explode(':', $controll)[0]);
19
+        if (!class_exists($controllname)) {
20 20
             throw new Exception("No controller {$controllname} found.");
21 21
         }
22 22
     }
23 23
 
24 24
     protected function check_controllmethod(string $controll)
25 25
     {
26
-        $controllname = ROUTER_CONFIG['controller.namespace'].'\\'.ucfirst(explode(':',$controll)[0]);
27
-        $method = explode(':',$controll)[1];
28
-        if(!method_exists($controllname, $method)){
26
+        $controllname = ROUTER_CONFIG['controller.namespace'].'\\'.ucfirst(explode(':', $controll)[0]);
27
+        $method = explode(':', $controll)[1];
28
+        if (!method_exists($controllname, $method)) {
29 29
             throw new Exception("No method {$method} found for {$controllname}.");
30 30
         }
31 31
     }
Please login to merge, or discard this patch.
examples/Routes/default.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -3,30 +3,30 @@
 block discarded – undo
3 3
 use HnrAzevedo\Router\Router;
4 4
 
5 5
 
6
-Router::get('/{teste}',function(){
6
+Router::get('/{teste}', function() {
7 7
     echo 'teste';
8 8
 });
9 9
 
10
-Router::get('/1',function(){
10
+Router::get('/1', function() {
11 11
     echo 1;
12 12
 });
13 13
 
14
-Router::get('/3',function(){
14
+Router::get('/3', function() {
15 15
     echo 3;
16 16
 });
17 17
 
18 18
 /* Returning parameters passed via URL in anonymous functions */
19
-Router::get('/{parameter}/{otherparameter}', function($data){
19
+Router::get('/{parameter}/{otherparameter}', function($data) {
20 20
     echo "Parameter 1:{$data['parameter']}, Parameter 2:{$data['otherparameter']}.";
21 21
 });
22 22
 
23 23
 /* Passing controller and/or method via parameter in URL */
24
-Router::get('/{controller}/{method}','{controller}:{method}');
24
+Router::get('/{controller}/{method}', '{controller}:{method}');
25 25
 
26 26
 /* Passing value via parameter */
27
-Router::get('/my-account/{teste}','User:my_account');
27
+Router::get('/my-account/{teste}', 'User:my_account');
28 28
 
29 29
 /* Filter example */
30
-Router::get('/my-account','User:my_account')->filter('User:user_in');
30
+Router::get('/my-account', 'User:my_account')->filter('User:user_in');
31 31
 
32 32
 
Please login to merge, or discard this patch.
examples/Controllers/User.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use HnrAzevedo\Router\Controller;
6 6
 
7
-class User extends Controller{
7
+class User extends Controller {
8 8
 
9 9
     public function my_account(array $data): void
10 10
     {
Please login to merge, or discard this patch.
src/FilterTrait.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -4,13 +4,13 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 
7
-trait FilterTrait{
7
+trait FilterTrait {
8 8
     protected function check_filtering(array $route)
9 9
     {
10
-        $filters = (is_array($route['filters'])) ? $route['filters'] : [ $route['filters'] ];
10
+        $filters = (is_array($route['filters'])) ? $route['filters'] : [$route['filters']];
11 11
 
12
-        foreach($filters as $filter){
13
-            if(is_null($filter)){
12
+        foreach ($filters as $filter) {
13
+            if (is_null($filter)) {
14 14
                 continue;
15 15
             }
16 16
             $this->check_filter($filter);
@@ -19,24 +19,24 @@  discard block
 block discarded – undo
19 19
 
20 20
     protected function check_filter(string $filtername)
21 21
     {
22
-        if(count(explode(':',$filtername)) != 2){
22
+        if (count(explode(':', $filtername)) != 2) {
23 23
             throw new Exception("Wrongly configured filter: {$filtername}.");
24 24
         }
25 25
 
26
-        $filter = $this->check_filClassExist(explode(':',$filtername)[0]);
26
+        $filter = $this->check_filClassExist(explode(':', $filtername)[0]);
27 27
 
28
-        if(!$filter->check(explode(':',$filtername)[1])){
29
-            throw new Exception($filter->getMessage(explode(':',$filtername)[1]));
28
+        if (!$filter->check(explode(':', $filtername)[1])) {
29
+            throw new Exception($filter->getMessage(explode(':', $filtername)[1]));
30 30
         }
31 31
     }
32 32
 
33 33
     protected function check_filClassExist(string $class)
34 34
     {
35
-        if(class_exists(ROUTER_CONFIG['filter.namespace']."\\{$class}")){
35
+        if (class_exists(ROUTER_CONFIG['filter.namespace']."\\{$class}")) {
36 36
             $filter = ROUTER_CONFIG['filter.namespace']."\\{$class}";
37 37
             return new $filter();
38 38
         }
39
-        if(file_exists(ROUTER_CONFIG['path.filters'].$class.'.php')){
39
+        if (file_exists(ROUTER_CONFIG['path.filters'].$class.'.php')) {
40 40
             require_once(ROUTER_CONFIG['path.filters'].$class.'.php');
41 41
             $filter = ROUTER_CONFIG['filter.namespace']."\\{$class}";
42 42
             return new $filter();
Please login to merge, or discard this patch.
src/Controller.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -5,14 +5,14 @@  discard block
 block discarded – undo
5 5
 use HnrAzevedo\Validator\Validator;
6 6
 use Exception;
7 7
 
8
-class Controller{
8
+class Controller {
9 9
     use Helper;
10 10
 
11 11
     protected array $fail = [];
12 12
 
13 13
     private function check_method(string $method): void
14 14
     {
15
-        if(!method_exists($this,$method)){
15
+        if (!method_exists($this, $method)) {
16 16
             throw new Exception("{$method} not found in ".get_class($this).".");
17 17
         }
18 18
     }
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
     {        
22 22
         $this->ValidateData();
23 23
 
24
-        if($this->check_failData()){
24
+        if ($this->check_failData()) {
25 25
             return false;
26 26
         }
27 27
 
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
     {
39 39
         $valid = Validator::execute($this->getData()['POST']);
40 40
 
41
-        if(!$valid){
42
-            foreach(Validator::getErrors() as $err => $message){
41
+        if (!$valid) {
42
+            foreach (Validator::getErrors() as $err => $message) {
43 43
                 $this->fail[] = [
44 44
                     'input' => array_keys($message)[0],
45 45
                     'message' => $message[array_keys($message)[0]]
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
 
51 51
     private function check_failData(): bool
52 52
     {
53
-        if(count($this->fail) > 0 ){
53
+        if (count($this->fail) > 0) {
54 54
             echo json_encode([
55 55
                 'error'=> $this->fail
56 56
             ]);
57 57
         }
58
-        return (count($this->fail) > 0 );
58
+        return (count($this->fail) > 0);
59 59
     }
60 60
 
61 61
 }
62 62
\ No newline at end of file
Please login to merge, or discard this patch.