Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
CreateQuestionEndpoint
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
2
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%
10 / 10
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\Question;
7
8/**
9 * @phpstan-import-type OlzQuestionId from QuestionEndpointTrait
10 * @phpstan-import-type OlzQuestionData from QuestionEndpointTrait
11 *
12 * @extends OlzCreateEntityTypedEndpoint<OlzQuestionId, OlzQuestionData>
13 */
14class CreateQuestionEndpoint extends OlzCreateEntityTypedEndpoint {
15    use QuestionEndpointTrait;
16
17    public function configure(): void {
18        parent::configure();
19        $this->phpStanUtils->registerTypeImport(QuestionEndpointTrait::class);
20    }
21
22    protected function handle(mixed $input): mixed {
23        $this->checkPermission('faq');
24
25        $entity = new Question();
26        $this->entityUtils()->createOlzEntity($entity, $input['meta']);
27        $this->updateEntityWithData($entity, $input['data']);
28
29        $this->entityManager()->persist($entity);
30        $this->entityManager()->flush();
31        $this->persistUploads($entity, $input['data']);
32
33        return [
34            'id' => $entity->getId() ?? 0,
35        ];
36    }
37}