diff --git a/config/auth.php b/config/auth.php index 18290dc..3975db6 100644 --- a/config/auth.php +++ b/config/auth.php @@ -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' + ), ], ], diff --git a/src/Application/Security/Usecases/FindClient/Output.php b/src/Application/Security/Usecases/FindClient/Output.php index ad045f9..55d2fc1 100644 --- a/src/Application/Security/Usecases/FindClient/Output.php +++ b/src/Application/Security/Usecases/FindClient/Output.php @@ -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 $clients + * @param Paginated<\Application\Security\Models\Entities\Client> $clients */ public function __construct( public Paginated $clients, diff --git a/src/Infra/Adapters/Directories/InMemoryEmployeeDirectory.php b/src/Infra/Adapters/Directories/InMemoryEmployeeDirectory.php index 52ec7a8..7728173 100644 --- a/src/Infra/Adapters/Directories/InMemoryEmployeeDirectory.php +++ b/src/Infra/Adapters/Directories/InMemoryEmployeeDirectory.php @@ -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 $employees + * @return list + */ + 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 $employees + * @return list + */ + 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; } } diff --git a/src/Infra/Adapters/Repositories/InMemoryClientRepository.php b/src/Infra/Adapters/Repositories/InMemoryClientRepository.php index a897b88..db4beec 100644 --- a/src/Infra/Adapters/Repositories/InMemoryClientRepository.php +++ b/src/Infra/Adapters/Repositories/InMemoryClientRepository.php @@ -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; } } diff --git a/src/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsIndexView.php b/src/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsIndexView.php index 5d1fb63..a43398d 100644 --- a/src/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsIndexView.php +++ b/src/Presentation/Api/V1/Presenters/IncoSheets/IncoSheetsIndexView.php @@ -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, diff --git a/src/Presentation/Console/Commands/CreateClientCommand.php b/src/Presentation/Console/Commands/CreateClientCommand.php index 407e6e9..cf180c0 100644 --- a/src/Presentation/Console/Commands/CreateClientCommand.php +++ b/src/Presentation/Console/Commands/CreateClientCommand.php @@ -51,7 +51,6 @@ final class CreateClientCommand extends Command $input = new Input($clientName); - /** @var CreateClientView $view */ $view = UsecaseBuilder::using($executor) ->do($usecase) ->from($input)