Lines
89.47%
17 / 19
Functions and Methods
80.00%
4 / 5
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| TicketprinterAccess | 89.47% | 17 / 19 | 80.00% | 4 / 5 | 18.38 | 0.00% | 0 / 1 | |||
| testTicketprinter | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 2 | |||||
| testMatchingClusterAndScopes | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 6 | |||||
| testTicketprinterNotFound | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 3 | |||||
| testTicketprinterIsProtectedEnabled | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 12 | |||||
| testTicketprinterValidHash | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 4 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsbackend\Helper; | |
| 4 | ||
| 5 | use BO\Slim\Render; | |
| 6 | use BO\Zmsbackend\Useraccount\Service\Useraccount; | |
| 7 | ||
| 8 | class TicketprinterAccess | |
| 9 | { | |
| 10 | /** | |
| 11 | * Test if ticketprinter found and if protection is enabled | |
| 12 | * | |
| 13 | * @return array $useraccount | |
| 14 | */ | |
| 15 | public static function testTicketprinter(\BO\Zmsentities\Ticketprinter $entity) | |
| 16 | { | |
| 17 | if ($entity->hasId()) { | |
| 18 | $organisation = (new \BO\Zmsbackend\Organisation\Service\Organisation())->readByHash($entity->hash); | |
| 19 | } | |
| 20 | self::testTicketprinterNotFound($entity); | |
| 21 | self::testTicketprinterValidHash($entity); | |
| 22 | self::testMatchingClusterAndScopes($entity, $organisation->getId()); | |
| 23 | } | |
| 24 | ||
| 25 | /** | |
| 26 | * @return void | |
| 27 | */ | |
| 28 | public static function testMatchingClusterAndScopes($entity, $organisationId) | |
| 29 | { | |
| 30 | if (isset($entity->buttons) && $entity->buttons) { | |
| 31 | $departmentList = (new \BO\Zmsbackend\Department\Service\Department())->readByOrganisationId($organisationId, 1); | |
| 32 | $scopeList = $departmentList->getUniqueScopeList(); | |
| 33 | //$clusterList = $departmentList->getUniqueClusterList(); | |
| 34 | foreach ($entity->buttons as $button) { | |
| 35 | if ('scope' == $button['type'] && ! $scopeList->hasEntity($button['scope']['id'])) { | |
| 36 | throw new \BO\Zmsbackend\Ticketprinter\Exception\UnvalidButtonList(); | |
| 37 | } /*elseif ('cluster' == $button['type'] && ! $clusterList->hasEntity($button['cluster']['id'])) { | |
| 38 | throw new \BO\Zmsbackend\Ticketprinter\Exception\UnvalidButtonList(); | |
| 39 | }*/ | |
| 40 | } | |
| 41 | } | |
| 42 | } | |
| 43 | ||
| 44 | /** | |
| 45 | * @return void | |
| 46 | */ | |
| 47 | public static function testTicketprinterNotFound($entity) | |
| 48 | { | |
| 49 | if (! $entity->hasId() || ! (new \BO\Zmsbackend\Ticketprinter\Service\Ticketprinter())->readByHash($entity->getId())->hasId()) { | |
| 50 | throw new \BO\Zmsbackend\Ticketprinter\Exception\TicketprinterNotFound(); | |
| 51 | } | |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * @psalm-api | |
| 56 | * | |
| 57 | * @return void | |
| 58 | */ | |
| 59 | public static function testTicketprinterIsProtectedEnabled($entity, bool $isProtectionEnabled) | |
| 60 | { | |
| 61 | if ($isProtectionEnabled && ! $entity->isEnabled()) { | |
| 62 | throw new \BO\Zmsbackend\Ticketprinter\Exception\TicketprinterNotEnabled(); | |
| 63 | } | |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * @return void | |
| 68 | */ | |
| 69 | public static function testTicketprinterValidHash($entity) | |
| 70 | { | |
| 71 | if ( | |
| 72 | isset($entity->id) && | |
| 73 | $entity->id && | |
| 74 | (new \BO\Zmsbackend\Ticketprinter\Service\Ticketprinter())->readByHash($entity->hash)->id != $entity->id | |
| 75 | ) { | |
| 76 | throw new \BO\Zmsbackend\Ticketprinter\Exception\TicketprinterHashNotValid(); | |
| 77 | } | |
| 78 | } | |
| 79 | } |