Skip to content

Commit 24ce1fb

Browse files
Remove status code dependency
1 parent e95e4f4 commit 24ce1fb

27 files changed

+55
-135
lines changed

composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"ext-redis": "*",
1717
"ext-simplexml": "*",
1818
"ext-zip": "*",
19-
"fig/http-message-util": "^1.1",
2019
"firebase/php-jwt": "^v6.0",
2120
"geoip2/geoip2": "~3.0",
2221
"graylog2/gelf-php": "dev-master",

composer.lock

+1-57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/index.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
require $applicationDir . '/vendor/autoload.php';
66

7-
use Fig\Http\Message\StatusCodeInterface;
87
use Monolog\Logger;
98
use Reconmap\ApiRouter;
109
use Reconmap\Services\ApplicationConfig;
@@ -15,7 +14,7 @@
1514
$configFilePath = $applicationDir . '/config.json';
1615
if (!file_exists($configFilePath) || !is_readable($configFilePath)) {
1716
$errorMessage = 'Missing or unreadable API configuration file (config.json)';
18-
header($errorMessage, true, StatusCodeInterface::STATUS_SERVICE_UNAVAILABLE);
17+
header($errorMessage, true, \Symfony\Component\HttpFoundation\Response::HTTP_SERVICE_UNAVAILABLE);
1918
echo $errorMessage, PHP_EOL;
2019
exit;
2120
}

src/ApiStrategy.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Reconmap;
44

5-
use Fig\Http\Message\StatusCodeInterface;
65
use League\Route\Http;
76
use League\Route\Strategy\JsonStrategy;
87
use Monolog\Logger;
@@ -12,6 +11,7 @@
1211
use Psr\Http\Server\MiddlewareInterface;
1312
use Psr\Http\Server\RequestHandlerInterface;
1413
use Reconmap\Http\CorsResponseDecorator;
14+
use Symfony\Component\HttpFoundation\Response;
1515

1616
class ApiStrategy extends JsonStrategy
1717
{
@@ -49,12 +49,12 @@ public function process(
4949
}
5050

5151
$response->getBody()->write(json_encode([
52-
'status_code' => StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR,
52+
'status_code' => Response::HTTP_INTERNAL_SERVER_ERROR,
5353
'reason_phrase' => 'Internal server error'
5454
]));
5555

5656
$response = $response->withAddedHeader('content-type', 'application/json');
57-
$response = $response->withStatus(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR, 'Internal server error');
57+
$response = $response->withStatus(Response::HTTP_INTERNAL_SERVER_ERROR, 'Internal server error');
5858

5959
return $this->corsResponseDecorator->decorate($request, $response);
6060
}

src/Controllers/Controller.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Reconmap\Controllers;
44

5-
use Fig\Http\Message\StatusCodeInterface;
65
use GuzzleHttp\Psr7\Response;
76
use League\Container\ContainerAwareInterface;
87
use League\Container\ContainerAwareTrait;
@@ -48,27 +47,27 @@ public function getJsonBodyDecodedAsArray(ServerRequestInterface $request): arra
4847

