Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
25 / 25 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CreateInvestorAction | |
100.00% |
25 / 25 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
23 / 23 |
|
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 class CreateInvestorAction |
| 13 | { |
| 14 | private InvestorService $investorService; |
| 15 | |
| 16 | private JsonRenderer $renderer; |
| 17 | |
| 18 | public function __construct( |
| 19 | InvestorService $investorService, |
| 20 | JsonRenderer $renderer, |
| 21 | ) { |
| 22 | $this->investorService = $investorService; |
| 23 | $this->renderer = $renderer; |
| 24 | } |
| 25 | |
| 26 | public function __invoke( |
| 27 | ServerRequestInterface $request, |
| 28 | ResponseInterface $response, |
| 29 | ): ResponseInterface { |
| 30 | // Get request data |
| 31 | $data = (array)$request->getParsedBody(); |
| 32 | |
| 33 | // Create investor |
| 34 | $investor = $this->investorService->createInvestor($data); |
| 35 | |
| 36 | // Return success response |
| 37 | return $this->renderer->json($response, [ |
| 38 | 'success' => true, |
| 39 | 'message' => 'Investor created successfully', |
| 40 | 'data' => [ |
| 41 | 'investorId' => $investor->investorId, |
| 42 | 'firstName' => $investor->firstName, |
| 43 | 'lastName' => $investor->lastName, |
| 44 | 'email' => $investor->email, |
| 45 | 'phone' => $investor->phone, |
| 46 | 'dateOfBirth' => $investor->dateOfBirth, |
| 47 | 'addressLine1' => $investor->addressLine1, |
| 48 | 'addressLine2' => $investor->addressLine2, |
| 49 | 'city' => $investor->city, |
| 50 | 'state' => $investor->state, |
| 51 | 'zipCode' => $investor->zipCode, |
| 52 | 'country' => $investor->country, |
| 53 | 'kycStatus' => $investor->kycStatus, |
| 54 | 'status' => $investor->status, |
| 55 | 'createdAt' => $investor->createdAt, |
| 56 | ], |
| 57 | ], 201); |
| 58 | } |
| 59 | } |