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