Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ProcessNextByScope
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
3
 getProcess
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsapi;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12use BO\Zmsdb\Scope as Query;
13use BO\Zmsentities\Helper\DateTime;
14
15class ProcessNextByScope extends BaseController
16{
17    /**
18     * @SuppressWarnings(Param)
19     * @return String
20     */
21    public function readResponse(
22        \Psr\Http\Message\RequestInterface $request,
23        \Psr\Http\Message\ResponseInterface $response,
24        array $args
25    ) {
26        (new Helper\User($request))->checkRights();
27        $query = new Query();
28        $selectedDate = Validator::param('date')->isString()->getValue();
29        $exclude = Validator::param('exclude')->isString()->getValue();
30        $dateTime = ($selectedDate) ? new DateTime($selectedDate) : \App::$now;
31        $scope = $query->readEntity($args['id']);
32        if (! $scope) {
33            throw new Exception\Scope\ScopeNotFound();
34        }
35        $queueList = $query->readQueueList($scope->id, $dateTime, 1);
36
37        $message = Response\Message::create($request);
38        $message->data = static::getProcess($queueList, $dateTime, $exclude);
39
40        $response = Render::withLastModified($response, time(), '0');
41        $response = Render::withJson($response, $message, 200);
42        return $response;
43    }
44
45    public static function getProcess($queueList, $dateTime, $exclude = null)
46    {
47        $process = $queueList->getNextProcess($dateTime, $exclude);
48        return ($process) ? $process : new \BO\Zmsentities\Process();
49    }
50}