DX: rector rules upt to PHP 74

This commit is contained in:
2023-04-15 00:20:19 +02:00
parent a68190f0c6
commit 858ade467c
213 changed files with 433 additions and 1052 deletions

View File

@@ -514,9 +514,7 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente
*/
public function getUsers(): ReadableCollection
{
return $this->getInvites()->map(static function (Invite $i) {
return $i->getUser();
});
return $this->getInvites()->map(static fn(Invite $i) => $i->getUser());
}
public function hasCalendarRange(): bool
@@ -601,9 +599,7 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente
}
$invite = $this->invites
->filter(static function (Invite $invite) use ($user) {
return $invite->getUser() === $user;
})
->filter(static fn(Invite $invite) => $invite->getUser() === $user)
->first();
$this->removeInvite($invite);

View File

@@ -63,7 +63,7 @@ class CalendarRange implements TrackCreationInterface, TrackUpdateInterface
* @Groups({"read", "write", "calendar:read"})
* @Assert\NotNull
*/
private ?Location $location;
private ?Location $location = null;
/**
* @ORM\Column(type="datetime_immutable", nullable=false)

View File

@@ -61,9 +61,7 @@ class CountCalendars implements ExportInterface, GroupedExportInterface
$labels = array_combine($values, $values);
$labels['_header'] = $this->getTitle();
return static function ($value) use ($labels) {
return $labels[$value];
};
return static fn($value) => $labels[$value];
}
public function getQueryKeys($data): array
@@ -91,9 +89,7 @@ class CountCalendars implements ExportInterface, GroupedExportInterface
*/
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$centers = array_map(static fn($el) => $el['center'], $acl);
$qb = $this->calendarRepository->createQueryBuilder('cal');

View File

@@ -61,9 +61,7 @@ class StatCalendarAvgDuration implements ExportInterface, GroupedExportInterface
$labels = array_combine($values, $values);
$labels['_header'] = $this->getTitle();
return static function ($value) use ($labels) {
return $labels[$value];
};
return static fn($value) => $labels[$value];
}
public function getQueryKeys($data): array

View File

@@ -61,9 +61,7 @@ class StatCalendarSumDuration implements ExportInterface, GroupedExportInterface
$labels = array_combine($values, $values);
$labels['_header'] = $this->getTitle();
return static function ($value) use ($labels) {
return $labels[$value];
};
return static fn($value) => $labels[$value];
}
public function getQueryKeys($data): array

View File

