diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results index 722ec3d..2f06690 100644 --- a/.phpunit.cache/test-results +++ b/.phpunit.cache/test-results @@ -1 +1 @@ -{"version":2,"defects":[],"times":{"Tests\\Api\\OneTest::testConfigs":6.205,"Tests\\Api\\OneTest::testIndex":0.195,"Tests\\Api\\OneTest::testAbout":0.04,"Tests\\Api\\OneTest::testNotFound":0.038}} \ No newline at end of file +{"version":2,"defects":[],"times":{"Tests\\Api\\OneTest::testConfigs":3.588,"Tests\\Api\\OneTest::testIndex":0.139,"Tests\\Api\\OneTest::testAbout":0.043,"Tests\\Api\\OneTest::testNotFound":0.031}} \ No newline at end of file diff --git a/App.php b/App.php index 5af289a..68f7dbe 100644 --- a/App.php +++ b/App.php @@ -1,2 +1,10 @@ 'API is running.', @@ -21,7 +21,7 @@ public function index(): Response ]); } - public function about(): Response + public function about() : Response { return success_response([ 'message' => 'API project powered by Webisters framework.', @@ -29,8 +29,8 @@ public function about(): Response ]); } - public function notFound(): Response + public function notFound() : Response { return respond_not_found(); } -} \ No newline at end of file +} diff --git a/app/Languages/en/home.php b/app/Languages/en/home.php index 8b4e8ed..14c0b31 100644 --- a/app/Languages/en/home.php +++ b/app/Languages/en/home.php @@ -1,6 +1,6 @@ setStatusCode($code); - + foreach ($headers as $name => $value) { $response->setHeader($name, $value); } - + $response->setHeader('Content-Type', 'application/json; charset=UTF-8'); $response->setBody(json_encode($data, \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT)); - + return $response; } @@ -85,18 +84,18 @@ function json_response($data, int $code = 200, array $headers = []): Response * * @return Response */ -function error_response(string $message, int $code = 400, $details = null): Response +function error_response(string $message, int $code = 400, $details = null) : Response { $data = [ 'success' => false, 'message' => $message, 'code' => $code, ]; - + if ($details !== null) { $data['details'] = $details; } - + return json_response($data, $code); } @@ -109,17 +108,17 @@ function error_response(string $message, int $code = 400, $details = null): Resp * * @return Response */ -function success_response($data, int $code = 200, ?string $message = null): Response +function success_response($data, int $code = 200, ?string $message = null) : Response { $response = [ 'success' => true, 'data' => $data, ]; - + if ($message !== null) { $response['message'] = $message; } - + return json_response($response, $code); } @@ -129,7 +128,7 @@ function success_response($data, int $code = 200, ?string $message = null): Resp * @return string */ if (!function_exists('current_url')) { - function current_url(): string + function current_url() : string { return App::request()->getUrl()->toString(); } @@ -163,7 +162,7 @@ function env(string $key, $default = null) * @return Response */ if (!function_exists('respond_not_found')) { - function respond_not_found(): Response + function respond_not_found() : Response { return error_response('Not Found', 404, [ 'path' => App::request()->getUrl()->getPath(), diff --git a/boot/routes.php b/boot/routes.php index bbff911..a7c484c 100644 --- a/boot/routes.php +++ b/boot/routes.php @@ -9,11 +9,11 @@ App::router()->serve( null, - static function (RouteCollection $routes): void { - $routes->namespace('Api\\Controllers', [ + static function (RouteCollection $routes) : void { + $routes->namespace('Api\Controllers', [ $routes->get('/', 'Home::index', 'api.home.index'), $routes->get('/about', 'Home::about', 'api.home.about'), ]); $routes->notFound(static fn () => respond_not_found()); } -); \ No newline at end of file +); diff --git a/config/antiCsrf.php b/config/antiCsrf.php index 6e595cf..5c05053 100644 --- a/config/antiCsrf.php +++ b/config/antiCsrf.php @@ -1,6 +1,6 @@