Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
89.47% covered (warning)
89.47%
17 / 19
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UpdateInvestorStatusAction
89.47% covered (warning)
89.47%
17 / 19
50.00% covered (danger)
50.00%
1 / 2
4.02
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
88.89% covered (warning)
88.89%
16 / 18
0.00% covered (danger)
0.00%
0 / 1
3.01
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\Investor;
6
7use App\Domain\Exception\BadRequestException;
8use App\Domain\Exception\ValidationException;
9use App\Domain\Investor\Service\InvestorService;
10use App\Renderer\JsonRenderer;
11use App\Support\Row;
12use Psr\Http\Message\ResponseInterface;
13use Psr\Http\Message\ServerRequestInterface;
14
15final readonly class UpdateInvestorStatusAction
16{
17    public function __construct(
18        private InvestorService $investorService,
19        private JsonRenderer $renderer,
20    ) {}
21
22    /**
23     * @param array<string, string> $args
24     * @param ServerRequestInterface $request
25     * @param ResponseInterface $response
26     */
27    public function __invoke(
28        ServerRequestInterface $request,
29        ResponseInterface $response,
30        array $args,
31    ): ResponseInterface {
32        // Get investor ID from route
33        $investorId = (int)$args['id'];
34
35        // Get status from request body
36        $data = (array)$request->getParsedBody();
37        $status = Row::nullableString($data, 'status') ?? '';
38
39        // Validate investor ID
40        if ($investorId <= 0) {
41            throw new ValidationException('Invalid investor ID');
42        }
43
44        // Validate status is not empty
45        if ($status === '') {
46            throw new BadRequestException('Status is required');
47        }
48
49        // Update investor status
50        $investor = $this->investorService->updateInvestorStatus($investorId, $status);
51
52        // Return updated investor data
53        return $this->renderer->json($response, [
54            'success' => true,
55            'message' => 'Investor status updated successfully',
56            'data' => [
57                'investorId' => $investor->investorId,
58                'status' => $investor->status,
59                'kycStatus' => $investor->kycStatus,
60                'updatedAt' => $investor->updatedAt,
61            ],
62        ]);
63    }
64}