Skip to content

Commit

Permalink
phpbfc app/src/Common
Browse files Browse the repository at this point in the history
  • Loading branch information
Lbagg1 committed Nov 2, 2023
1 parent 5560da0 commit ab21061
Show file tree
Hide file tree
Showing 79 changed files with 646 additions and 525 deletions.
16 changes: 11 additions & 5 deletions service-front/app/src/Common/src/Entity/CaseActor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class CaseActor
protected int $id;
protected ?string $uId = null;

/** @var array<array<mixed>>|null */
/**
* @var array<array<mixed>>|null
*/
protected ?array $linked = null;

protected ?string $email = null;
Expand All @@ -23,7 +25,9 @@ class CaseActor
protected ?string $companyName = null;
protected ?bool $systemStatus = null;

/** @var Address[] */
/**
* @var Address[]
*/
protected array $addresses = [];

public function getId(): int
Expand Down Expand Up @@ -55,9 +59,11 @@ public function getIds(): ?array
return [$this->getId()];
}

return array_map(function ($x) {
return $x['id'];
}, $this->linked);
return array_map(
function ($x) {
return $x['id'];
}, $this->linked
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class Images implements JsonSerializable
private const UNKNOWN = '/iap-%s-continuation_unknown/';

/**
* @param int $uId
* @param ImagesStatus $status
* @param array<SignedUrl> $signedUrls
* @param int $uId
* @param ImagesStatus $status
* @param array<SignedUrl> $signedUrls
*/
public function __construct(
public readonly int $uId,
Expand Down Expand Up @@ -56,9 +56,11 @@ protected function getImageRegex(string $format): string
protected function getImageUrls(string $pattern): array
{
return array_values(
array_filter($this->signedUrls, function ($signedUrl) use ($pattern) {
return preg_match($pattern, $signedUrl->imageName);
})
array_filter(
$this->signedUrls, function ($signedUrl) use ($pattern) {
return preg_match($pattern, $signedUrl->imageName);
}
)
);
}

Expand Down
24 changes: 18 additions & 6 deletions service-front/app/src/Common/src/Entity/Lpa.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,34 @@ class Lpa
protected ?string $attorneyActDecisions = null;
protected ?CaseActor $donor = null;

/** @var CaseActor[] */
/**
* @var CaseActor[]
*/
protected array $attorneys = [];

/** @var CaseActor[] */
/**
* @var CaseActor[]
*/
protected array $replacementAttorneys = [];

/** @var CaseActor[] */
/**
* @var CaseActor[]
*/
protected array $certificateProviders = [];

/** @var CaseActor[] */
/**
* @var CaseActor[]
*/
protected array $trustCorporations = [];

/** @var CaseActor[] */
/**
* @var CaseActor[]
*/
protected array $activeAttorneys = [];

/** @var CaseActor[] */
/**
* @var CaseActor[]
*/
protected array $inactiveAttorneys = [];

public function getUId(): ?string
Expand Down
6 changes: 3 additions & 3 deletions service-front/app/src/Common/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function getRoles(): iterable
/**
* Get a detail $name if present, $default otherwise
*
* @param string $name
* @param null $default
* @param string $name
* @param null $default
* @return mixed|null
*/
public function getDetail(string $name, $default = null): mixed
Expand Down Expand Up @@ -88,7 +88,7 @@ public function getDetails(): array
/**
* Attempts to figure out how to construct a valid DateTime from the information made available.
*
* @param array|string $date An array, or string containing a serialised DateTime or ATOM compliant date.
* @param array|string $date An array, or string containing a serialised DateTime or ATOM compliant date.
* @throws Exception
*/
public function setLastLogin(array|string $date): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ abstract class AbstractApiException extends RuntimeException
*
* Following the sprint of https://framework.zend.com/blog/2017-03-23-expressive-error-handling.html
*
* @param string $title
* @param string|null $message
* @param array|null $additionalData
* @param string $title
* @param string|null $message
* @param array|null $additionalData
* @param Throwable|null $previous
*/
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ApiException extends AbstractApiException
public const DEFAULT_TITLE = 'An API exception has occurred';

/**
* @var int|null
* @var int|null
* @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
*/
protected $code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class ActorViewerCodeFilter extends AbstractFilter
{
/**
* @param string $code
* @param string $code
* @return string
*/
public function filter($code): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class ConvertQuotesToApostrophe extends AbstractFilter
{
/**
* @param string $name
* @param string $name
* @return string
*/
public function filter($name): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class StripSpacesAndHyphens extends AbstractFilter
{
/**
* @param string $value
* @param string $value
* @return string
*/
public function filter($value): string
Expand Down
2 changes: 1 addition & 1 deletion service-front/app/src/Common/src/Form/AbstractForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(string $formName, CsrfGuardInterface $csrfGuard)
* Allows the addition of form level error messages to a form. These will typically be displayed at the
* summary level on the page.
*
* @param string $messageKey The key to a message stored in the messageTemplates array of the form
* @param string $messageKey The key to a message stored in the messageTemplates array of the form
* @param string $elementName An optional field name to link the error message to
*/
public function addErrorMessage(string $messageKey, string $elementName = ''): void
Expand Down
12 changes: 8 additions & 4 deletions service-front/app/src/Common/src/Form/CookieConsent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function __construct(CsrfGuardInterface $csrfGuard)
{
parent::__construct(self::FORM_NAME, $csrfGuard);

$this->add([
$this->add(
[
'name' => 'usageCookies',
'type' => 'Radio',
'options' => [
Expand All @@ -31,11 +32,14 @@ public function __construct(CsrfGuardInterface $csrfGuard)
'yes' => 'yes',
],
],
]);
$this->add([
]
);
$this->add(
[
'name' => 'referer',
'type' => 'Hidden',
]);
]
);
}

public function getInputFilterSpecification(): array
Expand Down
18 changes: 12 additions & 6 deletions service-front/app/src/Common/src/Form/Fieldset/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@ public function __construct(?string $name = null, array $options = [])
{
parent::__construct($name, $options);

$this->add([
$this->add(
[
'name' => 'day',
'type' => 'Text',
]);
]
);

$this->add([
$this->add(
[
'name' => 'month',
'type' => 'Text',
]);
]
);

$this->add([
$this->add(
[
'name' => 'year',
'type' => 'Text',
]);
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class DatePrefixFilter extends AbstractFilter
*/
public function filter($value): array
{
if (
$value !== null && !empty($value['day']) && !empty($value['month'])
if ($value !== null && !empty($value['day']) && !empty($value['month'])
&& ($value['day'] <= 9 || $value['month'] <= 9)
) {
return $this->formatWithLeadingZero($value);
Expand All @@ -28,8 +27,8 @@ public function filter($value): array
}

/**
* @param array $value
* @param array $formattedDate
* @param array $value
* @param array $formattedDate
* @return array
*/
protected function formatWithLeadingZero($value): array
Expand Down
8 changes: 4 additions & 4 deletions service-front/app/src/Common/src/Handler/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ public function __construct(
/**
* Handles a request and produces a response
*
* @param ServerRequestInterface $request
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
abstract public function handle(ServerRequestInterface $request): ResponseInterface;

/**
* Redirect to the specified route
*
* @param $route
* @param array $routeParams
* @param array $queryParams
* @param $route
* @param array $routeParams
* @param array $queryParams
* @return RedirectResponse
*/
protected function redirectToRoute($route, $routeParams = [], $queryParams = []): RedirectResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$refererHeader = $request->getHeaders()['referer'][0] ?? null;

$referer = $this->urlValidityCheckService->setValidReferrer($refererHeader);
return new HtmlResponse($this->renderer->render('common::contact-us', [
'referer' => $referer,
]));
return new HtmlResponse(
$this->renderer->render(
'common::contact-us', [
'referer' => $referer,
]
)
);
}
}
22 changes: 15 additions & 7 deletions service-front/app/src/Common/src/Handler/CookiesPageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public function __construct(

public function handle(ServerRequestInterface $request): ResponseInterface
{
/** @var FlashMessagesInterface $flash */
/**
* @var FlashMessagesInterface $flash
*/
$flash = $request->getAttribute(FlashMessageMiddleware::FLASH_ATTRIBUTE);

$form = new CookieConsent($this->getCsrfGuard($request));
Expand All @@ -69,11 +71,15 @@ public function handle(ServerRequestInterface $request): ResponseInterface

$form->get('referer')->setValue($this->urlValidityCheckService->setValidReferrer($cookiesPageReferer));

return new HtmlResponse($this->renderer->render('common::cookies', [
'form' => $form,
'application' => $this->application,
'flash' => $flash,
]));
return new HtmlResponse(
$this->renderer->render(
'common::cookies', [
'form' => $form,
'application' => $this->application,
'flash' => $flash,
]
)
);
}

public function handlePost(ServerRequestInterface $request): ResponseInterface
Expand All @@ -83,7 +89,9 @@ public function handlePost(ServerRequestInterface $request): ResponseInterface

$response = new RedirectResponse($this->urlHelper->generate('cookies'));

/** @var FlashMessagesInterface $flash */
/**
* @var FlashMessagesInterface $flash
*/
$flash = $request->getAttribute(FlashMessageMiddleware::FLASH_ATTRIBUTE);
$flash->flash(self::COOKIES_SET_FLASH_MSG, $form->get('referer')->getValue());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ public function __construct(protected string $version, protected ApiClient $apiC

public function handle(ServerRequestInterface $request): ResponseInterface
{
return new JsonResponse([
return new JsonResponse(
[
'overall_healthy' => $this->isHealthy(),
'version' => $this->version,
'dependencies' => $this->checkDependencyEndpoints(),
], StatusCodeInterface::STATUS_OK, [], JSON_PRETTY_PRINT);
], StatusCodeInterface::STATUS_OK, [], JSON_PRETTY_PRINT
);
}

protected function isHealthy(): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ public function __construct(
/**
* Handles a request and produces a response
*
* @param ServerRequestInterface $request
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$referer = $this->urlValidityCheckService->setValidReferrer($request->getHeaders()['referer'][0]);

return new HtmlResponse($this->renderer->render('common::instructions-preferences-signed-before-2016', [
'referer' => $referer,
]));
return new HtmlResponse(
$this->renderer->render(
'common::instructions-preferences-signed-before-2016', [
'referer' => $referer,
]
)
);
}
}
Loading

0 comments on commit ab21061

Please sign in to comment.