Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
89.47% |
17 / 19 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| UpdateKycStatusAction | |
89.47% |
17 / 19 |
|
50.00% |
1 / 2 |
4.02 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
88.89% |
16 / 18 |
|
0.00% |
0 / 1 |
3.01 | |||
| 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 InvalidArgumentException; |
| 10 | use Psr\Http\Message\ResponseInterface; |
| 11 | use Psr\Http\Message\ServerRequestInterface; |
| 12 | |
| 13 | /** |
| 14 | * Handles the action of updating an investor's KYC (Know Your Customer) status. |
| 15 | * |
| 16 | * This class is responsible for processing the HTTP request to update the KYC status |
| 17 | * of a specified investor. It validates the investor ID, the provided KYC status, |
| 18 | * and updates the status using the InvestorService. It also constructs the applicable |
| 19 | * JSON response using the JsonRenderer. |
| 20 | * |
| 21 | * Dependencies: |
| 22 | * - InvestorService: Provides methods to update and manage investor-related data. |
| 23 | * - JsonRenderer: Responsible for rendering JSON responses. |
| 24 | * |
| 25 | * Methods: |
| 26 | * - __construct: Initializes the action with required dependencies. |
| 27 | * - __invoke: Handles the incoming HTTP request, processes the update, and returns an HTTP response. |
| 28 | * |
| 29 | * Exceptions: |
| 30 | * - InvalidArgumentException: Thrown when invalid input (e.g., invalid ID, missing status) is provided. |
| 31 | */ |
| 32 | final readonly class UpdateKycStatusAction |
| 33 | { |
| 34 | public function __construct( |
| 35 | private InvestorService $investorService, |
| 36 | private JsonRenderer $renderer, |
| 37 | ) {} |
| 38 | |
| 39 | /** |
| 40 | * @param array<string, string> $args |
| 41 | * @param ServerRequestInterface $request |
| 42 | * @param ResponseInterface $response |
| 43 | */ |
| 44 | public function __invoke( |
| 45 | ServerRequestInterface $request, |
| 46 | ResponseInterface $response, |
| 47 | array $args, |
| 48 | ): ResponseInterface { |
| 49 | // Get investor ID from route |
| 50 | $investorId = (int)$args['id']; |
| 51 | |
| 52 | // Get KYC status from request body |
| 53 | $data = (array)$request->getParsedBody(); |
| 54 | $status = $data['status'] ?? ''; |
| 55 | |
| 56 | // Validate investor ID |
| 57 | if ($investorId <= 0) { |
| 58 | throw new InvalidArgumentException('Invalid investor ID'); |
| 59 | } |
| 60 | |
| 61 | // Validate status is not empty |
| 62 | if (empty($status)) { |
| 63 | throw new InvalidArgumentException('Status is required'); |
| 64 | } |
| 65 | |
| 66 | // Update KYC status |
| 67 | $investor = $this->investorService->updateKycStatus($investorId, $status); |
| 68 | |
| 69 | // Return updated investor data |
| 70 | return $this->renderer->json($response, [ |
| 71 | 'success' => true, |
| 72 | 'message' => 'KYC status updated successfully', |
| 73 | 'data' => [ |
| 74 | 'investorId' => $investor->investorId, |
| 75 | 'kycStatus' => $investor->kycStatus, |
| 76 | 'status' => $investor->status, |
| 77 | 'updatedAt' => $investor->updatedAt, |
| 78 | ], |
| 79 | ]); |
| 80 | } |
| 81 | } |