fix(quality): resolve PHP_CodeSniffer warnings and errors

This commit is contained in:
Jérémy Munsch 2026-08-18 18:25:04 +02:00
parent bad76036f1
commit 2d46f774b3
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
6 changed files with 73 additions and 42 deletions

View file

@ -132,7 +132,10 @@ return [
'id' => env('ARCADIA_DEV_CLIENT_ID', '01915ec0-0000-7000-8000-000000000001'),
'name' => env('ARCADIA_DEV_CLIENT_NAME', 'Arcadia Dev Test Client'),
'identifier' => env('ARCADIA_DEV_CLIENT_IDENTIFIER', 'arcadia_id_00000000000000000000000000000001'),
'secret' => env('ARCADIA_DEV_CLIENT_SECRET', 'arcadia_sec_00000000000000000000000000000000000000000000000000000000000000000000000000000000000001'),
'secret' => env(
'ARCADIA_DEV_CLIENT_SECRET',
'arcadia_sec_00000000000000000000000000000000000000000000000000000000000000000000000000000000000001'
),
],
],

View file

@ -4,14 +4,13 @@ declare(strict_types=1);
namespace Application\Security\Usecases\FindClient;
use Application\Security\Models\Entities\Client;
use Shared\DDD\Usecase\Output as BaseOutput;
use Shared\Paginated;
final readonly class Output implements BaseOutput
{
/**
* @param Paginated<Client> $clients
* @param Paginated<\Application\Security\Models\Entities\Client> $clients
*/
public function __construct(
public Paginated $clients,

View file

@ -44,35 +44,67 @@ final class InMemoryEmployeeDirectory implements EmployeeDirectory
EmployeeSorter $sorter,
?EmployeeFilter $filter = null,
): Paginated {
$filtered = array_values($this->employees);
$items = array_values($this->employees);
if ($filter !== null) {
$filtered = array_filter($filtered, static function (Employee $employee) use ($filter): bool {
if ($filter->establishment !== null && $employee->establishment->value !== $filter->establishment->value) {
return false;
}
if (! empty($filter->sites)) {
$siteValues = array_map(static fn ($site): string => $site->value, $filter->sites);
if (! in_array($employee->site->value, $siteValues, true)) {
return false;
}
}
if ($filter->service !== null && $employee->service->value !== $filter->service->value) {
return false;
}
if ($filter->since !== null && $employee->startDate < $filter->since) {
return false;
}
return true;
});
$filtered = array_values($filtered);
$items = $this->applyFilter($items, $filter);
}
usort($filtered, static function (Employee $a, Employee $b) use ($sorter): int {
$items = $this->applySorting($items, $sorter);
$total = count($items);
$offset = $pagination->from();
$limit = $pagination->pageSize();
$paged = array_slice($items, $offset, $limit);
return new Paginated($pagination, $paged, $total);
}
/**
* @param list<Employee> $employees
* @return list<Employee>
*/
private function applyFilter(array $employees, EmployeeFilter $filter): array
{
$filtered = array_filter(
$employees,
fn (Employee $employee): bool => $this->matchesFilter($employee, $filter)
);
return array_values($filtered);
}
private function matchesFilter(Employee $employee, EmployeeFilter $filter): bool
{
if ($filter->establishment !== null && $employee->establishment->value !== $filter->establishment->value) {
return false;
}
if (! empty($filter->sites)) {
$siteValues = array_map(static fn ($site): string => $site->value, $filter->sites);
if (! in_array($employee->site->value, $siteValues, true)) {
return false;
}
}
if ($filter->service !== null && $employee->service->value !== $filter->service->value) {
return false;
}
if ($filter->since !== null && $employee->startDate < $filter->since) {
return false;
}
return true;
}
/**
* @param list<Employee> $employees
* @return list<Employee>
*/
private function applySorting(array $employees, EmployeeSorter $sorter): array
{
usort($employees, static function (Employee $a, Employee $b) use ($sorter): int {
$cmp = match ($sorter->sortBy) {
EmployeeSortColumn::arcadiaId => strcmp($a->publicEmployeeNumber->value, $b->publicEmployeeNumber->value),
EmployeeSortColumn::startDate => $a->startDate <=> $b->startDate,
@ -85,11 +117,6 @@ final class InMemoryEmployeeDirectory implements EmployeeDirectory
return $sorter->direction === \SortDirection::Ascending ? $cmp : -$cmp;
});
$total = count($filtered);
$offset = $pagination->from();
$limit = $pagination->pageSize();
$paged = array_slice($filtered, $offset, $limit);
return new Paginated($pagination, $paged, $total);
return $employees;
}
}

View file

@ -73,12 +73,12 @@ final class InMemoryClientRepository implements ClientRepository
$matches = [];
foreach ($this->clients as $client) {
if (
str_contains(strtolower($client->name->value), $trimmed) || // Check if the query matches any of the client's properties (name, slug, identifier, or id)
str_contains(strtolower(Str::slug($client->name->value)), $trimmed) || // Check if the query matches the slug of the client's name
str_contains(strtolower($client->identifier->value), $trimmed) || // Check if the query matches the client's identifier or id
str_contains(strtolower($client->id->value), $trimmed) // Check if the query matches the client's id
) {
$nameMatches = str_contains(strtolower($client->name->value), $trimmed);
$slugMatches = str_contains(strtolower(Str::slug($client->name->value)), $trimmed);
$identifierMatches = str_contains(strtolower($client->identifier->value), $trimmed);
$idMatches = str_contains(strtolower($client->id->value), $trimmed);
if ($nameMatches || $slugMatches || $identifierMatches || $idMatches) {
$matches[] = $client;
}
}

View file

@ -7,7 +7,10 @@ namespace Presentation\Api\V1\Presenters\IncoSheets;
final readonly class IncoSheetsIndexView
{
/**
* @param (\Application\Arcadia\Usecase\IncoSheets\FindAll\PaginatedIncoSheet|\Application\Arcadia\Usecase\IncoSheets\FindAll\PaginatedShortIncoSheet)[] $incoSheets
* @param list<
* \Application\Arcadia\Usecase\IncoSheets\FindAll\PaginatedIncoSheet
* |\Application\Arcadia\Usecase\IncoSheets\FindAll\PaginatedShortIncoSheet
* > $incoSheets
*/
public function __construct(
public array $incoSheets,

View file

@ -51,7 +51,6 @@ final class CreateClientCommand extends Command
$input = new Input($clientName);
/** @var CreateClientView $view */
$view = UsecaseBuilder::using($executor)
->do($usecase)
->from($input)