Lines 100.00% 20 / 20
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 readResponse 100.00% 17 / 17 100.00% 1 / 1 4
 [BO\Zmsbackend\Api\BaseController] __invoke 100.00% 3 / 3 100.00% 1 / 1 1
15class OrganisationByCluster extends \BO\Zmsbackend\Api\BaseController
16{
17    /**
18     * @SuppressWarnings(Param)
19     * @return \Psr\Http\Message\ResponseInterface
20     */
21    #[\Override]
22    public function readResponse(
23        \Psr\Http\Message\RequestInterface $request,
24        \Psr\Http\Message\ResponseInterface $response,
25        array $args
26    ) {
27        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(1)->getValue();
28        $cluster = (new \BO\Zmsbackend\Cluster\Service\Cluster())->readEntity($args['id']);
29        if (! $cluster) {
30            throw new \BO\Zmsbackend\Cluster\Exception\ClusterNotFound();
31        }
32        $organisation = (new Query())->readByClusterId($cluster->id, $resolveReferences);
33        if (! $organisation->hasId()) {
34            throw new \BO\Zmsbackend\Organisation\Exception\OrganisationNotFound();
35        }
36
37        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
38        $user = new \BO\Zmsbackend\Helper\User($request);
39        if ($user->hasLogin()) {
40            $user->checkPermissions('cluster');
41        } else {
42            $organisation = $organisation->withLessData();
43            $message->meta->reducedData = true;
44        }
45        $message->data = $organisation;
46
47        $response = Render::withLastModified($response, time(), '0');
48        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
49        return $response;
50    }
51}

Inherited from BO\Zmsbackend\Api\BaseController

20    public function __invoke(RequestInterface $request, ResponseInterface $response, array $args)
21    {
22        $request = $this->initRequest($request);
23        $noCacheResponse = \BO\Slim\Render::withLastModified($response, time(), '0');
24        return $this->readResponse($request, $noCacheResponse, $args);
25    }