Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
CalldisplayGet
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
2 / 2
8
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
 testScopeAndCluster
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
7
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\Calldisplay as Query;
13use BO\Zmsentities\Calldisplay as Entity;
14
15/**
16 * @SuppressWarnings(Coupling)
17 * @return \Psr\Http\Message\ResponseInterface
18 */
19class CalldisplayGet extends BaseController
20{
21    /**
22     * @SuppressWarnings(Param)
23     * @return \Psr\Http\Message\ResponseInterface
24     */
25    #[\Override]
26    public function readResponse(
27        \Psr\Http\Message\RequestInterface $request,
28        \Psr\Http\Message\ResponseInterface $response,
29        array $args
30    ) {
31        $query = new Query();
32        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(1)->getValue();
33        $input = Validator::input()->isJson()->assertValid()->getValue();
34        $entity = new Entity($input);
35
36        $this->testScopeAndCluster($entity);
37        $message = Response\Message::create($request);
38        $message->data = $query->readResolvedEntity($entity, \App::getNow(), $resolveReferences);
39
40        $response = Render::withLastModified($response, time(), '0');
41        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
42        return $response;
43    }
44
45    protected function testScopeAndCluster($calldisplay)
46    {
47        if (! $calldisplay->hasScopeList() && ! $calldisplay->hasClusterList()) {
48            throw new Exception\Calldisplay\ScopeAndClusterNotFound();
49        }
50        foreach ($calldisplay->getClusterList() as $cluster) {
51            $cluster = (new \BO\Zmsdb\Cluster())->readEntity($cluster->id);
52            if (! $cluster) {
53                throw new Exception\Cluster\ClusterNotFound();
54            }
55        }
56        foreach ($calldisplay->getScopeList() as $scope) {
57            $scope = (new \BO\Zmsdb\Scope())->readEntity($scope->id);
58            if (! $scope) {
59                throw new Exception\Scope\ScopeNotFound();
60            }
61        }
62    }
63}