Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
EditNewsEndpoint
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 configure
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 handle
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Olz\News\Endpoints;
4
5use Olz\Api\OlzEditEntityTypedEndpoint;
6use PhpTypeScriptApi\HttpError;
7
8/**
9 * @phpstan-import-type OlzNewsId from NewsEndpointTrait
10 * @phpstan-import-type OlzNewsData from NewsEndpointTrait
11 *
12 * TODO: Those should not be necessary!
13 * @phpstan-import-type OlzNewsFormat from NewsEndpointTrait
14 *
15 * @extends OlzEditEntityTypedEndpoint<OlzNewsId, OlzNewsData>
16 */
17class EditNewsEndpoint extends OlzEditEntityTypedEndpoint {
18    use NewsEndpointTrait;
19
20    public function configure(): void {
21        parent::configure();
22        $this->configureNewsEndpointTrait();
23        $this->phpStanUtils->registerTypeImport(NewsEndpointTrait::class);
24    }
25
26    protected function handle(mixed $input): mixed {
27        $this->checkPermission('any');
28
29        $entity = $this->getEntityById($input['id']);
30
31        if (!$this->entityUtils()->canUpdateOlzEntity($entity, null, 'news')) {
32            throw new HttpError(403, "Kein Zugriff!");
33        }
34
35        $this->editUploads($entity);
36
37        return [
38            'id' => $entity->getId() ?? 0,
39            'meta' => $entity->getMetaData(),
40            'data' => $this->getEntityData($entity),
41        ];
42    }
43}