Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ListPendingDisbursementsAction | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\Disbursement; |
| 6 | |
| 7 | use App\Domain\Disbursement\Service\DisbursementService; |
| 8 | use App\Domain\Exception\ForbiddenException; |
| 9 | use App\Renderer\JsonRenderer; |
| 10 | use App\Support\Row; |
| 11 | use Psr\Http\Message\ResponseInterface; |
| 12 | use Psr\Http\Message\ServerRequestInterface; |
| 13 | |
| 14 | final readonly class ListPendingDisbursementsAction |
| 15 | { |
| 16 | public function __construct( |
| 17 | private DisbursementService $disbursementService, |
| 18 | private JsonRenderer $renderer, |
| 19 | ) {} |
| 20 | |
| 21 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
| 22 | { |
| 23 | $attributes = $request->getAttributes(); |
| 24 | $role = Row::nullableString($attributes, 'userRole') ?? ''; |
| 25 | if ($role !== 'admin' && $role !== 'super_admin') { |
| 26 | throw new ForbiddenException('Admin access required'); |
| 27 | } |
| 28 | |
| 29 | $pending = $this->disbursementService->listPending(); |
| 30 | |
| 31 | return $this->renderer->json($response, [ |
| 32 | 'success' => true, |
| 33 | 'data' => [ |
| 34 | 'disbursements' => array_map(static fn($d): array => $d->toArray(), $pending), |
| 35 | ], |
| 36 | ]); |
| 37 | } |
| 38 | } |