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