@@ -33,10 +33,13 @@ discard block |
||
33 | 33 | { |
34 | 34 | $result = []; |
35 | 35 | foreach ($needle as $key) { |
36 | - if ($haystack[$key] == null) Response::send(StatusCode::BAD_REQUEST, [ |
|
36 | + if ($haystack[$key] == null) { |
|
37 | + Response::send(StatusCode::BAD_REQUEST, [ |
|
37 | 38 | 'description' => sprintf("Bad Request: the '%s' parameter is required", $key) |
38 | 39 | ]); |
39 | - else $result[$key] = $haystack[$key]; |
|
40 | + } else { |
|
41 | + $result[$key] = $haystack[$key]; |
|
42 | + } |
|
40 | 43 | } |
41 | 44 | return $result; |
42 | 45 | } |
@@ -60,7 +63,9 @@ discard block |
||
60 | 63 | |
61 | 64 | if (is_array($body)) { |
62 | 65 | $message['ok'] = $status; |
63 | - if (!$status) $message['error_code'] = $statusCode; |
|
66 | + if (!$status) { |
|
67 | + $message['error_code'] = $statusCode; |
|
68 | + } |
|
64 | 69 | $message['elapsed_time'] = Time::elapsedTime() . "ms"; |
65 | 70 | |
66 | 71 | foreach ($body as $key => $value) { |
@@ -82,9 +87,11 @@ discard block |
||
82 | 87 | public static function EmptyParams(array $params = []): void |
83 | 88 | { |
84 | 89 | foreach ($params as $key => $value) { |
85 | - if ($value == null) Response::send(StatusCode::BAD_REQUEST, [ |
|
90 | + if ($value == null) { |
|
91 | + Response::send(StatusCode::BAD_REQUEST, [ |
|
86 | 92 | 'description' => sprintf("Bad Request: the '%s' parameter is empty", $key) |
87 | 93 | ]); |
94 | + } |
|
88 | 95 | } |
89 | 96 | } |
90 | 97 |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | foreach (Assistant::extractRouteAttributes($refMethod) as $route) { |
103 | 103 | $methodName = $refMethod->getName(); |
104 | 104 | $routeUri = $uri . $route->getUri(); |
105 | - Router::match($route->getMethod(), $routeUri, function (...$args) use ($controller, $methodName) { |
|
105 | + Router::match($route->getMethod(), $routeUri, function(...$args) use ($controller, $methodName) { |
|
106 | 106 | Assistant::passDataToMethod($controller, $methodName); |
107 | 107 | }); |
108 | 108 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $routeUri = $uri; |
116 | 116 | } |
117 | 117 | |
118 | - Router::any($routeUri, function (...$args) use ($controller, $methodName) { |
|
118 | + Router::any($routeUri, function(...$args) use ($controller, $methodName) { |
|
119 | 119 | Assistant::passDataToMethod($controller, $methodName); |
120 | 120 | }); |
121 | 121 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | } else { |
170 | 170 | $extension = pathinfo($filePath, PATHINFO_EXTENSION); |
171 | 171 | header('Content-Type: ' . PathFinder::getMimeType($extension)); |
172 | - self::get($uri . '/' . $file, function () use ($filePath) { |
|
172 | + self::get($uri . '/' . $file, function() use ($filePath) { |
|
173 | 173 | return file_get_contents($filePath); |
174 | 174 | }); |
175 | 175 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $find = self::find($_SERVER['REQUEST_URI']); |
215 | 215 | $params = $find !== false ? $find['params'] : []; |
216 | 216 | |
217 | - $headers = (function () { |
|
217 | + $headers = (function() { |
|
218 | 218 | $headers = []; |
219 | 219 | foreach ($_SERVER as $key => $value) { |
220 | 220 | if (str_starts_with($key, 'HTTP_')) { |
@@ -60,7 +60,7 @@ |
||
60 | 60 | |
61 | 61 | $last_runs = []; |
62 | 62 | $startTime = time(); |
63 | - Loop::run(function () use (&$last_runs, $startTime) { |
|
63 | + Loop::run(function() use (&$last_runs, $startTime) { |
|
64 | 64 | if (time() - $startTime > 60) { |
65 | 65 | Loop::stop(); |
66 | 66 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | ]); |
59 | 59 | } |
60 | 60 | |
61 | - Router::any('/execute-watchers', function () { |
|
61 | + Router::any('/execute-watchers', function() { |
|
62 | 62 | $this->runWatchers(); |
63 | 63 | }); |
64 | 64 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function resolve(array $options = []): void |
73 | 73 | { |
74 | - set_exception_handler(function (\Throwable $throwable) { |
|
74 | + set_exception_handler(function(\Throwable $throwable) { |
|
75 | 75 | $this->__exception($throwable); |
76 | 76 | die(500); |
77 | 77 | }); |
@@ -102,7 +102,7 @@ |
||
102 | 102 | )); |
103 | 103 | } |
104 | 104 | |
105 | - Router::match($route->getMethod(), $route->getUri(), function () use ($class, $method) { |
|
105 | + Router::match($route->getMethod(), $route->getUri(), function() use ($class, $method) { |
|
106 | 106 | Assistant::passDataToMethod($class, $method); |
107 | 107 | }); |
108 | 108 | } |
@@ -98,7 +98,7 @@ |
||
98 | 98 | |
99 | 99 | $last_runs = []; |
100 | 100 | $startTime = time(); |
101 | - Loop::run(function () use (&$last_runs, $startTime) { |
|
101 | + Loop::run(function() use (&$last_runs, $startTime) { |
|
102 | 102 | if (time() - $startTime > 60) { |
103 | 103 | Loop::stop(); |
104 | 104 | } |
@@ -10,7 +10,7 @@ |
||
10 | 10 | * @author Shahrad Elahi (https://github.com/shahradelahi) |
11 | 11 | * @license https://github.com/utilities-php/router/blob/master/LICENSE (MIT License) |
12 | 12 | */ |
13 | -#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)] |
|
13 | +#[\Attribute(\Attribute::TARGET_CLASS|\Attribute::TARGET_METHOD)] |
|
14 | 14 | class RateLimit |
15 | 15 | { |
16 | 16 |