Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
OrganisationByScope
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
4
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\Organisation as Query;
13use BO\Zmsdb\Scope;
14
15/**
16  * Handle requests concerning services
17  */
18class OrganisationByScope extends BaseController
19{
20    /**
21     * @SuppressWarnings(Param)
22     * @return \Psr\Http\Message\ResponseInterface
23     */
24    #[\Override]
25    public function readResponse(
26        \Psr\Http\Message\RequestInterface $request,
27        \Psr\Http\Message\ResponseInterface $response,
28        array $args
29    ) {
30        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(1)->getValue();
31        $scope = (new Scope())->readEntity($args['id'], 0);
32        if (! $scope) {
33            throw new Exception\Scope\ScopeNotFound();
34        }
35        $organisation = (new Query())->readByScopeId($scope->id, $resolveReferences);
36
37        if (! $organisation->hasId()) {
38            throw new Exception\Organisation\OrganisationNotFound();
39        }
40
41        $message = Response\Message::create($request);
42        if ((new Helper\User($request))->hasRights()) {
43            (new Helper\User($request))->checkPermissions();
44        } else {
45            $organisation = $organisation->withLessData();
46            $message->meta->reducedData = true;
47        }
48        $message->data = $organisation;
49
50        $response = Render::withLastModified($response, time(), '0');
51        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
52        return $response;
53    }
54}