@@ -58,9 +58,7 @@ class AgentFilter implements FilterInterface
{
$builder->add('accepted_agents', EntityType::class, [
'class' => User::class,
'choice_label' => function (User $u) {
return $this->userRender->renderString($u, []);
},
'choice_label' => fn(User $u) => $this->userRender->renderString($u, []),
'multiple' => true,
'expanded' => true,
]);

View File

@@ -69,11 +69,9 @@ class JobFilter implements FilterInterface
{
$builder->add('job', EntityType::class, [
'class' => UserJob::class,
'choice_label' => function (UserJob $j) {
return $this->translatableStringHelper->localize(
$j->getLabel()
);
},
'choice_label' => fn(UserJob $j) => $this->translatableStringHelper->localize(
$j->getLabel()
),
'multiple' => true,
'expanded' => true,
]);

View File

@@ -69,11 +69,9 @@ class ScopeFilter implements FilterInterface
{
$builder->add('scope', EntityType::class, [
'class' => Scope::class,
'choice_label' => function (Scope $s) {
return $this->translatableStringHelper->localize(
$s->getName()
);
},
'choice_label' => fn(Scope $s) => $this->translatableStringHelper->localize(
$s->getName()
),
'multiple' => true,
'expanded' => true,
]);

View File

@@ -89,14 +89,10 @@ class CalendarToRemoteHandler implements MessageHandlerInterface
$newInvites = array_filter(
array_map(
function ($id) {
return $this->inviteRepository->find($id);
},
fn($id) => $this->inviteRepository->find($id),
$calendarMessage->getNewInvitesIds(),
),
static function (?Invite $invite) {
return null !== $invite;
}
static fn(?Invite $invite) => null !== $invite
);
$this->calendarConnector->syncCalendar(

View File

@@ -58,14 +58,12 @@ class CalendarMessage
$this->previousMainUserId = null !== $calendar->previousMainUser ?
$calendar->previousMainUser->getId() : null;
$this->newInvitesIds = array_map(static fn (Invite $i) => $i->getId(), $calendar->newInvites);
$this->oldInvites = array_map(static function (Invite $i) {
return [
'inviteId' => $i->getId(),
'userId' => $i->getUser()->getId(),
'userEmail' => $i->getUser()->getEmail(),
'userLabel' => $i->getUser()->getLabel(),
];
}, $calendar->oldInvites);
$this->oldInvites = array_map(static fn(Invite $i) => [
'inviteId' => $i->getId(),
'userId' => $i->getUser()->getId(),
'userEmail' => $i->getUser()->getEmail(),
'userLabel' => $i->getUser()->getLabel(),
], $calendar->oldInvites);
}
public function getAction(): string

View File

@@ -121,9 +121,7 @@ class RemoteEventConverter
'subject' => '[Chill] ' .
implode(
', ',
$calendar->getPersons()->map(function (Person $p) {
return $this->personRender->renderString($p, []);
})->toArray()
$calendar->getPersons()->map(fn(Person $p) => $this->personRender->renderString($p, []))->toArray()
),
'start' => [
'dateTime' => $calendar->getStartDate()->setTimezone($this->remoteDateTimeZone)
@@ -161,9 +159,7 @@ class RemoteEventConverter
{
return [
'attendees' => $calendar->getInvites()->map(
function (Invite $i) {
return $this->buildInviteToAttendee($i);
}
fn(Invite $i) => $this->buildInviteToAttendee($i)
)->toArray(),
];
}

View File

@@ -190,23 +190,17 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
]
)->toArray();
$ids = array_map(static function ($item) {
return $item['id'];
}, $bareEvents['value']);
$ids = array_map(static fn($item) => $item['id'], $bareEvents['value']);
$existingIdsInRange = $this->calendarRangeRepository->findRemoteIdsPresent($ids);
$existingIdsInCalendar = $this->calendarRepository->findRemoteIdsPresent($ids);
return array_values(
array_map(
function ($item) {
return $this->remoteEventConverter->convertToRemote($item);
},
fn($item) => $this->remoteEventConverter->convertToRemote($item),
// filter all event to keep only the one not in range
array_filter(
$bareEvents['value'],
static function ($item) use ($existingIdsInRange, $existingIdsInCalendar) {
return ((!$existingIdsInRange[$item['id']]) ?? true) && ((!$existingIdsInCalendar[$item['id']]) ?? true);
}
static fn($item) => ((!$existingIdsInRange[$item['id']]) ?? true) && ((!$existingIdsInCalendar[$item['id']]) ?? true)
)
)
);
@@ -601,9 +595,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
}
$this->cacheScheduleTimeForUser[$userId] = array_map(
function ($item) {
return $this->remoteEventConverter->convertAvailabilityToRemoteEvent($item);
},
fn($item) => $this->remoteEventConverter->convertAvailabilityToRemoteEvent($item),
$response['value'][0]['scheduleItems']
);

View File

@@ -114,12 +114,8 @@ final class CalendarTypeTest extends TypeTestCase
$this->assertEquals(8, $calendar->getCalendarRange()->getId());
$this->assertEquals(9, $calendar->getLocation()->getId());
$this->assertEquals(true, $calendar->getSendSMS());
$this->assertContains(2, $calendar->getUsers()->map(static function (User $u) {
return $u->getId();
}));
$this->assertContains(3, $calendar->getUsers()->map(static function (User $u) {
return $u->getId();
}));
$this->assertContains(2, $calendar->getUsers()->map(static fn(User $u) => $u->getId()));
$this->assertContains(3, $calendar->getUsers()->map(static fn(User $u) => $u->getId()));
}
protected function getExtensions()
@@ -148,25 +144,17 @@ final class CalendarTypeTest extends TypeTestCase
) {
$transformer = $this->prophesize($classTransformer);
$transformer->transform(Argument::type('array'))
->will(static function ($args) {
return implode(
',',
array_map(static function ($p) {
return $p->getId();
}, $args[0])
);
});
->will(static fn($args) => implode(
',',
array_map(static fn($p) => $p->getId(), $args[0])
));
$transformer->transform(Argument::exact(null))
->willReturn([]);
$transformer->transform(Argument::type(Collection::class))
->will(static function ($args) {
return implode(
',',
array_map(static function ($p) {
return $p->getId();
}, $args[0]->toArray())
);
});
->will(static fn($args) => implode(
',',
array_map(static fn($p) => $p->getId(), $args[0]->toArray())
));
$transformer->reverseTransform(Argument::type('string'))
->will(static function ($args) use ($objClass) {
if (null === $args[0]) {
@@ -195,9 +183,7 @@ final class CalendarTypeTest extends TypeTestCase
) {
$transformer = $this->prophesize($classTransformer);
$transformer->transform(Argument::type('object'))
->will(static function ($args) {
return (string) $args[0]->getId();
});
->will(static fn($args) => (string) $args[0]->getId());
$transformer->transform(Argument::exact(null))
->willReturn('');
$transformer->reverseTransform(Argument::type('string'))

View File

@@ -63,9 +63,7 @@ final class AddressConverterTest extends TestCase
{
$engine = $this->prophesize(EngineInterface::class);
$translatableStringHelper = $this->prophesize(TranslatableStringHelperInterface::class);
$translatableStringHelper->localize(Argument::type('array'))->will(static function ($args): string {
return ($args[0] ?? ['fr' => 'not provided'])['fr'] ?? 'not provided';
});
$translatableStringHelper->localize(Argument::type('array'))->will(static fn($args): string => ($args[0] ?? ['fr' => 'not provided'])['fr'] ?? 'not provided');
$addressRender = new AddressRender($engine->reveal(), $translatableStringHelper->reveal());

View File

@@ -72,17 +72,13 @@ final class CalendarForShortMessageProviderTest extends TestCase
Argument::type(DateTimeImmutable::class),
Argument::type('int'),
Argument::exact(0)
)->will(static function ($args) {
return array_fill(0, $args[2], new Calendar());
})->shouldBeCalledTimes(1);
)->will(static fn($args) => array_fill(0, $args[2], new Calendar()))->shouldBeCalledTimes(1);
$calendarRepository->findByNotificationAvailable(
Argument::type(DateTimeImmutable::class),
Argument::type(DateTimeImmutable::class),
Argument::type('int'),
Argument::not(0)
)->will(static function ($args) {
return array_fill(0, $args[2] - 1, new Calendar());
})->shouldBeCalledTimes(1);
)->will(static fn($args) => array_fill(0, $args[2] - 1, new Calendar()))->shouldBeCalledTimes(1);
$em = $this->prophesize(EntityManagerInterface::class);
$em->clear()->shouldBeCalled();
@@ -108,17 +104,13 @@ final class CalendarForShortMessageProviderTest extends TestCase
Argument::type(DateTimeImmutable::class),
Argument::type('int'),
Argument::exact(0)
)->will(static function ($args) {
return array_fill(0, 1, new Calendar());
})->shouldBeCalledTimes(1);
)->will(static fn($args) => array_fill(0, 1, new Calendar()))->shouldBeCalledTimes(1);
$calendarRepository->findByNotificationAvailable(
Argument::type(DateTimeImmutable::class),
Argument::type(DateTimeImmutable::class),
Argument::type('int'),
Argument::not(0)
)->will(static function ($args) {
return [];
})->shouldBeCalledTimes(1);
)->will(static fn($args) => [])->shouldBeCalledTimes(1);
$em = $this->prophesize(EntityManagerInterface::class);
$em->clear()->shouldBeCalled();