Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
CreateQuestionCategoryEndpoint
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 handle
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Olz\Faq\Endpoints;
4
5use Olz\Api\OlzCreateEntityTypedEndpoint;
6use Olz\Entity\Faq\QuestionCategory;
7
8/**
9 * @phpstan-import-type OlzQuestionCategoryId from QuestionCategoryEndpointTrait
10 * @phpstan-import-type OlzQuestionCategoryData from QuestionCategoryEndpointTrait
11 *
12 * @extends OlzCreateEntityTypedEndpoint<OlzQuestionCategoryId, OlzQuestionCategoryData>
13 */
14class CreateQuestionCategoryEndpoint extends OlzCreateEntityTypedEndpoint {
15    use QuestionCategoryEndpointTrait;
16
17    protected function handle(mixed $input): mixed {
18        $this->checkPermission('faq');
19
20        $entity = new QuestionCategory();
21        $this->entityUtils()->createOlzEntity($entity, $input['meta']);
22        $this->updateEntityWithData($entity, $input['data']);
23
24        $this->entityManager()->persist($entity);
25        $this->entityManager()->flush();
26
27        return [
28            'id' => $entity->getId() ?? 0,
29        ];
30    }
31}