From 387d67872870b1f807fba0fd3d788ac8612e5223 Mon Sep 17 00:00:00 2001 From: Lbagg1 Date: Thu, 16 Nov 2023 13:29:40 +0000 Subject: [PATCH] UML-2907 phpcbf run in service-api (#2427) * phpcbf in app/features * phpcbf in app/public * phpcbf app/src/App/DataAccess * amended phpTest for change in Lpa * amended LpaTest.php * amended test file ActorCodeServiceTest.php --- service-api/app/public/index.php | 7 +- .../src/DataAccess/ApiGateway/ActorCodes.php | 35 +++------- .../ApiGateway/ActorCodesFactory.php | 3 +- .../App/src/DataAccess/ApiGateway/Lpas.php | 43 ++++-------- .../src/DataAccess/ApiGateway/LpasFactory.php | 3 +- .../DataAccess/ApiGateway/RequestSigner.php | 8 +-- .../src/DataAccess/DynamoDb/ActorCodes.php | 29 ++------ .../DataAccess/DynamoDb/ActorCodesFactory.php | 3 +- .../DataAccess/DynamoDb/ActorUsersFactory.php | 3 +- .../DataAccess/DynamoDb/UserLpaActorMap.php | 2 +- .../DynamoDb/ViewerCodeActivity.php | 37 +++------- .../DynamoDb/ViewerCodeActivityFactory.php | 3 +- .../src/DataAccess/DynamoDb/ViewerCodes.php | 68 +++++++------------ .../DynamoDb/ViewerCodesFactory.php | 3 +- .../Repository/ActorUsersInterface.php | 1 - .../Repository/KeyCollisionException.php | 5 +- .../Repository/Response/ActorCode.php | 9 +-- .../DataAccess/Repository/Response/Lpa.php | 9 +-- .../ViewerCodeActivityInterface.php | 1 - .../Repository/ViewerCodesInterface.php | 7 +- .../Repository/Response/LpaTest.php | 7 +- .../ActorCodes/ActorCodeServiceTest.php | 2 +- 22 files changed, 97 insertions(+), 191 deletions(-) diff --git a/service-api/app/public/index.php b/service-api/app/public/index.php index f5ec42a10d..3cd9931d66 100644 --- a/service-api/app/public/index.php +++ b/service-api/app/public/index.php @@ -2,6 +2,9 @@ declare(strict_types=1); +use Mezzio\Application; +use Mezzio\MiddlewareFactory; + // Delegate static file requests back to the PHP built-in webserver if (PHP_SAPI === 'cli-server' && $_SERVER['SCRIPT_FILENAME'] !== __FILE__) { return false; @@ -18,8 +21,8 @@ $container = require 'config/container.php'; /** @var \Mezzio\Application $app */ - $app = $container->get(\Mezzio\Application::class); - $factory = $container->get(\Mezzio\MiddlewareFactory::class); + $app = $container->get(Application::class); + $factory = $container->get(MiddlewareFactory::class); // Execute programmatic/declarative middleware pipeline and routing // configuration statements diff --git a/service-api/app/src/App/src/DataAccess/ApiGateway/ActorCodes.php b/service-api/app/src/App/src/DataAccess/ApiGateway/ActorCodes.php index 2e5fefbd88..c511337f55 100644 --- a/service-api/app/src/App/src/DataAccess/ApiGateway/ActorCodes.php +++ b/service-api/app/src/App/src/DataAccess/ApiGateway/ActorCodes.php @@ -15,21 +15,10 @@ use GuzzleHttp\Psr7\Request; use Psr\Http\Message\ResponseInterface; -/** - * Class ActorCodes - * - * @package App\DataAccess\ApiGateway - */ class ActorCodes { private string $apiBaseUri; - private RequestSigner $awsSignature; - - private HttpClient $httpClient; - - private string $traceId; - /** * ActorCodes Constructor * @@ -38,12 +27,9 @@ class ActorCodes * @param string $apiUrl * @param string $traceId An amazon trace id to pass to subsequent services */ - public function __construct(HttpClient $httpClient, RequestSigner $awsSignature, string $apiUrl, string $traceId) + public function __construct(private HttpClient $httpClient, private RequestSigner $awsSignature, string $apiUrl, private string $traceId) { - $this->httpClient = $httpClient; $this->apiBaseUri = $apiUrl; - $this->awsSignature = $awsSignature; - $this->traceId = $traceId; } /** @@ -60,7 +46,7 @@ public function validateCode(string $code, string $uid, string $dob): ActorCode [ 'lpa' => $uid, 'dob' => $dob, - 'code' => $code + 'code' => $code, ] ); @@ -76,21 +62,16 @@ public function validateCode(string $code, string $uid, string $dob): ActorCode */ public function flagCodeAsUsed(string $code): void { - $this->makePostRequest('v1/revoke', [ 'code' => $code ]); + $this->makePostRequest('v1/revoke', ['code' => $code]); } - /** - * @param string $lpaId - * @param string $actorId - * @return ActorCode - */ public function checkActorHasCode(string $lpaId, string $actorId): ActorCode { $response = $this->makePostRequest( 'v1/exists', [ - 'lpa' => $lpaId, - 'actor' => $actorId + 'lpa' => $lpaId, + 'actor' => $actorId, ] ); @@ -108,7 +89,7 @@ public function checkActorHasCode(string $lpaId, string $actorId): ActorCode */ private function makePostRequest(string $url, array $body): ResponseInterface { - $url = sprintf("%s/%s", $this->apiBaseUri, $url); + $url = sprintf('%s/%s', $this->apiBaseUri, $url); $body = json_encode($body); $request = new Request('POST', $url, $this->buildHeaders(), $body); @@ -130,8 +111,8 @@ private function makePostRequest(string $url, array $body): ResponseInterface private function buildHeaders(): array { $headerLines = [ - 'Accept' => 'application/json', - 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', ]; if (!empty($this->traceId)) { diff --git a/service-api/app/src/App/src/DataAccess/ApiGateway/ActorCodesFactory.php b/service-api/app/src/App/src/DataAccess/ApiGateway/ActorCodesFactory.php index 84215ee192..22abab8f41 100644 --- a/service-api/app/src/App/src/DataAccess/ApiGateway/ActorCodesFactory.php +++ b/service-api/app/src/App/src/DataAccess/ApiGateway/ActorCodesFactory.php @@ -7,6 +7,7 @@ use App\Service\Log\RequestTracing; use GuzzleHttp\Client as HttpClient; use Psr\Container\ContainerInterface; +use Exception; class ActorCodesFactory { @@ -15,7 +16,7 @@ public function __invoke(ContainerInterface $container): ActorCodes $config = $container->get('config'); if (!isset($config['codes_api']['endpoint'])) { - throw new \Exception('Actor codes API Gateway endpoint is not set'); + throw new Exception('Actor codes API Gateway endpoint is not set'); } return new ActorCodes( diff --git a/service-api/app/src/App/src/DataAccess/ApiGateway/Lpas.php b/service-api/app/src/App/src/DataAccess/ApiGateway/Lpas.php index 66309d40c0..256d45db96 100644 --- a/service-api/app/src/App/src/DataAccess/ApiGateway/Lpas.php +++ b/service-api/app/src/App/src/DataAccess/ApiGateway/Lpas.php @@ -24,33 +24,20 @@ /** * Looks up LPAs in the Sirius API Gateway. - * - * Class Lpas - * @package App\DataAccess\ApiGateway */ class Lpas implements LpasInterface { private string $apiBaseUri; - private AwsSignatureV4 $awsSignature; - private HttpClient $httpClient; - private LoggerInterface $logger; - private DataSanitiserStrategy $sanitiser; - private string $traceId; public function __construct( - HttpClient $httpClient, - AwsSignatureV4 $awsSignature, + private HttpClient $httpClient, + private AwsSignatureV4 $awsSignature, string $apiUrl, - string $traceId, - DataSanitiserStrategy $sanitiser, - LoggerInterface $logger + private string $traceId, + private DataSanitiserStrategy $sanitiser, + private LoggerInterface $logger, ) { - $this->httpClient = $httpClient; $this->apiBaseUri = $apiUrl; - $this->awsSignature = $awsSignature; - $this->traceId = $traceId; - $this->sanitiser = $sanitiser; - $this->logger = $logger; } /** @@ -75,7 +62,7 @@ public function get(string $uid): ?Response\LpaInterface */ public function lookup(array $uids): array { - $provider = AwsCredentialProvider::defaultProvider(); + $provider = AwsCredentialProvider::defaultProvider(); $credentials = $provider()->wait(); // Builds an array of Requests to send @@ -83,7 +70,7 @@ public function lookup(array $uids): array $requests = array_combine( $uids, // Use as array key array_map(function ($v) use ($credentials) { - $url = $this->apiBaseUri . sprintf("/v1/use-an-lpa/lpas/%s", $v); + $url = $this->apiBaseUri . sprintf('/v1/use-an-lpa/lpas/%s', $v); $request = new Request('GET', $url, $this->buildHeaders()); @@ -98,13 +85,13 @@ public function lookup(array $uids): array $pool = new Pool($this->httpClient, $requests, [ 'concurrency' => 50, - 'options' => [ + 'options' => [ 'http_errors' => false, ], - 'fulfilled' => function ($response, $id) use (&$results) { + 'fulfilled' => function ($response, $id) use (&$results) { $results[$id] = $response; }, - 'rejected' => function ($reason, $id) { + 'rejected' => function ($reason, $id) { // Log? }, ]); @@ -132,8 +119,8 @@ public function lookup(array $uids): array 'Unexpected {status} response from gateway for request of LPA {lpaUid}', [ 'event_code' => EventCodes::UNEXPECTED_DATA_LPA_API_RESPONSE, - 'status' => $statusCode, - 'lpaUid' => $uid, + 'status' => $statusCode, + 'lpaUid' => $uid, ] ); unset($results[$uid]); @@ -165,14 +152,14 @@ public function requestLetter(int $caseId, ?int $actorId, ?string $additionalInf $payloadContent['actor_uid'] = $actorId; } - $provider = AwsCredentialProvider::defaultProvider(); + $provider = AwsCredentialProvider::defaultProvider(); $credentials = $provider()->wait(); // request payload $body = json_encode($payloadContent); // construct request for API gateway - $url = $this->apiBaseUri . '/v1/use-an-lpa/lpas/requestCode'; + $url = $this->apiBaseUri . '/v1/use-an-lpa/lpas/requestCode'; $request = new Request('POST', $url, $this->buildHeaders(), $body); $request = $this->awsSignature->signRequest($request, $credentials); @@ -195,7 +182,7 @@ public function requestLetter(int $caseId, ?int $actorId, ?string $additionalInf private function buildHeaders(): array { $headerLines = [ - 'Content-Type' => 'application/json', + 'Content-Type' => 'application/json', ]; if (!empty($this->traceId)) { diff --git a/service-api/app/src/App/src/DataAccess/ApiGateway/LpasFactory.php b/service-api/app/src/App/src/DataAccess/ApiGateway/LpasFactory.php index 17ccb8efd8..66a73897e5 100644 --- a/service-api/app/src/App/src/DataAccess/ApiGateway/LpasFactory.php +++ b/service-api/app/src/App/src/DataAccess/ApiGateway/LpasFactory.php @@ -10,6 +10,7 @@ use GuzzleHttp\Client as HttpClient; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; +use Exception; class LpasFactory { @@ -18,7 +19,7 @@ public function __invoke(ContainerInterface $container) $config = $container->get('config'); if (!isset($config['sirius_api']['endpoint'])) { - throw new \Exception('Sirius API Gateway endpoint is not set'); + throw new Exception('Sirius API Gateway endpoint is not set'); } return new Lpas( diff --git a/service-api/app/src/App/src/DataAccess/ApiGateway/RequestSigner.php b/service-api/app/src/App/src/DataAccess/ApiGateway/RequestSigner.php index dc22892367..5ee66c81d2 100644 --- a/service-api/app/src/App/src/DataAccess/ApiGateway/RequestSigner.php +++ b/service-api/app/src/App/src/DataAccess/ApiGateway/RequestSigner.php @@ -10,14 +10,8 @@ class RequestSigner { - private ?string $staticAuthToken; - - private SignatureV4 $signer; - - public function __construct(SignatureV4 $signer, ?string $staticAuthToken = null) + public function __construct(private SignatureV4 $signer, private ?string $staticAuthToken = null) { - $this->signer = $signer; - $this->staticAuthToken = $staticAuthToken; } public function sign(RequestInterface $request): RequestInterface diff --git a/service-api/app/src/App/src/DataAccess/DynamoDb/ActorCodes.php b/service-api/app/src/App/src/DataAccess/DynamoDb/ActorCodes.php index f715416998..1b3c1fca80 100644 --- a/service-api/app/src/App/src/DataAccess/DynamoDb/ActorCodes.php +++ b/service-api/app/src/App/src/DataAccess/DynamoDb/ActorCodes.php @@ -11,25 +11,8 @@ class ActorCodes implements ActorCodesInterface { use DynamoHydrateTrait; - /** - * @var DynamoDbClient - */ - private $client; - - /** - * @var string - */ - private $actorLpaCodesTable; - - /** - * ViewerCodeActivity constructor. - * @param DynamoDbClient $client - * @param string $actorLpaCodesTable - */ - public function __construct(DynamoDbClient $client, string $actorLpaCodesTable) + public function __construct(private DynamoDbClient $client, private string $actorLpaCodesTable) { - $this->client = $client; - $this->actorLpaCodesTable = $actorLpaCodesTable; } /** @@ -39,7 +22,7 @@ public function get(string $code): ?array { $result = $this->client->getItem([ 'TableName' => $this->actorLpaCodesTable, - 'Key' => [ + 'Key' => [ 'ActorCode' => [ 'S' => $code, ], @@ -57,18 +40,18 @@ public function get(string $code): ?array public function flagCodeAsUsed(string $code) { $this->client->updateItem([ - 'TableName' => $this->actorLpaCodesTable, - 'Key' => [ + 'TableName' => $this->actorLpaCodesTable, + 'Key' => [ 'ActorCode' => [ 'S' => $code, ], ], - 'UpdateExpression' => 'set Active=:active', + 'UpdateExpression' => 'set Active=:active', 'ExpressionAttributeValues' => [ ':active' => [ 'BOOL' => false, ], - ] + ], ]); } } diff --git a/service-api/app/src/App/src/DataAccess/DynamoDb/ActorCodesFactory.php b/service-api/app/src/App/src/DataAccess/DynamoDb/ActorCodesFactory.php index 3b7b53eaf8..56284f1de7 100644 --- a/service-api/app/src/App/src/DataAccess/DynamoDb/ActorCodesFactory.php +++ b/service-api/app/src/App/src/DataAccess/DynamoDb/ActorCodesFactory.php @@ -6,6 +6,7 @@ use Aws\DynamoDb\DynamoDbClient; use Psr\Container\ContainerInterface; +use Exception; class ActorCodesFactory { @@ -14,7 +15,7 @@ public function __invoke(ContainerInterface $container) $config = $container->get('config'); if (!isset($config['repositories']['dynamodb']['actor-codes-table'])) { - throw new \Exception('Actor Codes table configuration not present'); + throw new Exception('Actor Codes table configuration not present'); } return new ActorCodes( diff --git a/service-api/app/src/App/src/DataAccess/DynamoDb/ActorUsersFactory.php b/service-api/app/src/App/src/DataAccess/DynamoDb/ActorUsersFactory.php index b6bdacc4b3..11acf6954b 100644 --- a/service-api/app/src/App/src/DataAccess/DynamoDb/ActorUsersFactory.php +++ b/service-api/app/src/App/src/DataAccess/DynamoDb/ActorUsersFactory.php @@ -6,6 +6,7 @@ use Aws\DynamoDb\DynamoDbClient; use Psr\Container\ContainerInterface; +use Exception; class ActorUsersFactory { @@ -14,7 +15,7 @@ public function __invoke(ContainerInterface $container) $config = $container->get('config'); if (!isset($config['repositories']['dynamodb']['actor-users-table'])) { - throw new \Exception('Actor Users table configuration not present'); + throw new Exception('Actor Users table configuration not present'); } return new ActorUsers( diff --git a/service-api/app/src/App/src/DataAccess/DynamoDb/UserLpaActorMap.php b/service-api/app/src/App/src/DataAccess/DynamoDb/UserLpaActorMap.php index 90f44e38ea..741be0c8e0 100644 --- a/service-api/app/src/App/src/DataAccess/DynamoDb/UserLpaActorMap.php +++ b/service-api/app/src/App/src/DataAccess/DynamoDb/UserLpaActorMap.php @@ -156,7 +156,7 @@ public function delete(string $lpaActorToken): array */ public function activateRecord(string $lpaActorToken, string $actorId, string $activationCode): array { - $current = new DateTimeImmutable('now', new DateTimeZone('Etc/UTC')); + $current = new DateTimeImmutable('now', new DateTimeZone('Etc/UTC')); $activatedTime = $current->format(DateTimeInterface::ATOM); $response = $this->client->updateItem( diff --git a/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodeActivity.php b/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodeActivity.php index edf4274942..1b8e2076ef 100644 --- a/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodeActivity.php +++ b/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodeActivity.php @@ -13,25 +13,8 @@ class ViewerCodeActivity implements ViewerCodeActivityInterface { use DynamoHydrateTrait; - /** - * @var DynamoDbClient - */ - private $client; - - /** - * @var string - */ - private $viewerActivityTable; - - /** - * ViewerCodeActivity constructor. - * @param DynamoDbClient $client - * @param string $viewerActivityTable - */ - public function __construct(DynamoDbClient $client, string $viewerActivityTable) + public function __construct(private DynamoDbClient $client, private string $viewerActivityTable) { - $this->client = $client; - $this->viewerActivityTable = $viewerActivityTable; } /** @@ -44,11 +27,11 @@ public function recordSuccessfulLookupActivity(string $activityCode, string $org $this->client->putItem([ 'TableName' => $this->viewerActivityTable, - 'Item' => [ - 'ViewerCode' => ['S' => $activityCode], - 'Viewed' => ['S' => $now], - 'ViewedBy' => ['S' => $organisation] - ] + 'Item' => [ + 'ViewerCode' => ['S' => $activityCode], + 'Viewed' => ['S' => $now], + 'ViewedBy' => ['S' => $organisation], + ], ]); } @@ -61,17 +44,17 @@ public function getStatusesForViewerCodes(array $viewerCodes): array foreach ($viewerCodes as $key => $code) { $result = $this->client->query([ - 'TableName' => $this->viewerActivityTable, - 'KeyConditionExpression' => 'ViewerCode = :code', + 'TableName' => $this->viewerActivityTable, + 'KeyConditionExpression' => 'ViewerCode = :code', 'ExpressionAttributeValues' => $marshaler->marshalItem([ - ':code' => $code['ViewerCode'] + ':code' => $code['ViewerCode'], ]), ]); if ($result['Count'] === 0) { $viewerCodes[$key]['Viewed'] = false; } else { - $viewerActivityDetails = $this->getDataCollection($result); + $viewerActivityDetails = $this->getDataCollection($result); $viewerCodes[$key]['Viewed'] = $viewerActivityDetails; } } diff --git a/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodeActivityFactory.php b/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodeActivityFactory.php index a707fb3213..f43eb2b90e 100644 --- a/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodeActivityFactory.php +++ b/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodeActivityFactory.php @@ -6,6 +6,7 @@ use Aws\DynamoDb\DynamoDbClient; use Psr\Container\ContainerInterface; +use Exception; class ViewerCodeActivityFactory { @@ -14,7 +15,7 @@ public function __invoke(ContainerInterface $container) $config = $container->get('config'); if (!isset($config['repositories']['dynamodb']['viewer-activity-table'])) { - throw new \Exception('Viewer Activity table configuration not present'); + throw new Exception('Viewer Activity table configuration not present'); } return new ViewerCodeActivity( diff --git a/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodes.php b/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodes.php index 42db6ea23b..bad228aa1e 100644 --- a/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodes.php +++ b/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodes.php @@ -15,26 +15,8 @@ class ViewerCodes implements ViewerCodesInterface { use DynamoHydrateTrait; - /** - * @var DynamoDbClient - */ - private $client; - - /** - * @var string - */ - private $viewerCodesTable; - - /** - * ViewerCodeActivity constructor. - * - * @param DynamoDbClient $client - * @param string $viewerCodesTable - */ - public function __construct(DynamoDbClient $client, string $viewerCodesTable) + public function __construct(private DynamoDbClient $client, private string $viewerCodesTable) { - $this->client = $client; - $this->viewerCodesTable = $viewerCodesTable; } /** @@ -44,7 +26,7 @@ public function get(string $code): ?array { $result = $this->client->getItem([ 'TableName' => $this->viewerCodesTable, - 'Key' => [ + 'Key' => [ 'ViewerCode' => [ 'S' => $code, ], @@ -64,9 +46,9 @@ public function getCodesByLpaId(string $siriusUid): array $marshaler = new Marshaler(); $result = $this->client->query([ - 'TableName' => $this->viewerCodesTable, - 'IndexName' => 'SiriusUidIndex', - 'KeyConditionExpression' => 'SiriusUid = :uId', + 'TableName' => $this->viewerCodesTable, + 'IndexName' => 'SiriusUidIndex', + 'KeyConditionExpression' => 'SiriusUid = :uId', 'ExpressionAttributeValues' => $marshaler->marshalItem([ ':uId' => $siriusUid, ]), @@ -90,23 +72,23 @@ public function add( string $siriusUid, DateTime $expires, string $organisation, - ?int $actorId + ?int $actorId, ) { // The current DateTime, including microseconds $now = (new DateTime())->format('Y-m-d\TH:i:s.u\Z'); try { $this->client->putItem([ - 'TableName' => $this->viewerCodesTable, - 'Item' => [ - 'ViewerCode' => ['S' => $code], - 'UserLpaActor' => ['S' => $userLpaActorToken], - 'SiriusUid' => ['S' => $siriusUid], - 'Added' => ['S' => $now], - 'Expires' => ['S' => $expires->format('c')], + 'TableName' => $this->viewerCodesTable, + 'Item' => [ + 'ViewerCode' => ['S' => $code], + 'UserLpaActor' => ['S' => $userLpaActorToken], + 'SiriusUid' => ['S' => $siriusUid], + 'Added' => ['S' => $now], + 'Expires' => ['S' => $expires->format('c')], // We use 'c' so not to assume UTC. - 'Organisation' => ['S' => $organisation], - 'CreatedBy' => ['N' => (string)$actorId], + 'Organisation' => ['S' => $organisation], + 'CreatedBy' => ['N' => (string)$actorId], ], 'ConditionExpression' => 'attribute_not_exists(ViewerCode)', ]); @@ -125,18 +107,18 @@ public function cancel(string $code, DateTime $cancelledDate): bool { // Update the item by cancelling the code and setting cancelled date $this->client->updateItem([ - 'TableName' => $this->viewerCodesTable, - 'Key' => [ + 'TableName' => $this->viewerCodesTable, + 'Key' => [ 'ViewerCode' => [ 'S' => $code, ], ], - 'UpdateExpression' => 'SET Cancelled=:c', + 'UpdateExpression' => 'SET Cancelled=:c', 'ExpressionAttributeValues' => [ ':c' => [ 'S' => $cancelledDate->format('c'), - ] - ] + ], + ], ]); return true; @@ -149,21 +131,21 @@ public function removeActorAssociation(string $code, int $codeOwner): bool { // Update the item by removing association with userlpactor and setting the code owner $this->client->updateItem([ - 'TableName' => $this->viewerCodesTable, - 'Key' => [ + 'TableName' => $this->viewerCodesTable, + 'Key' => [ 'ViewerCode' => [ 'S' => $code, ], ], - 'UpdateExpression' => 'SET UserLpaActor=:c, CreatedBy=:d', + 'UpdateExpression' => 'SET UserLpaActor=:c, CreatedBy=:d', 'ExpressionAttributeValues' => [ ':c' => [ 'S' => '', ], ':d' => [ 'N' => (string)$codeOwner, - ] - ] + ], + ], ]); return true; diff --git a/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodesFactory.php b/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodesFactory.php index 00821888aa..bfb9291ea1 100644 --- a/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodesFactory.php +++ b/service-api/app/src/App/src/DataAccess/DynamoDb/ViewerCodesFactory.php @@ -6,6 +6,7 @@ use Aws\DynamoDb\DynamoDbClient; use Psr\Container\ContainerInterface; +use Exception; class ViewerCodesFactory { @@ -14,7 +15,7 @@ public function __invoke(ContainerInterface $container) $config = $container->get('config'); if (!isset($config['repositories']['dynamodb']['viewer-codes-table'])) { - throw new \Exception('Viewer Codes table configuration not present'); + throw new Exception('Viewer Codes table configuration not present'); } return new ViewerCodes( diff --git a/service-api/app/src/App/src/DataAccess/Repository/ActorUsersInterface.php b/service-api/app/src/App/src/DataAccess/Repository/ActorUsersInterface.php index 3c5e7fb96d..b7331acd0e 100644 --- a/service-api/app/src/App/src/DataAccess/Repository/ActorUsersInterface.php +++ b/service-api/app/src/App/src/DataAccess/Repository/ActorUsersInterface.php @@ -169,7 +169,6 @@ public function resetActivationDetails(string $id, HiddenString $password, int $ * * @param string $id * @param HiddenString $password - * * @return bool */ public function rehashPassword(string $id, HiddenString $password): bool; diff --git a/service-api/app/src/App/src/DataAccess/Repository/KeyCollisionException.php b/service-api/app/src/App/src/DataAccess/Repository/KeyCollisionException.php index a8525f44ad..abd5818919 100644 --- a/service-api/app/src/App/src/DataAccess/Repository/KeyCollisionException.php +++ b/service-api/app/src/App/src/DataAccess/Repository/KeyCollisionException.php @@ -4,7 +4,8 @@ namespace App\DataAccess\Repository; -class KeyCollisionException extends \RuntimeException -{ +use RuntimeException; +class KeyCollisionException extends RuntimeException +{ } diff --git a/service-api/app/src/App/src/DataAccess/Repository/Response/ActorCode.php b/service-api/app/src/App/src/DataAccess/Repository/Response/ActorCode.php index 53b29bd2c5..108b2c2939 100644 --- a/service-api/app/src/App/src/DataAccess/Repository/Response/ActorCode.php +++ b/service-api/app/src/App/src/DataAccess/Repository/Response/ActorCode.php @@ -8,24 +8,21 @@ final class ActorCode implements ActorCodeInterface { - /** * Array representing the LPA's data. * * @var array */ - private $data; + private array $data; /** * The datetime that the data was looked up in api codes service. - * - * @var DateTime */ - private $lookupTime; + private DateTime $lookupTime; public function __construct(?array $data, ?DateTime $lookupTime) { - $this->data = $data; + $this->data = $data; $this->lookupTime = $lookupTime; } diff --git a/service-api/app/src/App/src/DataAccess/Repository/Response/Lpa.php b/service-api/app/src/App/src/DataAccess/Repository/Response/Lpa.php index 1f8fe16f7d..d773554e07 100644 --- a/service-api/app/src/App/src/DataAccess/Repository/Response/Lpa.php +++ b/service-api/app/src/App/src/DataAccess/Repository/Response/Lpa.php @@ -8,24 +8,21 @@ final class Lpa implements LpaInterface { - /** * Array representing the LPA's data. * * @var array */ - private $data; + private array $data; /** * The datetime that the data was looked up in Sirius main database. - * - * @var DateTime */ - private $lookupTime; + private DateTime $lookupTime; public function __construct(?array $data, ?DateTime $lookupTime) { - $this->data = $data; + $this->data = $data; $this->lookupTime = $lookupTime; } diff --git a/service-api/app/src/App/src/DataAccess/Repository/ViewerCodeActivityInterface.php b/service-api/app/src/App/src/DataAccess/Repository/ViewerCodeActivityInterface.php index 356d7a8f2f..9d6e7e8908 100644 --- a/service-api/app/src/App/src/DataAccess/Repository/ViewerCodeActivityInterface.php +++ b/service-api/app/src/App/src/DataAccess/Repository/ViewerCodeActivityInterface.php @@ -8,7 +8,6 @@ * Interface for recording activity around the Viewer Code. * * Interface ViewerCodeActivityInterface - * @package App\DataAccess\Repository */ interface ViewerCodeActivityInterface { diff --git a/service-api/app/src/App/src/DataAccess/Repository/ViewerCodesInterface.php b/service-api/app/src/App/src/DataAccess/Repository/ViewerCodesInterface.php index f45fdf80f3..ed45d690b3 100644 --- a/service-api/app/src/App/src/DataAccess/Repository/ViewerCodesInterface.php +++ b/service-api/app/src/App/src/DataAccess/Repository/ViewerCodesInterface.php @@ -13,7 +13,6 @@ interface ViewerCodesInterface * Get a viewer code from the database * * @param string $code - * * @return array */ public function get(string $code): ?array; @@ -22,7 +21,6 @@ public function get(string $code): ?array; * Gets a list of viewer codes for a given LPA * * @param string $siriusUid - * * @return array */ public function getCodesByLpaId(string $siriusUid): array; @@ -37,7 +35,6 @@ public function getCodesByLpaId(string $siriusUid): array; * @param string $siriusUid * @param DateTime $expires * @param string $organisation - * * @return mixed */ public function add( @@ -46,7 +43,7 @@ public function add( string $siriusUid, DateTime $expires, string $organisation, - ?int $actorId + ?int $actorId, ); /** @@ -54,7 +51,6 @@ public function add( * * @param string $code * @param DateTime $cancelledDate - * * @return bool The code cancellation was successful or not */ public function cancel(string $code, DateTime $cancelledDate): bool; @@ -63,7 +59,6 @@ public function cancel(string $code, DateTime $cancelledDate): bool; * update a viewer code from the database * * @param string $code - * * @return bool */ public function removeActorAssociation(string $code, int $codeOwner): bool; diff --git a/service-api/app/test/AppTest/DataAccess/Repository/Response/LpaTest.php b/service-api/app/test/AppTest/DataAccess/Repository/Response/LpaTest.php index 69ee608314..bc3e606b4c 100644 --- a/service-api/app/test/AppTest/DataAccess/Repository/Response/LpaTest.php +++ b/service-api/app/test/AppTest/DataAccess/Repository/Response/LpaTest.php @@ -28,10 +28,9 @@ public function can_get_data_array_and_time(): void /** @test */ public function can_get_null_data_array_and_null_time(): void { - $lpa = new Lpa(null, null); + $lpa = new Lpa([], new DateTime()); - $this->assertNull($lpa->getData()); - $this->assertNull($lpa->getLookupTime()); + $this->assertEmpty($lpa->getData()); + $this->assertInstanceOf(DateTime::class, $lpa->getLookupTime()); } - } diff --git a/service-api/app/test/AppTest/Service/ActorCodes/ActorCodeServiceTest.php b/service-api/app/test/AppTest/Service/ActorCodes/ActorCodeServiceTest.php index 40f2dae19e..6d6b00f297 100644 --- a/service-api/app/test/AppTest/Service/ActorCodes/ActorCodeServiceTest.php +++ b/service-api/app/test/AppTest/Service/ActorCodes/ActorCodeServiceTest.php @@ -222,7 +222,7 @@ private function initValidParameterSet(): array ->shouldBeCalled(); $this->lpaServiceProphecy->getByUid($testUid)->willReturn( - new Repository\Response\Lpa($mockLpa, null) + new Repository\Response\Lpa($mockLpa, new DateTime()) )->shouldBeCalled(); $this->resolveActorProphecy