Lines 81.81% 18 / 22
Methods 66.66% 2 / 3
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 readResponse 73.33% 11 / 15 0.00% 0 / 1 3.17
 testEntity 100.00% 4 / 4 100.00% 1 / 1 2
 [BO\Zmsbackend\Api\BaseController] __invoke 100.00% 3 / 3 100.00% 1 / 1 1
15class SourceUpdate 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        (new \BO\Zmsbackend\Helper\User($request))->checkPermissions('source');
28        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(0)->getValue();
29        $input = Validator::input()->isJson()->assertValid()->getValue();
30
31        $entity = new Entity($input);
32        if (!is_array($input)) {
33            try {
34                $entity->testValid('de_DE', 1);
35            } catch (\Exception $exception) {
36                $exception->data['input'] = $input;
37                throw $exception;
38            }
39        } else {
40            $this->testEntity($entity, $input);
41        }
42
43        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
44        $message->data = (new Query())->writeEntity($entity, $resolveReferences);
45
46        $response = Render::withLastModified($response, time(), '0');
47        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
48        return $response;
49    }
50
51    /**
52     * @return void
53     */
54    protected function testEntity(Entity $entity, array $input)
55    {
56        try {
57            $entity->testValid('de_DE', 1);
58        } catch (\Exception $exception) {
59            $exception->data['input'] = $input;
60            throw $exception;
61        }
62    }
63}

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    }