Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| AdminService | |
100.00% |
17 / 17 |
|
100.00% |
4 / 4 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getStats | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getInvestorsList | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
4 | |||
| getInvestorDetail | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Domain\Admin\Service; |
| 6 | |
| 7 | use App\Domain\Admin\Data\AdminStatsData; |
| 8 | use App\Domain\Admin\Repository\AdminRepository; |
| 9 | use App\Domain\Exception\NotFoundException; |
| 10 | |
| 11 | /** |
| 12 | * Service for admin operations. |
| 13 | */ |
| 14 | final class AdminService |
| 15 | { |
| 16 | private AdminRepository $repository; |
| 17 | |
| 18 | public function __construct(AdminRepository $repository) |
| 19 | { |
| 20 | $this->repository = $repository; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Get platform statistics. |
| 25 | */ |
| 26 | public function getStats(): AdminStatsData |
| 27 | { |
| 28 | return $this->repository->getStats(); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Get paginated investors list. |
| 33 | * |
| 34 | * @param int $page |
| 35 | * @param int $limit |
| 36 | * @param string|null $search |
| 37 | * @param string|null $kycStatus |
| 38 | * @param string|null $status |
| 39 | * |
| 40 | * @return array{investors: array<int, array<string, mixed>>, total: int, page: int, limit: int} |
| 41 | */ |
| 42 | public function getInvestorsList( |
| 43 | int $page = 1, |
| 44 | int $limit = 20, |
| 45 | ?string $search = null, |
| 46 | ?string $kycStatus = null, |
| 47 | ?string $status = null, |
| 48 | ): array { |
| 49 | // Validate pagination |
| 50 | if ($page < 1) { |
| 51 | $page = 1; |
| 52 | } |
| 53 | if ($limit < 1 || $limit > 100) { |
| 54 | $limit = 20; |
| 55 | } |
| 56 | |
| 57 | $result = $this->repository->getInvestorsList($page, $limit, $search, $kycStatus, $status); |
| 58 | |
| 59 | return [ |
| 60 | 'investors' => $result['investors'], |
| 61 | 'total' => $result['total'], |
| 62 | 'page' => $page, |
| 63 | 'limit' => $limit, |
| 64 | ]; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Get detailed investor information. |
| 69 | * |
| 70 | * @param int $investorId |
| 71 | * |
| 72 | * @throws NotFoundException If investor not found |
| 73 | * |
| 74 | * @return array<string, mixed> |
| 75 | */ |
| 76 | public function getInvestorDetail(int $investorId): array |
| 77 | { |
| 78 | $investor = $this->repository->getInvestorDetail($investorId); |
| 79 | |
| 80 | if ($investor === null) { |
| 81 | throw new NotFoundException('Investor not found'); |
| 82 | } |
| 83 | |
| 84 | return $investor; |
| 85 | } |
| 86 | } |