Lines
100.00%
14 / 14
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| SourceUpdate | 100.00% | 14 / 14 | 100.00% | 2 / 2 | 3 | 100.00% | 1 / 1 | |||
| readResponse | 100.00% | 10 / 10 | 100.00% | 1 / 1 | 1 | |||||
| testEntity | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package ZMS API | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsbackend\Source\Api; | |
| 9 | ||
| 10 | use BO\Slim\Render; | |
| 11 | use BO\Mellon\Validator; | |
| 12 | use BO\Zmsbackend\Source\Service\Source as Query; | |
| 13 | use BO\Zmsentities\Source as Entity; | |
| 14 | ||
| 15 | class 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 | $this->testEntity($entity, $input); | |
| 33 | ||
| 34 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 35 | $message->data = (new Query())->writeEntity($entity, $resolveReferences); | |
| 36 | ||
| 37 | $response = Render::withLastModified($response, time(), '0'); | |
| 38 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 39 | return $response; | |
| 40 | } | |
| 41 | ||
| 42 | /** | |
| 43 | * @return void | |
| 44 | */ | |
| 45 | protected function testEntity(Entity $entity, $input) | |
| 46 | { | |
| 47 | try { | |
| 48 | $entity->testValid('de_DE', 1); | |
| 49 | } catch (\Exception $exception) { | |
| 50 | $exception->data['input'] = $input; | |
| 51 | throw $exception; | |
| 52 | } | |
| 53 | } | |
| 54 | } |