Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| GetAccountAction | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\Account; |
| 6 | |
| 7 | use App\Domain\Account\Service\AccountService; |
| 8 | use App\Renderer\JsonRenderer; |
| 9 | use Psr\Http\Message\ResponseInterface; |
| 10 | use Psr\Http\Message\ServerRequestInterface; |
| 11 | |
| 12 | final class GetAccountAction |
| 13 | { |
| 14 | private AccountService $accountService; |
| 15 | |
| 16 | private JsonRenderer $renderer; |
| 17 | |
| 18 | public function __construct( |
| 19 | AccountService $accountService, |
| 20 | JsonRenderer $renderer, |
| 21 | ) { |
| 22 | $this->accountService = $accountService; |
| 23 | $this->renderer = $renderer; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @param ServerRequestInterface $request |
| 28 | * @param ResponseInterface $response |
| 29 | * @param array<string, string> $args |
| 30 | * |
| 31 | * @return ResponseInterface |
| 32 | */ |
| 33 | public function __invoke( |
| 34 | ServerRequestInterface $request, |
| 35 | ResponseInterface $response, |
| 36 | array $args, |
| 37 | ): ResponseInterface { |
| 38 | $accountId = (int)$args['id']; |
| 39 | |
| 40 | $account = $this->accountService->getAccount($accountId); |
| 41 | |
| 42 | // Convert string values to float for JSON output |
| 43 | return $this->renderer->json($response, [ |
| 44 | 'success' => true, |
| 45 | 'data' => $account, |
| 46 | ]); |
| 47 | } |
| 48 | } |