Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| FundsFinder | |
0.00% |
0 / 24 |
|
0.00% |
0 / 2 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| findFunds | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
90 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Domain\Funds\Service; |
| 6 | |
| 7 | use App\Domain\Funds\Repository\FundsRepository; |
| 8 | use App\Domain\Funds\Data\FundData; |
| 9 | use InvalidArgumentException; |
| 10 | |
| 11 | final class FundsFinder |
| 12 | { |
| 13 | private const VALID_TYPES = [ |
| 14 | 'Private Equity', |
| 15 | 'Credit', |
| 16 | 'Real Assets', |
| 17 | 'Real Estate', |
| 18 | 'Hedge', |
| 19 | 'Other', |
| 20 | ]; |
| 21 | |
| 22 | private const VALID_STATUSES = [ |
| 23 | 'Active', |
| 24 | 'Raising', |
| 25 | 'Closed', |
| 26 | 'Coming Soon', |
| 27 | ]; |
| 28 | |
| 29 | private const MAX_LIMIT = 100; |
| 30 | |
| 31 | public function __construct( |
| 32 | private readonly FundsRepository $repository, |
| 33 | ) {} |
| 34 | |
| 35 | /** |
| 36 | * @return array{data: list<FundData>, total: int, page: int, limit: int} |
| 37 | */ |
| 38 | public function findFunds( |
| 39 | int $page = 1, |
| 40 | int $limit = 25, |
| 41 | ?string $search = null, |
| 42 | ?string $type = null, |
| 43 | ?string $status = null, |
| 44 | ?bool $published = null, |
| 45 | ): array { |
| 46 | if ($page < 1) { |
| 47 | $page = 1; |
| 48 | } |
| 49 | |
| 50 | if ($limit < 1) { |
| 51 | throw new InvalidArgumentException('Limit must be at least 1'); |
| 52 | } |
| 53 | |
| 54 | $limit = min($limit, self::MAX_LIMIT); |
| 55 | |
| 56 | if ($type !== null && $type !== '' && !in_array($type, self::VALID_TYPES, true)) { |
| 57 | throw new InvalidArgumentException('Invalid funds type'); |
| 58 | } |
| 59 | |
| 60 | if ($status !== null && $status !== '' && !in_array($status, self::VALID_STATUSES, true)) { |
| 61 | throw new InvalidArgumentException('Invalid funds status'); |
| 62 | } |
| 63 | |
| 64 | $result = $this->repository->findFunds( |
| 65 | page: $page, |
| 66 | limit: $limit, |
| 67 | search: $search, |
| 68 | type: $type, |
| 69 | status: $status, |
| 70 | published: $published, |
| 71 | ); |
| 72 | |
| 73 | return [ |
| 74 | 'data' => $result['data'], |
| 75 | 'total' => $result['total'], |
| 76 | 'page' => $page, |
| 77 | 'limit' => $limit, |
| 78 | ]; |
| 79 | } |
| 80 | } |
| 81 |