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\Investor\Service\InvestorService;
8use App\Renderer\JsonRenderer;
9use InvalidArgumentException;
10use Psr\Http\Message\ResponseInterface;
11use Psr\Http\Message\ServerRequestInterface;
12
13final readonly class UpdateInvestorStatusAction
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        // Get status from request body
34        $data = (array)$request->getParsedBody();
35        $status = $data['status'] ?? '';
36
37        // Validate investor ID
38        if ($investorId <= 0) {
39            throw new InvalidArgumentException('Invalid investor ID');
40        }
41
42        // Validate status is not empty
43        if (empty($status)) {
44            throw new InvalidArgumentException('Status is required');
45        }
46
47        // Update investor status
48        $investor = $this->investorService->updateInvestorStatus($investorId, $status);
49
50        // Return updated investor data
51        return $this->renderer->json($response, [
52            'success' => true,
53            'message' => 'Investor status updated successfully',
54            'data' => [
55                'investorId' => $investor->investorId,
56                'status' => $investor->status,
57                'kycStatus' => $investor->kycStatus,
58                'updatedAt' => $investor->updatedAt,
59            ],
60        ]);
61    }
62}