DX: apply rector rules up to php8.0

This commit is contained in:
2023-04-15 01:05:37 +02:00
parent d8870e906f
commit dde3002100
714 changed files with 2348 additions and 9263 deletions

View File

@@ -24,14 +24,8 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
class AddressConverter
{
private AddressRender $addressRender;
private TranslatableStringHelperInterface $translatableStringHelper;
public function __construct(AddressRender $addressRender, TranslatableStringHelperInterface $translatableStringHelper)
public function __construct(private AddressRender $addressRender, private TranslatableStringHelperInterface $translatableStringHelper)
{
$this->addressRender = $addressRender;
$this->translatableStringHelper = $translatableStringHelper;
}
public function addressToRemote(Address $address): array

View File

@@ -30,24 +30,8 @@ use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
*/
class EventsOnUserSubscriptionCreator
{
private LoggerInterface $logger;
private MachineHttpClient $machineHttpClient;
private MapCalendarToUser $mapCalendarToUser;
private UrlGeneratorInterface $urlGenerator;
public function __construct(
LoggerInterface $logger,
MachineHttpClient $machineHttpClient,
MapCalendarToUser $mapCalendarToUser,
UrlGeneratorInterface $urlGenerator
) {
$this->logger = $logger;
$this->machineHttpClient = $machineHttpClient;
$this->mapCalendarToUser = $mapCalendarToUser;
$this->urlGenerator = $urlGenerator;
public function __construct(private LoggerInterface $logger, private MachineHttpClient $machineHttpClient, private MapCalendarToUser $mapCalendarToUser, private UrlGeneratorInterface $urlGenerator)
{
}
/**

View File

@@ -22,11 +22,8 @@ use Chill\MainBundle\Entity\Location;
class LocationConverter
{
private AddressConverter $addressConverter;
public function __construct(AddressConverter $addressConverter)
public function __construct(private AddressConverter $addressConverter)
{
$this->addressConverter = $addressConverter;
}
public function locationToRemote(Location $location): array

View File

@@ -42,11 +42,8 @@ class MSGraphUserRepository
;
SQL;
private EntityManagerInterface $entityManager;
public function __construct(EntityManagerInterface $entityManager)
public function __construct(private EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
public function countByMostOldSubscriptionOrWithoutSubscriptionOrData(DateInterval $interval): int

View File

@@ -30,15 +30,12 @@ class MachineHttpClient implements HttpClientInterface
private HttpClientInterface $decoratedClient;
private MachineTokenStorage $machineTokenStorage;
/**
* @param HttpClientInterface $decoratedClient
*/
public function __construct(MachineTokenStorage $machineTokenStorage, ?HttpClientInterface $decoratedClient = null)
public function __construct(private MachineTokenStorage $machineTokenStorage, ?HttpClientInterface $decoratedClient = null)
{
$this->decoratedClient = $decoratedClient ?? \Symfony\Component\HttpClient\HttpClient::create();
$this->machineTokenStorage = $machineTokenStorage;
}
/**

View File

@@ -29,14 +29,8 @@ class MachineTokenStorage
private ?AccessTokenInterface $accessToken = null;
private Azure $azure;
private ChillRedis $chillRedis;
public function __construct(Azure $azure, ChillRedis $chillRedis)
public function __construct(private Azure $azure, private ChillRedis $chillRedis)
{
$this->azure = $azure;
$this->chillRedis = $chillRedis;
}
public function getToken(): AccessTokenInterface

View File

@@ -39,16 +39,8 @@ class MapCalendarToUser
public const SECRET_SUBSCRIPTION_EVENT = 'subscription_events_secret';
private LoggerInterface $logger;
private HttpClientInterface $machineHttpClient;
public function __construct(
HttpClientInterface $machineHttpClient,
LoggerInterface $logger
) {
$this->machineHttpClient = $machineHttpClient;
$this->logger = $logger;
public function __construct(private HttpClientInterface $machineHttpClient, private LoggerInterface $logger)
{
}
public function getActiveSubscriptionId(User $user): string

View File

@@ -30,15 +30,12 @@ class OnBehalfOfUserHttpClient
private HttpClientInterface $decoratedClient;
private OnBehalfOfUserTokenStorage $tokenStorage;
/**
* @param HttpClientInterface $decoratedClient
*/
public function __construct(OnBehalfOfUserTokenStorage $tokenStorage, ?HttpClientInterface $decoratedClient = null)
public function __construct(private OnBehalfOfUserTokenStorage $tokenStorage, ?HttpClientInterface $decoratedClient = null)
{
$this->decoratedClient = $decoratedClient ?? \Symfony\Component\HttpClient\HttpClient::create();
$this->tokenStorage = $tokenStorage;
}
public function request(string $method, string $url, array $options = []): ResponseInterface

View File

@@ -30,14 +30,8 @@ class OnBehalfOfUserTokenStorage
{
public const MS_GRAPH_ACCESS_TOKEN = 'msgraph_access_token';
private Azure $azure;
private SessionInterface $session;
public function __construct(Azure $azure, SessionInterface $session)
public function __construct(private Azure $azure, private SessionInterface $session)
{
$this->azure = $azure;
$this->session = $session;
}
public function getToken(): AccessToken

View File

@@ -54,30 +54,15 @@ class RemoteEventConverter
private DateTimeZone $defaultDateTimeZone;
private EngineInterface $engine;
private LocationConverter $locationConverter;
private LoggerInterface $logger;
private PersonRenderInterface $personRender;
private DateTimeZone $remoteDateTimeZone;
private TranslatorInterface $translator;
public function __construct(
EngineInterface $engine,
LocationConverter $locationConverter,
LoggerInterface $logger,
PersonRenderInterface $personRender,
TranslatorInterface $translator
private EngineInterface $engine,
private LocationConverter $locationConverter,
private LoggerInterface $logger,
private PersonRenderInterface $personRender,
private TranslatorInterface $translator
) {
$this->engine = $engine;
$this->locationConverter = $locationConverter;
$this->logger = $logger;
$this->translator = $translator;
$this->personRender = $personRender;
$this->defaultDateTimeZone = (new DateTimeImmutable())->getTimezone();
$this->remoteDateTimeZone = self::getRemoteTimeZone();
}

View File

@@ -30,23 +30,11 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
class CalendarRangeSyncer
{
private EntityManagerInterface $em;
private LoggerInterface $logger;
private HttpClientInterface $machineHttpClient;
/**
* @param MachineHttpClient $machineHttpClient
*/
public function __construct(
EntityManagerInterface $em,
LoggerInterface $logger,
HttpClientInterface $machineHttpClient
) {
$this->em = $em;
$this->logger = $logger;
$this->machineHttpClient = $machineHttpClient;
public function __construct(private EntityManagerInterface $em, private LoggerInterface $logger, private HttpClientInterface $machineHttpClient)
{
}
public function handleCalendarRangeSync(CalendarRange $calendarRange, array $notification, User $user): void

View File

@@ -32,35 +32,17 @@ use function in_array;
class CalendarSyncer
{
private LoggerInterface $logger;
private HttpClientInterface $machineHttpClient;
private UserRepositoryInterface $userRepository;
public function __construct(LoggerInterface $logger, HttpClientInterface $machineHttpClient, UserRepositoryInterface $userRepository)
public function __construct(private LoggerInterface $logger, private HttpClientInterface $machineHttpClient, private UserRepositoryInterface $userRepository)
{
$this->logger = $logger;
$this->machineHttpClient = $machineHttpClient;
$this->userRepository = $userRepository;
}
public function handleCalendarSync(Calendar $calendar, array $notification, User $user): void
{
switch ($notification['changeType']) {
case 'deleted':
$this->handleDeleteCalendar($calendar, $notification, $user);
break;
case 'updated':
$this->handleUpdateCalendar($calendar, $notification, $user);
break;
default:
throw new RuntimeException('this change type is not supported: ' . $notification['changeType']);
}
match ($notification['changeType']) {
'deleted' => $this->handleDeleteCalendar($calendar, $notification, $user),
'updated' => $this->handleUpdateCalendar($calendar, $notification, $user),
default => throw new RuntimeException('this change type is not supported: ' . $notification['changeType']),
};
}
private function handleDeleteCalendar(Calendar $calendar, array $notification, User $user): void
@@ -150,34 +132,13 @@ class CalendarSyncer
$invite = $calendar->getInviteForUser($user);
switch ($status) {
// possible cases: none, organizer, tentativelyAccepted, accepted, declined, notResponded.
case 'none':
case 'notResponded':
$invite->setStatus(Invite::PENDING);
break;
case 'tentativelyAccepted':
$invite->setStatus(Invite::TENTATIVELY_ACCEPTED);
break;
case 'accepted':
$invite->setStatus(Invite::ACCEPTED);
break;
case 'declined':
$invite->setStatus(Invite::DECLINED);
break;
default:
throw new LogicException('should not happens, not implemented: ' . $status);
break;
}
match ($status) {
'none', 'notResponded' => $invite->setStatus(Invite::PENDING),
'tentativelyAccepted' => $invite->setStatus(Invite::TENTATIVELY_ACCEPTED),
'accepted' => $invite->setStatus(Invite::ACCEPTED),
'declined' => $invite->setStatus(Invite::DECLINED),
default => throw new LogicException('should not happens, not implemented: ' . $status),
};
}
foreach ($calendar->getUsers() as $user) {

View File

@@ -45,52 +45,8 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
{
private array $cacheScheduleTimeForUser = [];
private CalendarRangeRepository $calendarRangeRepository;
private CalendarRepository $calendarRepository;
private LoggerInterface $logger;
private HttpClientInterface $machineHttpClient;
private MapCalendarToUser $mapCalendarToUser;
private RemoteEventConverter $remoteEventConverter;
private OnBehalfOfUserTokenStorage $tokenStorage;
private TranslatorInterface $translator;
private UrlGeneratorInterface $urlGenerator;
private OnBehalfOfUserHttpClient $userHttpClient;
private Security $security;
public function __construct(
CalendarRepository $calendarRepository,
CalendarRangeRepository $calendarRangeRepository,
HttpClientInterface $machineHttpClient,
MapCalendarToUser $mapCalendarToUser,
LoggerInterface $logger,
OnBehalfOfUserTokenStorage $tokenStorage,
OnBehalfOfUserHttpClient $userHttpClient,
RemoteEventConverter $remoteEventConverter,
TranslatorInterface $translator,
UrlGeneratorInterface $urlGenerator,
Security $security
) {
$this->calendarRepository = $calendarRepository;
$this->calendarRangeRepository = $calendarRangeRepository;
$this->machineHttpClient = $machineHttpClient;
$this->mapCalendarToUser = $mapCalendarToUser;
$this->logger = $logger;
$this->remoteEventConverter = $remoteEventConverter;
$this->tokenStorage = $tokenStorage;
$this->translator = $translator;
$this->urlGenerator = $urlGenerator;
$this->userHttpClient = $userHttpClient;
$this->security = $security;
public function __construct(private CalendarRepository $calendarRepository, private CalendarRangeRepository $calendarRangeRepository, private HttpClientInterface $machineHttpClient, private MapCalendarToUser $mapCalendarToUser, private LoggerInterface $logger, private OnBehalfOfUserTokenStorage $tokenStorage, private OnBehalfOfUserHttpClient $userHttpClient, private RemoteEventConverter $remoteEventConverter, private TranslatorInterface $translator, private UrlGeneratorInterface $urlGenerator, private Security $security)
{
}
public function countEventsForUser(User $user, DateTimeImmutable $startDate, DateTimeImmutable $endDate): int
@@ -685,7 +641,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
'DELETE',
'users/' . $userId . '/calendar/events/' . $remoteId
);
} catch (ClientExceptionInterface $e) {
} catch (ClientExceptionInterface) {
$this->logger->warning('could not remove event from calendar', [
'event_remote_id' => $remoteId,
'user_id' => $user->getId(),