Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
CheckEligibilityAction
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __invoke
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\Loan;
6
7use App\Domain\Loan\Service\LoanService;
8use App\Renderer\JsonRenderer;
9use App\Support\Row;
10use Psr\Http\Message\ResponseInterface;
11use Psr\Http\Message\ServerRequestInterface;
12use RuntimeException;
13
14final 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}