Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| QuestionCategoryEndpointTrait | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| getEntityData | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| updateEntityWithData | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getEntityById | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Faq\Endpoints; |
| 4 | |
| 5 | use Olz\Entity\Faq\QuestionCategory; |
| 6 | use Olz\Utils\WithUtilsTrait; |
| 7 | use PhpTypeScriptApi\HttpError; |
| 8 | |
| 9 | /** |
| 10 | * @phpstan-type OlzQuestionCategoryId int |
| 11 | * @phpstan-type OlzQuestionCategoryData array{ |
| 12 | * position: float, |
| 13 | * name: non-empty-string, |
| 14 | * } |
| 15 | */ |
| 16 | trait QuestionCategoryEndpointTrait { |
| 17 | use WithUtilsTrait; |
| 18 | |
| 19 | /** @return OlzQuestionCategoryData */ |
| 20 | public function getEntityData(QuestionCategory $entity): array { |
| 21 | return [ |
| 22 | 'position' => $entity->getPosition(), |
| 23 | 'name' => $entity->getName() ? $entity->getName() : '-', |
| 24 | ]; |
| 25 | } |
| 26 | |
| 27 | /** @param OlzQuestionCategoryData $input_data */ |
| 28 | public function updateEntityWithData(QuestionCategory $entity, array $input_data): void { |
| 29 | $entity->setPosition(intval($input_data['position'])); |
| 30 | $entity->setName($input_data['name']); |
| 31 | } |
| 32 | |
| 33 | protected function getEntityById(int $id): QuestionCategory { |
| 34 | $repo = $this->entityManager()->getRepository(QuestionCategory::class); |
| 35 | $entity = $repo->findOneBy(['id' => $id]); |
| 36 | if (!$entity) { |
| 37 | throw new HttpError(404, "Nicht gefunden."); |
| 38 | } |
| 39 | return $entity; |
| 40 | } |
| 41 | } |