Skip to content

Commit

Permalink
Applied coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
martinyde committed Sep 26, 2023
1 parent 27ec803 commit dbc5e3f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 43 deletions.
5 changes: 3 additions & 2 deletions src/Command/UserBookingCacheChangeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class UserBookingCacheChangeCommand extends Command
{
public const DATE_FORMAT = 'Y-m-d\TH:i:s';

public function __construct(
private readonly UserBookingCacheServiceInterface $userBookingCacheServiceInterface
) {
Expand Down Expand Up @@ -44,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
0
);

$fieldValue = $io->ask('Please enter the value for ' .$field .' field (In case of date fields use format ' . UserBookingCacheChangeCommand::DATE_FORMAT . ')');
$fieldValue = $io->ask('Please enter the value for '.$field.' field (In case of date fields use format '.UserBookingCacheChangeCommand::DATE_FORMAT.')');

// Date fields expect Datetime object.
if ('start' === $field || 'end' === $field) {
Expand All @@ -53,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$data[$field] = $fieldValue;

// Info on current state to be changed.
$io->writeln('Making the following changes to Cache Entry with id: ' . $entityId);
$io->writeln('Making the following changes to Cache Entry with id: '.$entityId);
$io->info(json_encode($data));

$another = $io->confirm(
Expand Down
6 changes: 3 additions & 3 deletions src/DataPersister/UserBookingDataPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function remove($data, array $context = []): void
NotificationTypeEnum::DELETE_SUCCESS
));

// @todo enable cache deletion.
//$this->userBookingCacheService->deleteCacheEntry($exchangeId);
// @todo enable cache deletion.
// $this->userBookingCacheService->deleteCacheEntry($exchangeId);
}
} catch (MicrosoftGraphCommunicationException|UserBookingException $e) {
throw new HttpException($e->getCode(), 'Booking could not be deleted.');
Expand All @@ -70,7 +70,7 @@ public function persist($data, array $context = []): mixed
));

// @todo enable cache alteration.
//$this->userBookingCacheService->changeCacheEntry($exchangeId, $newData);
// $this->userBookingCacheService->changeCacheEntry($exchangeId, $newData);
}

return $data;
Expand Down
10 changes: 5 additions & 5 deletions src/Service/BookingServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ public function getUserBookingFromApiData(array $data): UserBooking;
*/
public function createBodyUserId(string $id): string;

/**
* Get all future bookings.
*
* @return mixed
*/
/**
* Get all future bookings.
*
* @return mixed
*/
public function getAllFutureBookings(string $token): GraphResponse;
}
27 changes: 14 additions & 13 deletions src/Service/MicrosoftGraphBookingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,23 +509,24 @@ public function getUserBookingFromApiData(array $data): UserBooking
}
}

/**
* {@inheritdoc}
*/
public function getAllFutureBookings($token): GraphResponse {
$now = new \DateTime();
$nowFormatted = $now->setTimezone(new \DateTimeZone('UTC'))->format(MicrosoftGraphBookingService::DATE_FORMAT).'Z';

$query = implode('&', [
"\$filter=end/dateTime gt '$nowFormatted'",
'$top=100',
/**
* {@inheritdoc}
*/
public function getAllFutureBookings($token): GraphResponse
{
$now = new \DateTime();
$nowFormatted = $now->setTimezone(new \DateTimeZone('UTC'))->format(MicrosoftGraphBookingService::DATE_FORMAT).'Z';

$query = implode('&', [
"\$filter=end/dateTime gt '$nowFormatted'",
'$top=100',
]
);
);

return $this->graphHelperService->request("/me/events?$query", $token);
return $this->graphHelperService->request("/me/events?$query", $token);
}

/**
/**
* {@inheritdoc}
*/
public function createBodyUserId(string $id): string
Expand Down
38 changes: 19 additions & 19 deletions src/Service/UserBookingCacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public function addCacheEntry(UserBooking $userBooking): void
public function changeCacheEntry(string $exchangeId, array $changes): void
{
$entity = $this->entityManager->getRepository(UserBookingCacheEntry::class)
->findOneBy(['exchangeId' => $exchangeId]);
->findOneBy(['exchangeId' => $exchangeId]);

if (!$entity) {
throw new \Exception('No cache entry found for exchangeId: '. $exchangeId);
throw new \Exception('No cache entry found for exchangeId: '.$exchangeId);
}

foreach ($changes as $field => $value) {
Expand All @@ -107,12 +107,11 @@ public function changeCacheEntry(string $exchangeId, array $changes): void
*/
public function deleteCacheEntry(string $exchangeId): void
{
$entity = $this->entityManager->getRepository(UserBookingCacheEntry::class)
->findOneBy(['exchangeId' => $exchangeId]);
if ($entity) {
$this->entityManager->remove($entity);
}

$entity = $this->entityManager->getRepository(UserBookingCacheEntry::class)
->findOneBy(['exchangeId' => $exchangeId]);
if ($entity) {
$this->entityManager->remove($entity);
}
}

/**
Expand Down Expand Up @@ -169,16 +168,17 @@ private function clearUserBookingCache(): void
}
}

/**
* Remove UID from front and back of id.
*
* @param $documentBodyUid
*
* @return string
*/
private function extractRealUid($documentBodyUid): string {
$documentBodyUid = ltrim($documentBodyUid, 'UID-');

return rtrim($documentBodyUid, '-UID');
/**
* Remove UID from front and back of id.
*
* @param $documentBodyUid
*
* @return string
*/
private function extractRealUid($documentBodyUid): string
{
$documentBodyUid = ltrim($documentBodyUid, 'UID-');

return rtrim($documentBodyUid, '-UID');
}
}
1 change: 0 additions & 1 deletion src/Service/UserBookingCacheServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Service;

use App\Entity\Main\UserBooking;
use App\Entity\Main\UserBookingCacheEntry;

/**
* @see https://github.com/microsoftgraph/msgraph-sdk-php
Expand Down

0 comments on commit dbc5e3f

Please sign in to comment.