Lines 98.03% 50 / 51
Methods 50.00% 1 / 2
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 readResponse 97.91% 47 / 48 0.00% 0 / 1 8
 [BO\Zmsbackend\Api\BaseController] __invoke 100.00% 3 / 3 100.00% 1 / 1 1
15class ProcessSearch 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        $workstation = (new \BO\Zmsbackend\Helper\User($request, 2))->checkPermissions('customersearch');
28        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(0)->getValue();
29        $lessResolvedData = Validator::param('lessResolvedData')->isNumber()->setDefault(0)->getValue();
30
31        $requestedPage = (int) (Validator::param('page')->isNumber()->setDefault(1)->getValue() ?? 1);
32        $requestedLimit = (int) (
33            Validator::param('limit')->isNumber()->setDefault(SearchPagination::DEFAULT_RESULTS_PER_PAGE)->getValue()
34            ?? SearchPagination::DEFAULT_RESULTS_PER_PAGE
35        );
36        $page = SearchPagination::normalizePage($requestedPage);
37        $resultsPerPage = SearchPagination::normalizeResultsPerPage($requestedLimit);
38        $offset = SearchPagination::offset($page, $resultsPerPage);
39
40        $parameters = $request->getParams();
41        unset($parameters['denyHistory']);
42        unset($parameters['resolveReferences']);
43        unset($parameters['lessResolvedData']);
44        unset($parameters['limit']);
45        unset($parameters['page']);
46        unset($parameters['status']);
47
48        foreach (['service', 'provider', 'date'] as $filterKey) {
49            if (!isset($parameters[$filterKey]) || trim((string) $parameters[$filterKey]) === '') {
50                unset($parameters[$filterKey]);
51            }
52        }
53
54        $useraccount = $workstation->getUseraccount();
55
56        if (!$useraccount->isSuperUser()) {
57            $scopeIds = $workstation->getUseraccount()
58                ->getDepartmentList()
59                ->getUniqueScopeList()
60                ->getIds();
61            $parameters['scopeIds'] = implode(',', $scopeIds);
62        }
63
64        $parameters['denyHistory'] = !(
65            $useraccount->isSuperUser()
66            || $useraccount->hasRole('appointment_admin')
67            || $useraccount->hasRole('audit_viewer')
68        );
69
70        $processQuery = new ProcessSearchService();
71        $totalCount = $processQuery->readSearchCount($parameters);
72        $processList = $processQuery->readSearch($parameters, $resolveReferences, $resultsPerPage, $offset);
73        if ($lessResolvedData) {
74            $processList = $processList->withLessData([
75                'createTimestamp',
76            ]);
77        }
78
79        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
80        $message->data = $processList->withAccess($workstation->getUseraccount());
81        $message->meta->totalCount = $totalCount;
82        $message->meta->page = $page;
83        $message->meta->limit = $resultsPerPage;
84
85        $response = Render::withLastModified($response, time(), '0');
86        $response = Render::withJson($response, $message, 200);
87        return $response;
88    }
89}

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    }