4948
protected function createInternalServerErrorResponse(): ResponseInterface
5049
{
51-
return (new Response())->withStatus(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
50+
return (new Response())->withStatus(\Symfony\Component\HttpFoundation\Response::HTTP_INTERNAL_SERVER_ERROR);
5251
}
5352

5453
protected function createForbiddenResponse(): ResponseInterface
5554
{
56-
return (new Response())->withStatus(StatusCodeInterface::STATUS_FORBIDDEN);
55+
return (new Response())->withStatus(\Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
5756
}
5857

5958
protected function createNoContentResponse(): ResponseInterface
6059
{
61-
return (new Response())->withStatus(StatusCodeInterface::STATUS_NO_CONTENT);
60+
return (new Response())->withStatus(\Symfony\Component\HttpFoundation\Response::HTTP_NO_CONTENT);
6261
}
6362

6463
protected function createBadRequestResponse(): ResponseInterface
6564
{
66-
return (new Response())->withStatus(StatusCodeInterface::STATUS_BAD_REQUEST);
65+
return (new Response())->withStatus(\Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST);
6766
}
6867

6968
protected function createNotFoundResponse(): ResponseInterface
7069
{
71-
return (new Response())->withStatus(StatusCodeInterface::STATUS_NOT_FOUND);
70+
return (new Response())->withStatus(\Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND);
7271
}
7372

7473
protected function createDeletedResponse(): ResponseInterface
@@ -78,15 +77,15 @@ protected function createDeletedResponse(): ResponseInterface
7877

7978
protected function createOkResponse(): ResponseInterface
8079
{
81-
return (new Response())->withStatus(StatusCodeInterface::STATUS_OK);
80+
return (new Response())->withStatus(\Symfony\Component\HttpFoundation\Response::HTTP_OK);
8281
}
8382

8483
protected function createStatusCreatedResponse(string|array|object $body): ResponseInterface
8584
{
8685
$jsonBody = is_string($body) ? $body : json_encode($body);
8786

8887
$response = (new Response())
89-
->withStatus(StatusCodeInterface::STATUS_CREATED)
88+
->withStatus(\Symfony\Component\HttpFoundation\Response::HTTP_CREATED)
9089
->withHeader('Content-type', 'application/json');
9190
$response->getBody()->write($jsonBody);
9291
return $response;

src/Controllers/DeleteEntityController.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Reconmap\Controllers;
44

5-
use Fig\Http\Message\StatusCodeInterface;
65
use GuzzleHttp\Psr7\Response;
76
use Psr\Http\Message\ResponseInterface;
87
use Psr\Http\Message\ServerRequestInterface;
@@ -13,12 +12,12 @@
1312
abstract class DeleteEntityController extends Controller
1413
{
1514
public function __construct(
16-
private readonly AuthorisationService $authorisationService,
15+
private readonly AuthorisationService $authorisationService,
1716
private readonly ActivityPublisherService $activityPublisherService,
18-
private readonly Deletable $repository,
19-
private readonly string $entityName,
20-
private readonly string $auditLogAction,
21-
private readonly string $idParamName
17+
private readonly Deletable $repository,
18+
private readonly string $entityName,
19+
private readonly string $auditLogAction,
20+
private readonly string $idParamName
2221
)
2322
{
2423
}
@@ -31,7 +30,7 @@ public function __invoke(ServerRequestInterface $request, array $args): Response
3130
if (!$this->authorisationService->isRoleAllowed($role, $operation)) {
3231
$this->logger->warning("Unauthorised action '" . $operation . "' called for role '$role'");
3332

34-
return (new Response())->withStatus(StatusCodeInterface::STATUS_FORBIDDEN);
33+
return (new Response())->withStatus(\Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
3534
}
3635

3736
$entityId = intval($args[$this->idParamName]);
@@ -45,7 +44,7 @@ public function __invoke(ServerRequestInterface $request, array $args): Response
4544
return $this->createNoContentResponse();
4645
}
4746

48-
return (new Response())->withStatus(StatusCodeInterface::STATUS_BAD_REQUEST);
47+
return (new Response())->withStatus(\Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST);
4948
}
5049

5150
private function auditAction(int $loggedInUserId, int $entityId): void

src/Controllers/Users/DeleteUserController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Reconmap\Controllers\Users;
44

5-
use Fig\Http\Message\StatusCodeInterface;
65
use GuzzleHttp\Exception\ClientException;
76
use Psr\Http\Message\ResponseInterface;
87
use Psr\Http\Message\ServerRequestInterface;
@@ -11,6 +10,7 @@
1110
use Reconmap\Repositories\UserRepository;
1211
use Reconmap\Services\ActivityPublisherService;
1312
use Reconmap\Services\KeycloakService;
13+
use Symfony\Component\HttpFoundation\Response;
1414

1515
class DeleteUserController extends Controller
1616
{
@@ -30,7 +30,7 @@ public function __invoke(ServerRequestInterface $request, array $args): Response
3030
try {
3131
$this->keycloakService->deleteUser($user);
3232
} catch (ClientException $e) {
33-
if ($e->getCode() === StatusCodeInterface::STATUS_NOT_FOUND) {
33+
if ($e->getCode() === Response::HTTP_NOT_FOUND) {
3434
$this->logger->warning("User to delete not found on Keycloak", ['userId' => $userId]);
3535
} else {
3636
throw $e;

src/Http/AuthMiddleware.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Reconmap\Http;
44

5-
use Fig\Http\Message\StatusCodeInterface;
65
use Firebase\JWT\ExpiredException;
76
use Firebase\JWT\JWT;
87
use Firebase\JWT\Key;
@@ -64,13 +63,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6463
return $handler->handle($request);
6564
} catch (ForbiddenException|ExpiredException $e) {
6665
$this->logger->warning($e->getMessage());
67-
return (new Response)->withStatus(StatusCodeInterface::STATUS_UNAUTHORIZED)
66+
return (new Response)->withStatus(\Symfony\Component\HttpFoundation\Response::HTTP_UNAUTHORIZED)
6867
->withBody(Utils::streamFor($e->getMessage()));
6968
} catch (Exception $httpException) {
7069
throw $httpException;
7170
} catch (\Exception $e) {
7271
$this->logger->error($e->getMessage());
73-
return (new Response)->withStatus(StatusCodeInterface::STATUS_BAD_REQUEST);
72+
return (new Response)->withStatus(\Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST);
7473
}
7574
}
7675

src/Http/StaticMiddleware.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Reconmap\Http;
44

5-
use Fig\Http\Message\StatusCodeInterface;
65
use GuzzleHttp\Psr7\Response;
76
use Psr\Http\Message\ResponseInterface;
87
use Psr\Http\Message\ServerRequestInterface;
@@ -21,9 +20,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
2120
{
2221
$cookies = $request->getCookieParams();
2322

24-
if(!isset($cookies['reconmap-static']) || !$this->redisServer->exists('static-token')) {
23+
if (!isset($cookies['reconmap-static']) || !$this->redisServer->exists('static-token')) {
2524
$response = new Response();
26-
return $response->withStatus(StatusCodeInterface::STATUS_FORBIDDEN);
25+
return $response->withStatus(\Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
2726
}
2827

2928
return $handler->handle($request);

tests/Controllers/Attachments/DeleteAttachmentControllerTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Reconmap\Controllers\Attachments;
44

5-
use Fig\Http\Message\StatusCodeInterface;
65
use PHPUnit\Framework\TestCase;
76
use Psr\Http\Message\ServerRequestInterface;
87
use Reconmap\Models\Attachment;
@@ -54,6 +53,6 @@ public function testSuccessfulDelete()
5453
$controller = new DeleteAttachmentController($mockAttachmentRepository, $mockAttachmentFilePath, $mockPublisherService, $mockFilesystem);
5554
$response = $controller($mockRequest, $args);
5655

57-
$this->assertEquals(StatusCodeInterface::STATUS_NO_CONTENT, $response->getStatusCode());
56+
$this->assertEquals(\Symfony\Component\HttpFoundation\Response::HTTP_NO_CONTENT, $response->getStatusCode());
5857
}
5958
}

tests/Controllers/AuditLog/GetAuditLogControllerTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Reconmap\Controllers\AuditLog;
44

5-
use Fig\Http\Message\StatusCodeInterface;
65
use Psr\Http\Message\ServerRequestInterface;
76
use Reconmap\ControllerTestCase;
87
use Reconmap\Repositories\AuditLogRepository;
@@ -38,7 +37,7 @@ public function testResponse()
3837
*/
3938
$controller = $this->injectController(new GetAuditLogController($mockAuthorisationService, $mockRepository, $mockConfig));
4039
$response = $controller($mockRequest);
41-
$this->assertEquals(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
40+
$this->assertEquals(\Symfony\Component\HttpFoundation\Response::HTTP_OK, $response->getStatusCode());
4241
$this->assertEquals(1, $response->getHeaderLine('X-Page-Count'));
4342
$this->assertEquals('X-Page-Count', $response->getHeaderLine('Access-Control-Expose-Headers'));
4443
}

tests/Controllers/Auth/LoginControllerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Reconmap\Controllers\Auth;
44

5-
use Fig\Http\Message\StatusCodeInterface;
65
use League\Container\Container;
76
use PHPUnit\Framework\TestCase;
87
use Psr\Http\Message\ServerRequestInterface;
@@ -13,6 +12,7 @@
1312
use Reconmap\Services\JwtPayloadCreator;
1413
use Reconmap\Services\RedisServer;
1514
use Reconmap\Services\Security\AuthorisationService;
15+
use Symfony\Component\HttpFoundation\Response;
1616

1717
class LoginControllerTest extends TestCase
1818
{
@@ -65,6 +65,6 @@ public function testLogin()
6565
$controller->setContainer($mockContainer);
6666
$response = $controller($mockServerRequestInterface, []);
6767

68-
$this->assertEquals(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
68+
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
6969
}
7070
}

tests/Controllers/Auth/LogoutControllerTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Reconmap\Controllers\Auth;
44

5-
use Fig\Http\Message\StatusCodeInterface;
65
use League\Container\Container;
76
use PHPUnit\Framework\TestCase;
87
use Psr\Http\Message\ServerRequestInterface;
@@ -42,6 +41,6 @@ public function testLogout()
4241
$controller->setContainer($mockContainer);
4342
$response = $controller($mockRequest, []);
4443

45-
$this->assertEquals(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
44+
$this->assertEquals(\Symfony\Component\HttpFoundation\Response::HTTP_OK, $response->getStatusCode());
4645
}
4746
}

tests/Controllers/Clients/CreateClientControllerTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Reconmap\Controllers\Clients;
44

5-
use Fig\Http\Message\StatusCodeInterface;
65
use PHPUnit\Framework\TestCase;
76
use Psr\Http\Message\ServerRequestInterface;
87
use Reconmap\Models\AuditActions\ClientAuditActions;
@@ -43,6 +42,6 @@ public function testHappyPath()
4342
$controller = new CreateClientController($mockProjectRepository, $mockActivityPublisherService);
4443
$response = $controller($mockRequest);
4544

46-
$this->assertEquals(StatusCodeInterface::STATUS_CREATED, $response->getStatusCode());
45+
$this->assertEquals(\Symfony\Component\HttpFoundation\Response::HTTP_CREATED, $response->getStatusCode());
4746
}
4847
}

0 commit comments

Comments
 (0)