Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.15% covered (success)
96.15%
25 / 26
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
GetInvestorAction
96.15% covered (success)
96.15%
25 / 26
50.00% covered (danger)
50.00%
1 / 2
3
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
96.00% covered (success)
96.00%
24 / 25
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\Investor;
6
7use App\Domain\Investor\Service\InvestorService;
8use App\Renderer\JsonRenderer;
9use InvalidArgumentException;
10use Psr\Http\Message\ResponseInterface;
11use Psr\Http\Message\ServerRequestInterface;
12
13final readonly class GetInvestorAction
14{
15    public function __construct(
16        private InvestorService $investorService,
17        private JsonRenderer $renderer
18    ) {}
19
20    /**
21     * @param array<string, string> $args
22     * @param ServerRequestInterface $request
23     * @param ResponseInterface $response
24     */
25    public function __invoke(
26        ServerRequestInterface $request,
27        ResponseInterface $response,
28        array $args,
29    ): ResponseInterface {
30        // Get investor ID from route
31        $investorId = (int)$args['id'];
32
33        // Validate investor ID
34        if ($investorId <= 0) {
35            throw new InvalidArgumentException('Invalid investor ID');
36        }
37
38        // Get investor
39        $investor = $this->investorService->getInvestor($investorId);
40
41        // Return investor data
42        return $this->renderer->json($response, [
43            'success' => true,
44            'data' => [
45                'investorId' => $investor->investorId,
46                'firstName' => $investor->firstName,
47                'lastName' => $investor->lastName,
48                'email' => $investor->email,
49                'phone' => $investor->phone,
50                'dateOfBirth' => $investor->dateOfBirth,
51                'addressLine1' => $investor->addressLine1,
52                'addressLine2' => $investor->addressLine2,
53                'city' => $investor->city,
54                'state' => $investor->state,
55                'zipCode' => $investor->zipCode,
56                'country' => $investor->country,
57                'kycStatus' => $investor->kycStatus,
58                'status' => $investor->status,
59                'createdAt' => $investor->createdAt,
60                'updatedAt' => $investor->updatedAt,
61            ],
62        ]);
63    }
64}