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