Skip to content

Commit a0ecaab

Browse files
committed
4680: Applied coding standards
1 parent 459dfb3 commit a0ecaab

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7-
- [#244](https://github.com/os2display/display-api-service/pull/244)
7+
- [#245](https://github.com/os2display/display-api-service/pull/245)
88
- Added resource endpoint for limiting access to instant book interactive slide.
99
- [#243](https://github.com/os2display/display-api-service/pull/243)
1010
- Changed resource name in calendar api feed type resource selector.

src/InteractiveSlide/InstantBook.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use App\Entity\Tenant\InteractiveSlide;
1010
use App\Entity\Tenant\Slide;
1111
use App\Entity\User;
12-
use App\Exceptions\InteractiveSlideException;
1312
use App\Service\InteractiveSlideService;
1413
use App\Service\KeyVaultService;
1514
use Psr\Cache\CacheItemInterface;
@@ -256,7 +255,7 @@ private function createEntry(string $resource, array $schedules, string $startFo
256255
*/
257256
private function quickBook(Slide $slide, InteractionSlideRequest $interactionRequest): array
258257
{
259-
$resource = $this->getValueFromInterval('resource', $interactionRequest);
258+
$resource = (string) $this->getValueFromInterval('resource', $interactionRequest);
260259
$durationMinutes = $this->getValueFromInterval('durationMinutes', $interactionRequest);
261260

262261
$now = new \DateTime();
@@ -446,8 +445,9 @@ private function getHeaders(string $token): array
446445

447446
private function checkPermission(InteractiveSlide $interactive, string $resource): void
448447
{
448+
$configuration = $interactive->getConfiguration();
449449
// Optional limiting of available resources.
450-
if (!empty($interactive->getConfiguration()['resourceEndpoint'])) {
450+
if (null !== $configuration && !empty($configuration['resourceEndpoint'])) {
451451
$allowedResources = $this->getAllowedResources($interactive);
452452

453453
if (!in_array($resource, $allowedResources)) {
@@ -458,20 +458,31 @@ private function checkPermission(InteractiveSlide $interactive, string $resource
458458

459459
private function getAllowedResources(InteractiveSlide $interactive): array
460460
{
461-
return $this->interactiveSlideCache->get(self::CACHE_ALLOWED_RESOURCES_PREFIX . $interactive->getId(), function (CacheItemInterface $item) use ($interactive) {
461+
return $this->interactiveSlideCache->get(self::CACHE_ALLOWED_RESOURCES_PREFIX.$interactive->getId(), function (CacheItemInterface $item) use ($interactive) {
462462
$item->expiresAfter(60 * 60);
463463

464464
$configuration = $interactive->getConfiguration();
465-
$resourceEndpoint = $this->keyValueService->getValue($configuration['resourceEndpoint']);
465+
466+
$key = $configuration['resourceEndpoint'] ?? null;
467+
468+
if (null === $key) {
469+
throw new \Exception('resourceEndpoint not set');
470+
}
471+
472+
$resourceEndpoint = $this->keyValueService->getValue($key);
473+
474+
if (null === $resourceEndpoint) {
475+
throw new \Exception('resourceEndpoint value not set');
476+
}
466477

467478
$response = $this->client->request('GET', $resourceEndpoint);
468479
$content = $response->toArray();
469480

470481
$allowedResources = [];
471482

472483
foreach ($content as $resource) {
473-
if ($resource["allowInstantBooking"] === 'True') {
474-
$allowedResources[] = $resource["ResourceMail"];
484+
if ('True' === $resource['allowInstantBooking']) {
485+
$allowedResources[] = $resource['ResourceMail'];
475486
}
476487
}
477488

0 commit comments

Comments
 (0)