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
18class OrganisationByScope extends \BO\Zmsbackend\Api\BaseController
19{
20    /**
21     * @SuppressWarnings(Param)
22     * @return \Psr\Http\Message\ResponseInterface
23     */
24    #[\Override]
25    public function readResponse(
26        \Psr\Http\Message\RequestInterface $request,
27        \Psr\Http\Message\ResponseInterface $response,
28        array $args
29    ) {
30        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(1)->getValue();
31        $scope = (new \BO\Zmsbackend\Scope\Service\Scope())->readEntity($args['id'], 0);
32        if (! $scope) {
33            throw new \BO\Zmsbackend\Scope\Exception\ScopeNotFound();
34        }
35        $organisation = (new Query())->readByScopeId($scope->id, $resolveReferences);
36
37        if (! $organisation->hasId()) {
38            throw new \BO\Zmsbackend\Organisation\Exception\OrganisationNotFound();
39        }
40
41        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
42        $user = new \BO\Zmsbackend\Helper\User($request);
43        if ($user->hasLogin()) {
44            $user->checkPermissions();
45        } else {
46            $organisation = $organisation->withLessData();
47            $message->meta->reducedData = true;
48        }
49        $message->data = $organisation;
50
51        $response = Render::withLastModified($response, time(), '0');
52        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
53        return $response;
54    }
55}

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    }