Lines 100.00% 25 / 25
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 readResponse 100.00% 22 / 22 100.00% 1 / 1 7
 [BO\Zmsbackend\Api\BaseController] __invoke 100.00% 3 / 3 100.00% 1 / 1 1
14class ProcessFree 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        $slotsRequired = Validator::param('slotsRequired')->isNumber()->getValue();
27        $groupData = Validator::param('groupData')->isNumber()->getValue();
28        $slotType = Validator::param('slotType')->isString()->getValue();
29        $keepLessData = Validator::param('keepLessData')->isArray()->setDefault([])->getValue();
30        if ($slotType || $slotsRequired) {
31            (new \BO\Zmsbackend\Helper\User($request))->checkPermissions();
32        } else {
33            $slotsRequired = 0;
34            $slotType = 'public';
35        }
36
37        $calendarData = Validator::input()->isJson()->assertValid()->getValue();
38        $calendar = new \BO\Zmsentities\Calendar($calendarData);
39        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
40        $processList = (new Query())
41            ->readFreeProcesses($calendar, \App::getNow(), $slotType, $slotsRequired, $groupData ? true : false)
42            ->withLessData($keepLessData)
43        ;
44        if ($groupData && count($processList) >= $groupData) {
45            $processList = $processList->withUniqueScope(true);
46        } elseif ($groupData) {
47            $processList = $processList->withUniqueScope(false);
48        }
49        $message->data = $processList;
50
51        $response = Render::withLastModified($response, time(), '0');
52        return Render::withJson($response, $message, 200);
53    }
54}

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    }