mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 02:53:50 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -24,11 +24,7 @@ use Chill\CalendarBundle\Entity\Invite;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Model\RemoteEvent;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Templating\Entity\PersonRenderInterface;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
@@ -52,9 +48,9 @@ class RemoteEventConverter
|
||||
|
||||
private const REMOTE_DATETIME_WITHOUT_TZ_FORMAT = 'Y-m-d\TH:i:s.u?';
|
||||
|
||||
private readonly DateTimeZone $defaultDateTimeZone;
|
||||
private readonly \DateTimeZone $defaultDateTimeZone;
|
||||
|
||||
private readonly DateTimeZone $remoteDateTimeZone;
|
||||
private readonly \DateTimeZone $remoteDateTimeZone;
|
||||
|
||||
public function __construct(
|
||||
private readonly \Twig\Environment $engine,
|
||||
@@ -63,7 +59,7 @@ class RemoteEventConverter
|
||||
private readonly PersonRenderInterface $personRender,
|
||||
private readonly TranslatorInterface $translator
|
||||
) {
|
||||
$this->defaultDateTimeZone = (new DateTimeImmutable())->getTimezone();
|
||||
$this->defaultDateTimeZone = (new \DateTimeImmutable())->getTimezone();
|
||||
$this->remoteDateTimeZone = self::getRemoteTimeZone();
|
||||
}
|
||||
|
||||
@@ -103,7 +99,7 @@ class RemoteEventConverter
|
||||
{
|
||||
$result = array_merge(
|
||||
[
|
||||
'subject' => '[Chill] ' .
|
||||
'subject' => '[Chill] '.
|
||||
implode(
|
||||
', ',
|
||||
$calendar->getPersons()->map(fn (Person $p) => $this->personRender->renderString($p, []))->toArray()
|
||||
@@ -119,7 +115,7 @@ class RemoteEventConverter
|
||||
'timeZone' => 'UTC',
|
||||
],
|
||||
'allowNewTimeProposals' => false,
|
||||
'transactionId' => 'calendar_' . $calendar->getId(),
|
||||
'transactionId' => 'calendar_'.$calendar->getId(),
|
||||
'body' => [
|
||||
'contentType' => 'text',
|
||||
'content' => $this->engine->render(
|
||||
@@ -152,45 +148,45 @@ class RemoteEventConverter
|
||||
public function convertAvailabilityToRemoteEvent(array $event): RemoteEvent
|
||||
{
|
||||
$startDate =
|
||||
DateTimeImmutable::createFromFormat(self::REMOTE_DATE_FORMAT, $event['start']['dateTime'], $this->remoteDateTimeZone)
|
||||
\DateTimeImmutable::createFromFormat(self::REMOTE_DATE_FORMAT, $event['start']['dateTime'], $this->remoteDateTimeZone)
|
||||
->setTimezone($this->defaultDateTimeZone);
|
||||
$endDate =
|
||||
DateTimeImmutable::createFromFormat(self::REMOTE_DATE_FORMAT, $event['end']['dateTime'], $this->remoteDateTimeZone)
|
||||
\DateTimeImmutable::createFromFormat(self::REMOTE_DATE_FORMAT, $event['end']['dateTime'], $this->remoteDateTimeZone)
|
||||
->setTimezone($this->defaultDateTimeZone);
|
||||
|
||||
return new RemoteEvent(
|
||||
uniqid('generated_'),
|
||||
$this->translator->trans('remote_ms_graph.freebusy_statuses.' . $event['status']),
|
||||
$this->translator->trans('remote_ms_graph.freebusy_statuses.'.$event['status']),
|
||||
'',
|
||||
$startDate,
|
||||
$endDate
|
||||
);
|
||||
}
|
||||
|
||||
public static function convertStringDateWithoutTimezone(string $date): DateTimeImmutable
|
||||
public static function convertStringDateWithoutTimezone(string $date): \DateTimeImmutable
|
||||
{
|
||||
$d = DateTimeImmutable::createFromFormat(
|
||||
$d = \DateTimeImmutable::createFromFormat(
|
||||
self::REMOTE_DATETIME_WITHOUT_TZ_FORMAT,
|
||||
$date,
|
||||
self::getRemoteTimeZone()
|
||||
);
|
||||
|
||||
if (false === $d) {
|
||||
throw new RuntimeException("could not convert string date to datetime: {$date}");
|
||||
throw new \RuntimeException("could not convert string date to datetime: {$date}");
|
||||
}
|
||||
|
||||
return $d->setTimezone((new DateTimeImmutable())->getTimezone());
|
||||
return $d->setTimezone((new \DateTimeImmutable())->getTimezone());
|
||||
}
|
||||
|
||||
public static function convertStringDateWithTimezone(string $date): DateTimeImmutable
|
||||
public static function convertStringDateWithTimezone(string $date): \DateTimeImmutable
|
||||
{
|
||||
$d = DateTimeImmutable::createFromFormat(self::REMOTE_DATETIMEZONE_FORMAT, $date);
|
||||
$d = \DateTimeImmutable::createFromFormat(self::REMOTE_DATETIMEZONE_FORMAT, $date);
|
||||
|
||||
if (false === $d) {
|
||||
throw new RuntimeException("could not convert string date to datetime: {$date}");
|
||||
throw new \RuntimeException("could not convert string date to datetime: {$date}");
|
||||
}
|
||||
|
||||
$d->setTimezone((new DateTimeImmutable())->getTimezone());
|
||||
$d->setTimezone((new \DateTimeImmutable())->getTimezone());
|
||||
|
||||
return $d;
|
||||
}
|
||||
@@ -198,10 +194,10 @@ class RemoteEventConverter
|
||||
public function convertToRemote(array $event): RemoteEvent
|
||||
{
|
||||
$startDate =
|
||||
DateTimeImmutable::createFromFormat(self::REMOTE_DATE_FORMAT, $event['start']['dateTime'], $this->remoteDateTimeZone)
|
||||
\DateTimeImmutable::createFromFormat(self::REMOTE_DATE_FORMAT, $event['start']['dateTime'], $this->remoteDateTimeZone)
|
||||
->setTimezone($this->defaultDateTimeZone);
|
||||
$endDate =
|
||||
DateTimeImmutable::createFromFormat(self::REMOTE_DATE_FORMAT, $event['end']['dateTime'], $this->remoteDateTimeZone)
|
||||
\DateTimeImmutable::createFromFormat(self::REMOTE_DATE_FORMAT, $event['end']['dateTime'], $this->remoteDateTimeZone)
|
||||
->setTimezone($this->defaultDateTimeZone);
|
||||
|
||||
return new RemoteEvent(
|
||||
@@ -214,26 +210,22 @@ class RemoteEventConverter
|
||||
);
|
||||
}
|
||||
|
||||
public function getLastModifiedDate(array $event): DateTimeImmutable
|
||||
public function getLastModifiedDate(array $event): \DateTimeImmutable
|
||||
{
|
||||
$date = DateTimeImmutable::createFromFormat(self::REMOTE_DATETIMEZONE_FORMAT, $event['lastModifiedDateTime']);
|
||||
$date = \DateTimeImmutable::createFromFormat(self::REMOTE_DATETIMEZONE_FORMAT, $event['lastModifiedDateTime']);
|
||||
|
||||
if (false === $date) {
|
||||
$date = DateTimeImmutable::createFromFormat(self::REMOTE_DATETIMEZONE_FORMAT_ALT, $event['lastModifiedDateTime']);
|
||||
$date = \DateTimeImmutable::createFromFormat(self::REMOTE_DATETIMEZONE_FORMAT_ALT, $event['lastModifiedDateTime']);
|
||||
}
|
||||
|
||||
if (false === $date) {
|
||||
$this->logger->error(self::class . ' Could not convert lastModifiedDate', [
|
||||
$this->logger->error(self::class.' Could not convert lastModifiedDate', [
|
||||
'actual' => $event['lastModifiedDateTime'],
|
||||
'format' => self::REMOTE_DATETIMEZONE_FORMAT,
|
||||
'format_alt' => self::REMOTE_DATETIMEZONE_FORMAT_ALT,
|
||||
]);
|
||||
|
||||
throw new RuntimeException(sprintf(
|
||||
'could not convert lastModifiedDate: %s, expected format: %s',
|
||||
$event['lastModifiedDateTime'],
|
||||
self::REMOTE_DATETIMEZONE_FORMAT . ' and ' . self::REMOTE_DATETIMEZONE_FORMAT_ALT
|
||||
));
|
||||
throw new \RuntimeException(sprintf('could not convert lastModifiedDate: %s, expected format: %s', $event['lastModifiedDateTime'], self::REMOTE_DATETIMEZONE_FORMAT.' and '.self::REMOTE_DATETIMEZONE_FORMAT_ALT));
|
||||
}
|
||||
|
||||
return $date;
|
||||
@@ -247,9 +239,9 @@ class RemoteEventConverter
|
||||
return 'Y-m-d\TH:i:s';
|
||||
}
|
||||
|
||||
public static function getRemoteTimeZone(): DateTimeZone
|
||||
public static function getRemoteTimeZone(): \DateTimeZone
|
||||
{
|
||||
return new DateTimeZone('UTC');
|
||||
return new \DateTimeZone('UTC');
|
||||
}
|
||||
|
||||
private function buildInviteToAttendee(Invite $invite): array
|
||||
|
Reference in New Issue
Block a user