mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 01:53:49 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -28,8 +28,6 @@ use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\RemoteEventConverter;
|
||||
use Chill\CalendarBundle\Repository\CalendarRangeRepository;
|
||||
use Chill\CalendarBundle\Repository\CalendarRepository;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use DateTimeImmutable;
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -38,8 +36,6 @@ use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
|
||||
class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
{
|
||||
@@ -47,7 +43,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
|
||||
public function __construct(private readonly CalendarRepository $calendarRepository, private readonly CalendarRangeRepository $calendarRangeRepository, private readonly HttpClientInterface $machineHttpClient, private readonly MapCalendarToUser $mapCalendarToUser, private readonly LoggerInterface $logger, private readonly OnBehalfOfUserTokenStorage $tokenStorage, private readonly OnBehalfOfUserHttpClient $userHttpClient, private readonly RemoteEventConverter $remoteEventConverter, private readonly TranslatorInterface $translator, private readonly UrlGeneratorInterface $urlGenerator, private readonly Security $security) {}
|
||||
|
||||
public function countEventsForUser(User $user, DateTimeImmutable $startDate, DateTimeImmutable $endDate): int
|
||||
public function countEventsForUser(User $user, \DateTimeImmutable $startDate, \DateTimeImmutable $endDate): int
|
||||
{
|
||||
$userId = $this->mapCalendarToUser->getUserId($user);
|
||||
|
||||
@@ -58,7 +54,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
try {
|
||||
$data = $this->userHttpClient->request(
|
||||
'GET',
|
||||
'users/' . $userId . '/calendarView',
|
||||
'users/'.$userId.'/calendarView',
|
||||
[
|
||||
'query' => [
|
||||
'startDateTime' => $startDate->setTimezone(RemoteEventConverter::getRemoteTimeZone())->format(RemoteEventConverter::getRemoteDateTimeSimpleFormat()),
|
||||
@@ -70,7 +66,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
)->toArray();
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
if (403 === $e->getResponse()->getStatusCode()) {
|
||||
return count($this->getScheduleTimesForUser($user, $startDate, $endDate));
|
||||
return \count($this->getScheduleTimesForUser($user, $startDate, $endDate));
|
||||
}
|
||||
|
||||
$this->logger->error('Could not get list of event on MSGraph', [
|
||||
@@ -107,6 +103,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
$this->logger->debug('mark user ready for msgraph calendar as he does not have any mapping', [
|
||||
'userId' => $user->getId(),
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -114,14 +111,14 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|\Chill\CalendarBundle\RemoteCalendar\Model\RemoteEvent[]
|
||||
*
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
||||
*
|
||||
* @return array|\Chill\CalendarBundle\RemoteCalendar\Model\RemoteEvent[]
|
||||
*/
|
||||
public function listEventsForUser(User $user, DateTimeImmutable $startDate, DateTimeImmutable $endDate, ?int $offset = 0, ?int $limit = 50): array
|
||||
public function listEventsForUser(User $user, \DateTimeImmutable $startDate, \DateTimeImmutable $endDate, ?int $offset = 0, ?int $limit = 50): array
|
||||
{
|
||||
$userId = $this->mapCalendarToUser->getUserId($user);
|
||||
|
||||
@@ -132,7 +129,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
try {
|
||||
$bareEvents = $this->userHttpClient->request(
|
||||
'GET',
|
||||
'users/' . $userId . '/calendarView',
|
||||
'users/'.$userId.'/calendarView',
|
||||
[
|
||||
'query' => [
|
||||
'startDateTime' => $startDate->setTimezone(RemoteEventConverter::getRemoteTimeZone())->format(RemoteEventConverter::getRemoteDateTimeSimpleFormat()),
|
||||
@@ -172,7 +169,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function removeCalendar(string $remoteId, array $remoteAttributes, User $user, ?CalendarRange $associatedCalendarRange = null): void
|
||||
public function removeCalendar(string $remoteId, array $remoteAttributes, User $user, CalendarRange $associatedCalendarRange = null): void
|
||||
{
|
||||
if ('' === $remoteId) {
|
||||
return;
|
||||
@@ -222,7 +219,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
$calendar->getRemoteId(),
|
||||
$this->translator->trans('remote_ms_graph.cancel_event_because_main_user_is_%label%', ['%label%' => $calendar->getMainUser()]),
|
||||
$previousMainUser,
|
||||
'calendar_' . $calendar->getRemoteId()
|
||||
'calendar_'.$calendar->getRemoteId()
|
||||
);
|
||||
$this->createCalendarOnRemote($calendar);
|
||||
} else {
|
||||
@@ -300,7 +297,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception('not supported');
|
||||
throw new \Exception('not supported');
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -313,7 +310,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
$this->logger->warning('could not update calendar range to remote', [
|
||||
'exception' => $e->getTraceAsString(),
|
||||
'content' => $e->getResponse()->getContent(),
|
||||
'calendarRangeId' => 'invite_' . $invite->getId(),
|
||||
'calendarRangeId' => 'invite_'.$invite->getId(),
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
@@ -355,7 +352,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
'id' => $id,
|
||||
'lastModifiedDateTime' => $lastModified,
|
||||
'changeKey' => $changeKey
|
||||
] = $this->createOnRemote($eventData, $calendar->getMainUser(), 'calendar_' . $calendar->getId());
|
||||
] = $this->createOnRemote($eventData, $calendar->getMainUser(), 'calendar_'.$calendar->getId());
|
||||
|
||||
if (null === $id) {
|
||||
return;
|
||||
@@ -390,7 +387,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
try {
|
||||
$event = $this->machineHttpClient->request(
|
||||
'POST',
|
||||
'users/' . $userId . '/calendar/events',
|
||||
'users/'.$userId.'/calendar/events',
|
||||
[
|
||||
'json' => $eventData,
|
||||
]
|
||||
@@ -434,7 +431,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
] = $this->createOnRemote(
|
||||
$eventData,
|
||||
$calendarRange->getUser(),
|
||||
'calendar_range_' . $calendarRange->getId()
|
||||
'calendar_range_'.$calendarRange->getId()
|
||||
);
|
||||
|
||||
$calendarRange->setRemoteId($id)
|
||||
@@ -457,7 +454,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
$userId = $this->mapCalendarToUser->getUserId($user);
|
||||
|
||||
if ('' === $iCalUid = ($event['iCalUId'] ?? '')) {
|
||||
throw new Exception('no iCalUid for this event');
|
||||
throw new \Exception('no iCalUid for this event');
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -475,8 +472,8 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
throw $clientException;
|
||||
}
|
||||
|
||||
if (1 !== count($events['value'])) {
|
||||
throw new Exception('multiple events found with same iCalUid');
|
||||
if (1 !== \count($events['value'])) {
|
||||
throw new \Exception('multiple events found with same iCalUid');
|
||||
}
|
||||
|
||||
return $events['value'][0]['id'];
|
||||
@@ -487,19 +484,13 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
$userId = $this->mapCalendarToUser->getUserId($user);
|
||||
|
||||
if (null === $userId) {
|
||||
throw new Exception(
|
||||
sprintf(
|
||||
'no remote calendar for this user: %s, remoteid: %s',
|
||||
$user->getId(),
|
||||
$remoteId
|
||||
)
|
||||
);
|
||||
throw new \Exception(sprintf('no remote calendar for this user: %s, remoteid: %s', $user->getId(), $remoteId));
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->machineHttpClient->request(
|
||||
'GET',
|
||||
'users/' . $userId . '/calendar/events/' . $remoteId
|
||||
'users/'.$userId.'/calendar/events/'.$remoteId
|
||||
)->toArray();
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
$this->logger->warning('Could not get event from calendar', [
|
||||
@@ -510,11 +501,11 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function getScheduleTimesForUser(User $user, DateTimeImmutable $startDate, DateTimeImmutable $endDate): array
|
||||
private function getScheduleTimesForUser(User $user, \DateTimeImmutable $startDate, \DateTimeImmutable $endDate): array
|
||||
{
|
||||
$userId = $this->mapCalendarToUser->getUserId($user);
|
||||
|
||||
if (array_key_exists($userId, $this->cacheScheduleTimeForUser)) {
|
||||
if (\array_key_exists($userId, $this->cacheScheduleTimeForUser)) {
|
||||
return $this->cacheScheduleTimeForUser[$userId];
|
||||
}
|
||||
|
||||
@@ -529,17 +520,17 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
$body = [
|
||||
'schedules' => [$user->getEmailCanonical()],
|
||||
'startTime' => [
|
||||
'dateTime' => ($startDate->setTimezone(RemoteEventConverter::getRemoteTimeZone())->format(RemoteEventConverter::getRemoteDateTimeSimpleFormat())),
|
||||
'dateTime' => $startDate->setTimezone(RemoteEventConverter::getRemoteTimeZone())->format(RemoteEventConverter::getRemoteDateTimeSimpleFormat()),
|
||||
'timeZone' => 'UTC',
|
||||
],
|
||||
'endTime' => [
|
||||
'dateTime' => ($endDate->setTimezone(RemoteEventConverter::getRemoteTimeZone())->format(RemoteEventConverter::getRemoteDateTimeSimpleFormat())),
|
||||
'dateTime' => $endDate->setTimezone(RemoteEventConverter::getRemoteTimeZone())->format(RemoteEventConverter::getRemoteDateTimeSimpleFormat()),
|
||||
'timeZone' => 'UTC',
|
||||
],
|
||||
];
|
||||
|
||||
try {
|
||||
$response = $this->userHttpClient->request('POST', 'users/' . $userId . '/calendar/getSchedule', [
|
||||
$response = $this->userHttpClient->request('POST', 'users/'.$userId.'/calendar/getSchedule', [
|
||||
'json' => $body,
|
||||
])->toArray();
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
@@ -564,7 +555,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
$eventDatas = [];
|
||||
$eventDatas[] = $this->remoteEventConverter->calendarToEvent($calendar);
|
||||
|
||||
if (0 < count($newInvites)) {
|
||||
if (0 < \count($newInvites)) {
|
||||
// it seems that invitaiton are always send, even if attendee changes are mixed with other datas
|
||||
// $eventDatas[] = $this->remoteEventConverter->calendarToEventAttendeesOnly($calendar);
|
||||
}
|
||||
@@ -578,7 +569,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
$calendar->getRemoteId(),
|
||||
$eventData,
|
||||
$calendar->getMainUser(),
|
||||
'calendar_' . $calendar->getId()
|
||||
'calendar_'.$calendar->getId()
|
||||
);
|
||||
|
||||
$calendar->addRemoteAttributes([
|
||||
@@ -609,7 +600,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
try {
|
||||
$event = $this->machineHttpClient->request(
|
||||
'PATCH',
|
||||
'users/' . $userId . '/calendar/events/' . $remoteId,
|
||||
'users/'.$userId.'/calendar/events/'.$remoteId,
|
||||
[
|
||||
'json' => $eventData,
|
||||
]
|
||||
@@ -637,7 +628,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
try {
|
||||
$this->machineHttpClient->request(
|
||||
'DELETE',
|
||||
'users/' . $userId . '/calendar/events/' . $remoteId
|
||||
'users/'.$userId.'/calendar/events/'.$remoteId
|
||||
);
|
||||
} catch (ClientExceptionInterface) {
|
||||
$this->logger->warning('could not remove event from calendar', [
|
||||
@@ -664,7 +655,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
try {
|
||||
$event = $this->machineHttpClient->request(
|
||||
'GET',
|
||||
'users/' . $userId . '/calendar/events/' . $calendarRange->getRemoteId()
|
||||
'users/'.$userId.'/calendar/events/'.$calendarRange->getRemoteId()
|
||||
)->toArray();
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
$this->logger->warning('Could not get event from calendar', [
|
||||
@@ -691,7 +682,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
try {
|
||||
$event = $this->machineHttpClient->request(
|
||||
'PATCH',
|
||||
'users/' . $userId . '/calendar/events/' . $calendarRange->getRemoteId(),
|
||||
'users/'.$userId.'/calendar/events/'.$calendarRange->getRemoteId(),
|
||||
[
|
||||
'json' => $eventData,
|
||||
]
|
||||
|
Reference in New Issue
Block a user