Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
41.18% |
7 / 17 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| OfficesServicesRelationsController | |
41.18% |
7 / 17 |
|
50.00% |
1 / 2 |
10.09 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| readResponse | |
33.33% |
5 / 15 |
|
0.00% |
0 / 1 |
8.74 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace BO\Zmscitizenapi\Controllers\Office; |
| 6 | |
| 7 | use App; |
| 8 | use BO\Zmscitizenapi\BaseController; |
| 9 | use BO\Zmscitizenapi\Utils\ErrorMessages; |
| 10 | use BO\Zmscitizenapi\Services\Office\OfficesServicesRelationsService; |
| 11 | use BO\Zmscitizenapi\Services\Core\ValidationService; |
| 12 | use Psr\Http\Message\RequestInterface; |
| 13 | use Psr\Http\Message\ResponseInterface; |
| 14 | use BO\Zmscitizenapi\Controllers\UnpublishedAccessTrait; |
| 15 | |
| 16 | class OfficesServicesRelationsController extends BaseController |
| 17 | { |
| 18 | use UnpublishedAccessTrait; |
| 19 | |
| 20 | private OfficesServicesRelationsService $service; |
| 21 | private bool $showUnpublished; |
| 22 | |
| 23 | public function __construct() |
| 24 | { |
| 25 | $this->service = new OfficesServicesRelationsService(); |
| 26 | $this->initializeUnpublishedAccess(); |
| 27 | } |
| 28 | |
| 29 | public function readResponse(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface |
| 30 | { |
| 31 | $requestErrors = ValidationService::validateServerGetRequest($request); |
| 32 | if (!empty($requestErrors['errors'])) { |
| 33 | return $this->createJsonResponse( |
| 34 | $response, |
| 35 | $requestErrors, |
| 36 | ErrorMessages::get('invalidRequest', $this->language)['statusCode'] |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | $result = $this->service->getServicesAndOfficesList($this->showUnpublished); |
| 41 | |
| 42 | return is_array($result) && isset($result['errors']) |
| 43 | ? $this->createJsonResponse( |
| 44 | $response, |
| 45 | $result, |
| 46 | ErrorMessages::getHighestStatusCode($result['errors']) |
| 47 | ) |
| 48 | : $this->createJsonResponse($response, $result->toArray(), 200); |
| 49 | } |
| 50 | } |