Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpcbf service-front/app #2401

Merged
merged 8 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions service-front/app/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion service-front/app/src/Actor/src/Form/CancelCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class CancelCode extends AbstractForm implements InputFilterProviderInterface
{
const FORM_NAME = 'cancel_code';
public const FORM_NAME = 'cancel_code';

public function __construct(CsrfGuardInterface $csrfGuard)
{
Expand Down
8 changes: 5 additions & 3 deletions service-front/app/src/Actor/src/Form/ChangeEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ class ChangeEmail extends AbstractForm implements InputFilterProviderInterface
/**
* Error messages
*
* @var array
* @var string[]
*/
protected array $messageTemplates = [
self::INVALID_PASSWORD => 'The password you entered is incorrect',
self::NEW_EMAIL_NOT_DIFFERENT => 'The new email address you entered is the same as your current email address. They must be different.',
self::NEW_EMAIL_NOT_DIFFERENT => 'The new email address you entered is the same as '
. 'your current email address. They must be different.',
];

public function __construct(CsrfGuardInterface $guard)
Expand Down Expand Up @@ -74,7 +75,8 @@ public function getInputFilterSpecification()
'break_chain_on_failure' => true,
'options' => [
'messages' => [
EmailAddressValidator::INVALID => 'Enter an email address in the correct format, like [email protected]',
EmailAddressValidator::INVALID => 'Enter an email address in the correct format, '
. 'like [email protected]',
],
],
],
Expand Down
7 changes: 4 additions & 3 deletions service-front/app/src/Actor/src/Form/CreateAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

class CreateAccount extends AbstractForm implements InputFilterProviderInterface
{
const FORM_NAME = 'create_account';
public const FORM_NAME = 'create_account';

public const NEW_EMAIL_CONFLICT = 'NewEmailConflict';

/**
* Error messages
*
* @var array
* @var string[]
*/
protected array $messageTemplates = [
self::NEW_EMAIL_CONFLICT => 'Sorry, there was a problem with that email address. Please try a different one',
Expand Down Expand Up @@ -71,7 +71,8 @@ public function getInputFilterSpecification(): array
'break_chain_on_failure' => true,
'options' => [
'messages' => [
NotEmpty::IS_EMPTY => 'Enter an email address in the correct format, like [email protected]',
NotEmpty::IS_EMPTY => 'Enter an email address in the correct format, ' .
'like [email protected]',
],
],
],
Expand Down
2 changes: 1 addition & 1 deletion service-front/app/src/Actor/src/Form/CreateShareCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class CreateShareCode extends AbstractForm implements InputFilterProviderInterface
{
const FORM_NAME = 'lpa_sharecode_create';
public const FORM_NAME = 'lpa_sharecode_create';

public function __construct(CsrfGuardInterface $csrfGuard)
{
Expand Down
4 changes: 2 additions & 2 deletions service-front/app/src/Actor/src/Form/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class Login extends AbstractForm implements InputFilterProviderInterface
/**
* Error messages
*
* @var array
* @var string[]
*/
protected array $messageTemplates = [
self::NOT_SAME => 'Security validation failed. Please try again.',
self::NOT_FOUND => 'Check your details and try again. We could not find a ' .
'Use a lasting power of attorney account with that email address and password.'
'Use a lasting power of attorney account with that email address and password.',
];

public function __construct(CsrfGuardInterface $csrfGuard)
Expand Down
2 changes: 1 addition & 1 deletion service-front/app/src/Actor/src/Form/LpaConfirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class LpaConfirm extends AbstractForm
{
const FORM_NAME = 'lpa_add';
public const FORM_NAME = 'lpa_add';

public function __construct(CsrfGuardInterface $csrfGuard)
{
Expand Down
2 changes: 1 addition & 1 deletion service-front/app/src/Actor/src/Form/PasswordChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PasswordChange extends AbstractForm implements InputFilterProviderInterfac
/**
* Error messages
*
* @var array
* @var string[]
*/
protected array $messageTemplates = [
self::INVALID_PASSWORD => 'Current password is incorrect',
Expand Down
2 changes: 1 addition & 1 deletion service-front/app/src/Actor/src/Form/PasswordReset.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class PasswordReset extends AbstractForm implements InputFilterProviderInterface
{
const FORM_NAME = 'password-reset';
public const FORM_NAME = 'password-reset';

public function __construct(CsrfGuardInterface $guard)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function __construct(CsrfGuardInterface $csrfGuard)
'type' => 'Radio',
'options' => [
'value_options' => [
'Donor' => 'Donor',
'Attorney' => 'Attorney',
'Donor' => 'Donor',
'Attorney' => 'Attorney',
'ReplacementAttorney' => 'ReplacementAttorney',
],
],
Expand Down
2 changes: 1 addition & 1 deletion service-front/app/src/Actor/src/Form/Triage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Triage extends AbstractForm implements InputFilterProviderInterface
{
const FORM_NAME = 'triage';
public const FORM_NAME = 'triage';

public function __construct(CsrfGuardInterface $csrfGuard)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Locale;

/**
* @codeCoverageIgnore
Expand Down Expand Up @@ -51,7 +52,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface

if ($request->getMethod() === 'POST') {
$signInLink = $this->serverUrlHelper->generate($this->urlHelper->generate('auth-redirect'));
$uiLocale = \Locale::getPrimaryLanguage($request->getAttribute('locale'));
$uiLocale = Locale::getPrimaryLanguage($request->getAttribute('locale'));

if ($uiLocale === 'cy') {
$signInLink = str_replace('/cy', '', $signInLink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$shareCodes[$key]['CreatedBy'] = $trustCorporation->getCompanyName();
}
}

$this->logger->debug(
'Created by resolved to {actor_name}',
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function handlePost(ServerRequestInterface $request): ResponseInterface
'Request for activation key for LPA {uID} with address abroad',
[
'event_code' => EventCodes::USER_ABROAD_ADDRESS_REQUEST_SUCCESS,
'uID' => $state->referenceNumber
'uID' => $state->referenceNumber,
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ public function handlePost(ServerRequestInterface $request): ResponseInterface
$state->postcode
);

if ($state->liveInUK === 'No'
if (
$state->liveInUK === 'No'
&& $result->getResponse() !== AccessForAllResult::LPA_ALREADY_ADDED
&& $result->getResponse() !== AccessForAllResult::STATUS_NOT_VALID) {
&& $result->getResponse() !== AccessForAllResult::STATUS_NOT_VALID
) {
return $this->redirectToRoute('lpa.add.actor-address');
}

Expand Down Expand Up @@ -211,7 +213,7 @@ public function handlePost(ServerRequestInterface $request): ResponseInterface
);

case AccessForAllResult::DOES_NOT_MATCH:
return $this->redirectToRoute('lpa.add.actor-address');
return $this->redirectToRoute('lpa.add.actor-address');

case AccessForAllResult::FOUND:
$form = new CreateNewActivationKey($this->getCsrfGuard($request));
Expand Down
3 changes: 1 addition & 2 deletions service-front/app/src/Common/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public function getDependencies(): array
// allows value setting on the container at runtime.
Service\Container\ModifiableContainerInterface::class
=> Service\Container\PhpDiModifiableContainer::class,

Service\Lpa\LpaFactory::class => Service\Lpa\Factory\Sirius::class,
Service\Lpa\LpaFactory::class => Service\Lpa\Factory\Sirius::class,
Service\Lpa\InstAndPrefImagesFactory::class => Service\Lpa\Factory\InstAndPrefImages::class,

// Language extraction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
abstract class AbstractApiException extends RuntimeException
{
/**
* @var array
* @var string[]
*/
private array $additionalData = [];

Expand Down
4 changes: 2 additions & 2 deletions service-front/app/src/Common/src/Exception/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ApiException extends AbstractApiException
protected $code;

/**
* @var array|null
* @var array<string>|null
*/
protected ?array $additionalData = null;

Expand Down Expand Up @@ -87,7 +87,7 @@ public static function create(
}
}

if ($statusCode != null) {
if ($statusCode !== null) {
$code = $statusCode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

class InvalidRequestException extends Exception
{
public function __construct(string $message, int $code = StatusCodeInterface::STATUS_BAD_REQUEST, ?Exception $previous = null)
{
public function __construct(

Check warning on line 12 in service-front/app/src/Common/src/Exception/InvalidRequestException.php

View check run for this annotation

Codecov / codecov/patch

service-front/app/src/Common/src/Exception/InvalidRequestException.php#L12

Added line #L12 was not covered by tests
string $message,
int $code = StatusCodeInterface::STATUS_BAD_REQUEST,
?Exception $previous = null,
) {
parent::__construct($message, $code, $previous);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

class RateLimitExceededException extends Exception
{
public function __construct(string $message, int $code = StatusCodeInterface::STATUS_TOO_MANY_REQUESTS, ?Exception $previous = null)
{
public function __construct(
string $message,
int $code = StatusCodeInterface::STATUS_TOO_MANY_REQUESTS,
?Exception $previous = null,
) {
parent::__construct($message, $code, $previous);
}
}
8 changes: 5 additions & 3 deletions service-front/app/src/Common/src/Form/AbstractForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ abstract class AbstractForm extends Form

/**
* Error messages templates
*
* @var string[]
*/
protected array $messageTemplates = [];

/**
* @var array This, and its associated functions below allow form level error messages not attached to
* @var string[] This, and its associated functions below allow form level error messages not attached to
* any individual form elements. Something that Zend form does not provide OOTB.
*/
protected array $errorMessages = [];
Expand Down Expand Up @@ -50,11 +52,11 @@ public function __construct(string $formName, CsrfGuardInterface $csrfGuard)
public function addErrorMessage(string $messageKey, string $elementName = ''): void
{
if (! isset($this->messageTemplates[$messageKey])) {
throw new InvalidArgumentException("No message template exists for key '$messageKey'");
throw new InvalidArgumentException('No message template exists for key ' . $messageKey);
}

if ($elementName !== '' && ! $this->has($elementName)) {
throw new InvalidArgumentException("No form element named '$elementName' found");
throw new InvalidArgumentException('No form element named ' . $elementName . ' found');
}

if ($elementName === '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __invoke(ArrayObject $lpas, string $userToken): ArrayObject
);

$lpas->$lpaKey->activeCodeCount = $shareCodes->activeCodeCount;
$lpas->$lpaKey->shareCodes = $shareCodes;
$lpas->$lpaKey->shareCodes = $shareCodes;
$lpas->$lpaKey->actorActive =
$lpaData['actor']['type'] === 'donor' || $lpaData['actor']['details']->getSystemStatus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function isLimited(string $identity, string $key = ''): bool
}

// walk the time window and drop expired records
$expiredTime = time() - $this->interval;
$expiredTime = time() - $this->interval;
$accessRecords = array_filter($accessRecords, function (int $item) use ($expiredTime) {
return $item >= $expiredTime;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

abstract class RateLimitService implements RateLimiterInterface
{
public function __construct(protected StorageInterface $cacheService, protected int $interval, protected int $requestsPerInterval, protected LoggerInterface $logger)
{
public function __construct(
protected StorageInterface $cacheService,
protected int $interval,
protected int $requestsPerInterval,
protected LoggerInterface $logger,
) {
}

abstract public function isLimited(string $identity): bool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function __construct(private ContainerInterface $container)
* Returns a configured rate limit service loaded using the name given
*
* @param string $limitName
*
* @return RateLimitService
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ class KmsManager implements KeyManagerInterface
/**
* Time to cache encryption data key.
*/
const ENCRYPTION_KEY_TTL = 60 * 60 * 1;
public const ENCRYPTION_KEY_TTL = 60 * 60 * 1;

/**
* Time to cache decryption data keys.
* These are held longer to allow for rotation crossover.
*/
const DECRYPTION_KEY_TTL = 60 * 60 * 2;
public const DECRYPTION_KEY_TTL = 60 * 60 * 2;

/**
* Current Key name within the cache.
*/
const CURRENT_ENCRYPTION_KEY = 'current_session_encryption_key';
public const CURRENT_ENCRYPTION_KEY = 'current_session_encryption_key';

public function __construct(private KmsClient $kmsClient, private KeyCache $cache, private string $kmsAlias)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CsrfGuardValidator extends LaminasCsrf

/**
* Set to null in order to force the user to manually set it
*
* @var ?string
* @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
*/
Expand Down
5 changes: 3 additions & 2 deletions service-front/app/src/Common/src/Validator/DobValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class DobValidator extends DateValidator
self::MONTH_INCOMPLETE => 'Date of birth must include a month',
self::YEAR_INCOMPLETE => 'Date of birth must include a year',
self::AGE_NEGATIVE => 'Date of birth must be in the past',
self::AGE_TOO_YOUNG => 'Check your date of birth is correct - you cannot be an attorney or donor if you’re under 18',
];
self::AGE_TOO_YOUNG => 'Check your date of birth is correct - you cannot be an attorney or donor'
. ' if you’re under 18',
];

/**
* @param mixed $value
Expand Down
Loading
Loading