Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
10 / 11
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ListMyProvidedDocumentsAction
90.91% covered (success)
90.91%
10 / 11
50.00% covered (danger)
50.00%
1 / 2
3.01
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __invoke
90.00% covered (success)
90.00%
9 / 10
0.00% covered (danger)
0.00%
0 / 1
2.00
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\Document\Provided;
6
7use App\Domain\Document\Provided\Service\ProvidedDocumentService;
8use App\Domain\Exception\ForbiddenException;
9use App\Renderer\JsonRenderer;
10use App\Support\Row;
11use Psr\Http\Message\ResponseInterface;
12use Psr\Http\Message\ServerRequestInterface;
13
14/**
15 * The investor's own list of documents an admin has provided to them (FSC-57).
16 */
17final readonly class ListMyProvidedDocumentsAction
18{
19    public function __construct(
20        private ProvidedDocumentService $service,
21        private JsonRenderer $renderer,
22    ) {}
23
24    public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
25    {
26        $investorId = Row::nullableInt($request->getAttributes(), 'investorId');
27        if ($investorId === null) {
28            throw new ForbiddenException('This endpoint requires an investor account.');
29        }
30
31        $documents = $this->service->listForInvestor($investorId);
32
33        return $this->renderer->json($response, [
34            'success' => true,
35            'data' => [
36                'documents' => array_map(static fn($d) => $d->toArray(), $documents),
37            ],
38        ]);
39    }
40}