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

@@ -59,9 +59,7 @@ class Configuration implements ConfigurationInterface
->info('The number of seconds of this duration. Must be an integer.')
->cannotBeEmpty()
->validate()
->ifTrue(static function ($data) {
return !is_int($data);
})->thenInvalid('The value %s is not a valid integer')
->ifTrue(static fn($data) => !is_int($data))->thenInvalid('The value %s is not a valid integer')
->end()
->end()
->scalarNode('label')

View File

@@ -195,7 +195,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
* @Groups({"docgen:read"})
*/
private ?User $user;
private ?User $user = null;
/**
* @ORM\ManyToMany(targetEntity="Chill\MainBundle\Entity\User")

View File

@@ -34,7 +34,7 @@ class ActivityPresence
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"docgen:read"})
*/
private ?int $id;
private ?int $id = null;
/**
* @ORM\Column(type="json")

View File

@@ -122,7 +122,7 @@ class ActivityType
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"docgen:read"})
*/
private ?int $id;
private ?int $id = null;
/**
* @ORM\Column(type="string", nullable=false, options={"default": ""})

View File

@@ -86,9 +86,7 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$centers = array_map(static fn($el) => $el['center'], $acl);
$qb = $this->repository->createQueryBuilder('activity');

View File

@@ -87,9 +87,7 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$centers = array_map(static fn($el) => $el['center'], $acl);
$qb = $this->repository->createQueryBuilder('activity');

View File

@@ -86,9 +86,7 @@ class CountActivity implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$centers = array_map(static fn($el) => $el['center'], $acl);
$qb = $this->repository
->createQueryBuilder('activity')

View File

@@ -109,9 +109,7 @@ class ListActivity implements ListInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$centers = array_map(static fn($el) => $el['center'], $acl);
$qb = $this->entityManager->createQueryBuilder();

View File

@@ -87,9 +87,7 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$centers = array_map(static fn($el) => $el['center'], $acl);
$qb = $this->repository
->createQueryBuilder('activity')

View File

@@ -87,9 +87,7 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$centers = array_map(static fn($el) => $el['center'], $acl);
$qb = $this->repository
->createQueryBuilder('activity')

View File

@@ -137,13 +137,11 @@ class ListActivity implements ListInterface, GroupedExportInterface
$activity = $activityRepository->find($value);
return implode(', ', array_map(function (ActivityReason $r) {
return '"' .
$this->translatableStringHelper->localize($r->getCategory()->getName())
. ' > ' .
$this->translatableStringHelper->localize($r->getName())
. '"';
}, $activity->getReasons()->toArray()));
return implode(', ', array_map(fn(ActivityReason $r) => '"' .
$this->translatableStringHelper->localize($r->getCategory()->getName())
. ' > ' .
$this->translatableStringHelper->localize($r->getName())
. '"', $activity->getReasons()->toArray()));
};
case 'circle_name':
@@ -197,9 +195,7 @@ class ListActivity implements ListInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$centers = array_map(static fn($el) => $el['center'], $acl);
// throw an error if any fields are present
if (!array_key_exists('fields', $data)) {

View File

@@ -61,12 +61,9 @@ class ActivityTypeFilter implements FilterInterface
$builder->add('accepted_activitytypes', EntityType::class, [
'class' => ActivityType::class,
'choices' => $this->activityTypeRepository->findAllActive(),
'choice_label' => function (ActivityType $aty) {
return
($aty->hasCategory() ? $this->translatableStringHelper->localize($aty->getCategory()->getName()) . ' > ' : '')
.
$this->translatableStringHelper->localize($aty->getName());
},
'choice_label' => fn(ActivityType $aty) => ($aty->hasCategory() ? $this->translatableStringHelper->localize($aty->getCategory()->getName()) . ' > ' : '')
.
$this->translatableStringHelper->localize($aty->getName()),
'multiple' => true,
'expanded' => true,
]);

View File

@@ -64,11 +64,9 @@ class UserScopeFilter implements FilterInterface
{
$builder->add('accepted_userscope', 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

@@ -61,12 +61,9 @@ class ActivityTypeFilter implements ExportElementValidatedInterface, FilterInter
$builder->add('types', EntityType::class, [
'choices' => $this->activityTypeRepository->findAllActive(),
'class' => ActivityType::class,
'choice_label' => function (ActivityType $aty) {
return
($aty->hasCategory() ? $this->translatableStringHelper->localize($aty->getCategory()->getName()) . ' > ' : '')
.
$this->translatableStringHelper->localize($aty->getName());
},
'choice_label' => fn(ActivityType $aty) => ($aty->hasCategory() ? $this->translatableStringHelper->localize($aty->getCategory()->getName()) . ' > ' : '')
.
$this->translatableStringHelper->localize($aty->getName()),
'group_by' => function (ActivityType $type) {
if (!$type->hasCategory()) {
return null;

View File

@@ -211,13 +211,9 @@ class ActivityType extends AbstractType
'required' => $activityType->isRequired('attendee'),
'expanded' => true,
'class' => ActivityPresence::class,
'choice_label' => function (ActivityPresence $activityPresence) {
return $this->translatableStringHelper->localize($activityPresence->getName());
},
'query_builder' => static function (EntityRepository $er) {
return $er->createQueryBuilder('a')
->where('a.active = true');
},
'choice_label' => fn(ActivityPresence $activityPresence) => $this->translatableStringHelper->localize($activityPresence->getName()),
'query_builder' => static fn(EntityRepository $er) => $er->createQueryBuilder('a')
->where('a.active = true'),
]);
}
@@ -357,9 +353,7 @@ class ActivityType extends AbstractType
return (string) $location->getId();
},
function (?string $id): ?Location {
return $this->om->getRepository(Location::class)->findOneBy(['id' => (int) $id]);
}
fn(?string $id): ?Location => $this->om->getRepository(Location::class)->findOneBy(['id' => (int) $id])
));
}

View File

@@ -45,9 +45,7 @@ class ActivityTypeType extends AbstractType
])
->add('category', EntityType::class, [
'class' => ActivityTypeCategory::class,
'choice_label' => function (ActivityTypeCategory $activityTypeCategory) {
return $this->translatableStringHelper->localize($activityTypeCategory->getName());
},
'choice_label' => fn(ActivityTypeCategory $activityTypeCategory) => $this->translatableStringHelper->localize($activityTypeCategory->getName()),
])
->add('ordering', NumberType::class, [
'required' => true,

View File

@@ -45,9 +45,7 @@ class PickActivityReasonType extends AbstractType
$resolver->setDefaults(
[
'class' => ActivityReason::class,
'choice_label' => function (ActivityReason $choice) {
return $this->reasonRender->renderString($choice, []);
},
'choice_label' => fn(ActivityReason $choice) => $this->reasonRender->renderString($choice, []),
'group_by' => function (ActivityReason $choice): ?string {
if (null !== $category = $choice->getCategory()) {
return $this->translatableStringHelper->localize($category->getName());

View File

@@ -38,10 +38,8 @@ class TranslatableActivityReasonCategoryType extends AbstractType
$resolver->setDefaults(
[
'class' => ActivityReasonCategory::class,
'choice_label' => function (ActivityReasonCategory $category) {
return $this->translatableStringHelper->localize($category->getName())
. (!$category->getActive() ? ' (' . $this->translator->trans('inactive') . ')' : '');
},
'choice_label' => fn(ActivityReasonCategory $category) => $this->translatableStringHelper->localize($category->getName())
. (!$category->getActive() ? ' (' . $this->translator->trans('inactive') . ')' : ''),
]
);
}

View File

@@ -39,9 +39,7 @@ class TranslatableActivityType extends AbstractType
'class' => ActivityType::class,
'active_only' => true,
'choices' => $this->activityTypeRepository->findAllActive(),
'choice_label' => function (ActivityType $type) {
return $this->translatableStringHelper->localize($type->getName());
},
'choice_label' => fn(ActivityType $type) => $this->translatableStringHelper->localize($type->getName()),
]
);
}

View File

@@ -254,9 +254,7 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte
$reachableScopes = $this->authorizationHelper->getReachableScopes($this->tokenStorage->getToken()->getUser(), ActivityVoter::SEE, $center);
// we get the ids for those scopes
$reachablesScopesId = array_map(
static function (Scope $scope) {
return $scope->getId();
},
static fn(Scope $scope) => $scope->getId(),
$reachableScopes
);

View File

@@ -134,9 +134,7 @@ class ActivityContext implements
$builder->add($key, EntityType::class, [
'class' => Person::class,
'choices' => $persons,
'choice_label' => function (Person $p) {
return $this->personRender->renderString($p, []);
},
'choice_label' => fn(Person $p) => $this->personRender->renderString($p, []),
'multiple' => false,
'required' => false,
'expanded' => true,

View File

@@ -146,9 +146,7 @@ class ListActivitiesByAccompanyingPeriodContext implements
return array_filter(
$activities,
function ($activity) use ($user) {
$activityUsernames = array_map(static function ($user) {
return $user['username'];
}, $activity['users'] ?? []);
$activityUsernames = array_map(static fn($user) => $user['username'], $activity['users'] ?? []);
return in_array($user->getUsername(), $activityUsernames, true);
}
);
@@ -159,9 +157,7 @@ class ListActivitiesByAccompanyingPeriodContext implements
return array_filter(
$works,
function ($work) use ($user) {
$workUsernames = array_map(static function ($user) {
return $user['username'];
}, $work['referrers'] ?? []);
$workUsernames = array_map(static fn($user) => $user['username'], $work['referrers'] ?? []);
return in_array($user->getUsername(), $workUsernames, true);
}

View File

@@ -369,12 +369,8 @@ final class ActivityControllerTest extends WebTestCase
$center
);
$reachableScopesId = array_intersect(
array_map(static function ($s) {
return $s->getId();
}, $reachableScopesDelete),
array_map(static function ($s) {
return $s->getId();
}, $reachableScopesUpdate)
array_map(static fn($s) => $s->getId(), $reachableScopesDelete),
array_map(static fn($s) => $s->getId(), $reachableScopesUpdate)
);
if (count($reachableScopesId) === 0) {

View File

@@ -188,9 +188,7 @@ final class ActivityTypeTest extends KernelTestCase
// map all the values in an array
$values = array_map(
static function ($choice) {
return $choice->value;
},
static fn($choice) => $choice->value,
$view['activity']['durationTime']->vars['choices']
);

View File

@@ -83,9 +83,7 @@ final class TranslatableActivityReasonTest extends TypeTestCase
$request->getLocale()->willReturn($fallbackLocale);
$requestStack->willExtend(\Symfony\Component\HttpFoundation\RequestStack::class);
$requestStack->getCurrentRequest()->will(static function () use ($request) {
return $request;
});
$requestStack->getCurrentRequest()->will(static fn() => $request);
$translator->willExtend(\Symfony\Component\Translation\Translator::class);
$translator->getFallbackLocales()->willReturn($locale);