Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
21 / 21 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
TerminLocationEndpointTrait | |
100.00% |
21 / 21 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
getEntityData | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
updateEntityWithData | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
persistUploads | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
editUploads | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getEntityById | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Olz\Termine\Endpoints; |
4 | |
5 | use Olz\Entity\Termine\TerminLocation; |
6 | use Olz\Utils\WithUtilsTrait; |
7 | use PhpTypeScriptApi\HttpError; |
8 | |
9 | /** |
10 | * Note: `latitude` may be from -90.0 to 90.0, `longitude` from -180.0 to 180.0. |
11 | * |
12 | * @phpstan-type OlzTerminLocationId int |
13 | * @phpstan-type OlzTerminLocationData array{ |
14 | * name: non-empty-string, |
15 | * details: string, |
16 | * latitude: float, |
17 | * longitude: float, |
18 | * imageIds: array<non-empty-string>, |
19 | * } |
20 | */ |
21 | trait TerminLocationEndpointTrait { |
22 | use WithUtilsTrait; |
23 | |
24 | /** @return OlzTerminLocationData */ |
25 | public function getEntityData(TerminLocation $entity): array { |
26 | $valid_image_ids = $this->uploadUtils()->getValidUploadIds($entity->getImageIds()); |
27 | |
28 | return [ |
29 | 'name' => $entity->getName() ?: '-', |
30 | 'details' => $entity->getDetails() ?? '', |
31 | 'latitude' => $entity->getLatitude(), |
32 | 'longitude' => $entity->getLongitude(), |
33 | 'imageIds' => $valid_image_ids, |
34 | ]; |
35 | } |
36 | |
37 | /** @param OlzTerminLocationData $input_data */ |
38 | public function updateEntityWithData(TerminLocation $entity, array $input_data): void { |
39 | $valid_image_ids = $this->uploadUtils()->getValidUploadIds($input_data['imageIds']); |
40 | |
41 | $entity->setName($input_data['name']); |
42 | $entity->setDetails($input_data['details']); |
43 | $entity->setLatitude($input_data['latitude']); |
44 | $entity->setLongitude($input_data['longitude']); |
45 | $entity->setImageIds($valid_image_ids); |
46 | } |
47 | |
48 | public function persistUploads(TerminLocation $entity): void { |
49 | $this->persistOlzImages($entity, $entity->getImageIds()); |
50 | } |
51 | |
52 | public function editUploads(TerminLocation $entity): void { |
53 | $this->editOlzImages($entity, $entity->getImageIds()); |
54 | } |
55 | |
56 | protected function getEntityById(int $id): TerminLocation { |
57 | $repo = $this->entityManager()->getRepository(TerminLocation::class); |
58 | $entity = $repo->findOneBy(['id' => $id]); |
59 | if (!$entity) { |
60 | throw new HttpError(404, "Nicht gefunden."); |
61 | } |
62 | return $entity; |
63 | } |
64 | } |