Skip to content

Commit 93b9852

Browse files
Refactor code to adhere to PSR-12 standards and improve consistency across files
1 parent 29104d9 commit 93b9852

17 files changed

+129
-80
lines changed

.vscode/tasks.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
"$phpunit"
1010
],
1111
"group": "build"
12+
},
13+
{
14+
"label": "phpcs lint",
15+
"type": "shell",
16+
"command": "vendor/bin/phpcs --standard=phpcs.xml",
17+
"problemMatcher": [
18+
"$eslint-stylish"
19+
],
20+
"group": "build"
1221
}
1322
]
1423
}

src/Config/Rest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace chriskacerguis\RestServer\Config;

src/Database/Migrations/2025-09-23-100001_CreateKeysTable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace chriskacerguis\RestServer\Database\Migrations;

src/Database/Migrations/2025-09-23-100002_CreateLogsTable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace chriskacerguis\RestServer\Database\Migrations;

src/Database/Migrations/2025-09-23-100003_CreateAccessTable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace chriskacerguis\RestServer\Database\Migrations;

src/Database/Migrations/2025-09-23-100004_CreateLimitsTable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace chriskacerguis\RestServer\Database\Migrations;

src/Filters/ApiKeyFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace chriskacerguis\RestServer\Filters;

src/Filters/AuthFilter.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace chriskacerguis\RestServer\Filters;
@@ -13,7 +14,7 @@ class AuthFilter implements FilterInterface
1314
{
1415
public function before(RequestInterface $request, $arguments = null)
1516
{
16-
$config = config(RestConfig::class);
17+
$config = config(RestConfig::class);
1718

1819
if ($config->auth === false || $config->auth === '') {
1920
// Auth disabled
@@ -163,15 +164,19 @@ private function findPasswordForUser(string $username, RestConfig $config): ?str
163164
return $config->validLogins[$username] ?? null;
164165
}
165166

166-
private function unauthorizedResponse(string $scheme, string $realm, string $message = 'Unauthorized'): ResponseInterface
167-
{
167+
private function unauthorizedResponse(
168+
string $scheme,
169+
string $realm,
170+
string $message = 'Unauthorized'
171+
): ResponseInterface {
168172
$response = service('response');
169173
if (!$response instanceof ResponseInterface) {
170174
$response = new Response(config('App'));
171175
}
172176

173177
if ($scheme === 'basic') {
174-
$response->setHeader('WWW-Authenticate', 'Basic realm="' . addslashes($realm) . '", charset="UTF-8"');
178+
$basicHeader = 'Basic realm="' . addslashes($realm) . '", charset="UTF-8"';
179+
$response->setHeader('WWW-Authenticate', $basicHeader);
175180
} elseif ($scheme === 'digest') {
176181
$nonce = bin2hex(random_bytes(16));
177182
$opaque = bin2hex(random_bytes(16));

src/Filters/CorsFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace chriskacerguis\RestServer\Filters;

src/Filters/RateLimitFilter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace chriskacerguis\RestServer\Filters;
@@ -14,7 +15,7 @@ class RateLimitFilter implements FilterInterface
1415
{
1516
public function before(RequestInterface $request, $arguments = null)
1617
{
17-
$config = config(RestConfig::class);
18+
$config = config(RestConfig::class);
1819

1920
if (!$config->enableLimits) {
2021
return null;
@@ -25,7 +26,7 @@ public function before(RequestInterface $request, $arguments = null)
2526
'class' => null,
2627
'method' => null,
2728
'api_key' => null,
28-
'ip_address'=> null,
29+
'ip_address' => null,
2930
];
3031

3132
$uriPath = '/' . ltrim((string) $request->getUri()->getPath(), '/');
@@ -76,8 +77,8 @@ public function before(RequestInterface $request, $arguments = null)
7677
'count' => 0,
7778
'limit' => $defaultLimit,
7879
'reset_at' => gmdate('Y-m-d H:i:s', $now + $periodSeconds),
79-
'created_at'=> $nowDt,
80-
'updated_at'=> null,
80+
'created_at' => $nowDt,
81+
'updated_at' => null,
8182
]);
8283
$limitModel->insert($row);
8384
$row['id'] = $limitModel->getInsertID();

0 commit comments

Comments
 (0)