Lines 100.00% 26 / 26
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 readResponse 100.00% 23 / 23 100.00% 1 / 1 6
 [BO\Zmsbackend\Api\BaseController] __invoke 100.00% 3 / 3 100.00% 1 / 1 1
14class ScopeGet extends \BO\Zmsbackend\Api\BaseController
15{
16    /**
17     * @SuppressWarnings(Param)
18     * @return \Psr\Http\Message\ResponseInterface
19     */
20    #[\Override]
21    public function readResponse(
22        \Psr\Http\Message\RequestInterface $request,
23        \Psr\Http\Message\ResponseInterface $response,
24        array $args
25    ) {
26        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
27        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(0)->getValue();
28        $keepLessData = Validator::param('keepLessData')->isArray()->setDefault([])->getValue();
29        $hasGQL = Validator::param('gql')->isString()->getValue();
30        $accessRights = Validator::param('accessRights')->isString()->isBiggerThan(4)->getValue();
31        $getIsOpened = Validator::param('getIsOpened')->isNumber()->setDefault(0)->getValue();
32        $scope = (new \BO\Zmsbackend\Scope\Service\Scope())->readEntity($args['id'], $resolveReferences);
33        if (! $scope) {
34            throw new \BO\Zmsbackend\Scope\Exception\ScopeNotFound();
35        }
36
37        $userAccess = new \BO\Zmsbackend\Helper\User($request, 2);
38        if ($userAccess->hasLogin()) {
39            $entityAccess = new \BO\Zmsentities\Useraccount\EntityAccess($scope);
40            if ($accessRights) {
41                $userAccess->checkPermissions($accessRights, $entityAccess);
42            } else {
43                $userAccess->checkPermissions($entityAccess);
44            }
45        } else {
46            $scope = ($hasGQL) ? $scope : $scope->withLessData($keepLessData);
47            $message->meta->reducedData = true;
48        }
49
50        if ($getIsOpened) {
51            $scope->setStatusAvailability('isOpened', (new \BO\Zmsbackend\Scope\Service\Scope())->readIsOpened($scope->getId(), \App::$now));
52        }
53        $message->data = $scope;
54
55        $response = Render::withLastModified($response, time(), '0');
56        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
57        return $response;
58    }
59}

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    }