Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
GetPendingLoansAction
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __invoke
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\Loan;
6
7use App\Domain\Exception\ForbiddenException;
8use App\Domain\Loan\Service\LoanService;
9use App\Renderer\JsonRenderer;
10use Psr\Http\Message\ResponseInterface;
11use Psr\Http\Message\ServerRequestInterface;
12
13final readonly class GetPendingLoansAction
14{
15    public function __construct(
16        private LoanService $loanService,
17        private JsonRenderer $renderer,
18    ) {}
19
20    public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
21    {
22        $role = (string)$request->getAttribute('userRole');
23        if ($role !== 'admin' && $role !== 'super_admin') {
24            throw new ForbiddenException('Admin access required');
25        }
26
27        $loans = $this->loanService->getPendingLoans();
28        $config = $this->loanService->getConfig();
29
30        return $this->renderer->json($response, [
31            'success' => true,
32            'data' => [
33                'loans' => array_map(static fn($l) => $l->toArray(), $loans),
34                'config' => [
35                    'defaultInterestRate' => $config['default_interest_rate'] ?? '8.00',
36                    'ltvPercentage' => $config['ltv_percentage'] ?? '80.00',
37                ],
38                'availableTerms' => LoanService::getValidTerms(),
39            ],
40        ]);
41    }
42}