Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CheckEligibilityAction | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\Loan; |
| 6 | |
| 7 | use App\Domain\Loan\Service\LoanService; |
| 8 | use App\Renderer\JsonRenderer; |
| 9 | use App\Support\Row; |
| 10 | use Psr\Http\Message\ResponseInterface; |
| 11 | use Psr\Http\Message\ServerRequestInterface; |
| 12 | use RuntimeException; |
| 13 | |
| 14 | final readonly class CheckEligibilityAction |
| 15 | { |
| 16 | public function __construct( |
| 17 | private LoanService $loanService, |
| 18 | private JsonRenderer $renderer |
| 19 | ) {} |
| 20 | |
| 21 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
| 22 | { |
| 23 | $investorId = Row::int($request->getAttributes(), 'investorId'); |
| 24 | $eligibility = $this->loanService->checkEligibility($investorId); |
| 25 | $config = $this->loanService->getConfig(); |
| 26 | |
| 27 | return $this->renderer->json($response, [ |
| 28 | 'success' => true, |
| 29 | 'data' => [ |
| 30 | 'eligibility' => $eligibility->toArray(), |
| 31 | 'availableTerms' => LoanService::getValidTerms(), |
| 32 | 'defaultInterestRate' => $config['default_interest_rate'] |
| 33 | ?? throw new RuntimeException('default_interest_rate is not configured'), |
| 34 | 'servicingFeeRate' => $config['servicing_fee_rate'] ?? '0.00', |
| 35 | ], |
| 36 | ]); |
| 37 | } |
| 38 | } |