Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce arrow functions from PHP 7.4 #13268

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
Expand All @@ -15,4 +16,5 @@

$services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class);
$services->set(ClosureToArrowFunctionRector::class);
};
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ public function configureOptions(OptionsResolver $resolver): void
$countries = array_filter($countries, $options['choice_filter']);
}

usort($countries, static function (CountryInterface $firstCountry, CountryInterface $secondCountry): int {
return $firstCountry->getName() <=> $secondCountry->getName();
});
usort($countries, static fn(CountryInterface $firstCountry, CountryInterface $secondCountry): int => $firstCountry->getName() <=> $secondCountry->getName());

return $countries;
})
Expand Down
4 changes: 1 addition & 3 deletions src/Sylius/Bundle/AddressingBundle/Form/Type/ZoneType.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
];

if ($zone->getType() === ZoneInterface::TYPE_ZONE) {
$entryOptions['entry_options']['choice_filter'] = static function (?ZoneInterface $subZone) use ($zone): bool {
return $subZone !== null && $zone->getId() !== $subZone->getId();
};
$entryOptions['entry_options']['choice_filter'] = static fn(?ZoneInterface $subZone): bool => $subZone !== null && $zone->getId() !== $subZone->getId();
}

$event->getForm()->add('members', CollectionType::class, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,14 @@ public function it_returns_filtered_out_countries(): void
$this->poland->reveal(),
]);

$this->assertChoicesLabels(['Poland'], ['choice_filter' => static function (?CountryInterface $country): bool {
return $country !== null && $country->getName() === 'Poland';
}]);
$this->assertChoicesLabels(['Poland'], ['choice_filter' => static fn(?CountryInterface $country): bool => $country !== null && $country->getName() === 'Poland']);
}

private function assertChoicesLabels(array $expectedLabels, array $formConfiguration = []): void
{
$form = $this->factory->create(CountryChoiceType::class, null, $formConfiguration);
$view = $form->createView();

Assert::assertSame($expectedLabels, array_map(static function (ChoiceView $choiceView): string {
return $choiceView->label;
}, $view->vars['choices']));
Assert::assertSame($expectedLabels, array_map(static fn(ChoiceView $choiceView): string => $choiceView->label, $view->vars['choices']));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ private function assertChoicesLabels(array $expectedLabels, array $formConfigura
$form = $this->factory->create(ZoneChoiceType::class, null, $formConfiguration);
$view = $form->createView();

Assert::assertSame($expectedLabels, array_map(function (ChoiceView $choiceView): string {
return $choiceView->label;
}, $view->vars['choices']));
Assert::assertSame($expectedLabels, array_map(fn(ChoiceView $choiceView): string => $choiceView->label, $view->vars['choices']));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public function its_services_are_initializable(): void

$services = $container->getServiceIds();

$services = array_filter($services, function (string $serviceId): bool {
return 0 === strpos($serviceId, 'sylius.');
});
$services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));

foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ private function getAmount(OrderItemInterface $orderItem, bool $neutral): int
{
$total = array_reduce(
$orderItem->getAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->toArray(),
static function (int $total, BaseAdjustmentInterface $adjustment) use ($neutral) {
return $neutral === $adjustment->isNeutral() ? $total + $adjustment->getAmount() : $total;
},
static fn(int $total, BaseAdjustmentInterface $adjustment) => $neutral === $adjustment->isNeutral() ? $total + $adjustment->getAmount() : $total,
0
);

Expand Down
4 changes: 1 addition & 3 deletions src/Sylius/Bundle/AdminBundle/Twig/ShopExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ public function __construct(bool $isShopEnabled)
public function getFunctions(): array
{
return [
new TwigFunction('is_shop_enabled', function (): bool {
return $this->isShopEnabled;
}),
new TwigFunction('is_shop_enabled', fn(): bool => $this->isShopEnabled),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@ public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'entries' => $this->definedLocalesCodes,
'entry_name' => function (string $localeCode): string {
return $localeCode;
},
'entry_options' => function (string $localeCode): array {
return [
'required' => $localeCode === $this->defaultLocaleCode,
];
},
'entry_name' => fn(string $localeCode): string => $localeCode,
'entry_options' => fn(string $localeCode): array => [
'required' => $localeCode === $this->defaultLocaleCode,
],
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ private function assertChoicesLabels(array $expectedLabels, array $formConfigura
);
$view = $form->createView();

Assert::assertSame($expectedLabels, array_map(function (ChoiceView $choiceView): string {
return $choiceView->label;
}, $view->vars['choices']));
Assert::assertSame($expectedLabels, array_map(fn(ChoiceView $choiceView): string => $choiceView->label, $view->vars['choices']));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public function its_services_are_initializable(): void

$services = $container->getServiceIds();

$services = array_filter($services, function (string $serviceId): bool {
return 0 === strpos($serviceId, 'sylius.');
});
$services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));

foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'choices' => function (Options $options): array {
return $this->channelRepository->findAll();
},
'choices' => fn(Options $options): array => $this->channelRepository->findAll(),
'choice_value' => 'code',
'choice_label' => 'name',
'choice_translation_domain' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ function it_persists_fake_channel_codes_in_a_cookie(

$response->headers = $responseHeaderBag;
$responseHeaderBag
->setCookie(Argument::that(static function (Cookie $cookie): bool {
return $cookie->getName() === '_channel_code' && $cookie->getValue() === 'fake_channel_code';
}))
->setCookie(Argument::that(static fn(Cookie $cookie): bool => $cookie->getName() === '_channel_code' && $cookie->getValue() === 'fake_channel_code'))
->shouldBeCalled()
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public function its_services_are_initializable(): void

$services = $container->getServiceIds();

$services = array_filter($services, function (string $serviceId): bool {
return 0 === strpos($serviceId, 'sylius.');
});
$services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));

foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public function process(ContainerBuilder $container): void
}
}

usort($uriBasedSectionProviders, static function (array $a, array $b): int {
return -($a['priority'] <=> $b['priority']);
});
usort($uriBasedSectionProviders, static fn(array $a, array $b): int => -($a['priority'] <=> $b['priority']));

$uriBasedSectionResolver->setArgument(1, array_column($uriBasedSectionProviders, 'id'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,13 @@ public function __construct(
protected function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefault('first_name', function (Options $options): string {
return $this->faker->firstName;
})
->setDefault('last_name', function (Options $options): string {
return $this->faker->lastName;
})
->setDefault('phone_number', function (Options $options): ?string {
return random_int(1, 100) > 50 ? $this->faker->phoneNumber : null;
})
->setDefault('company', function (Options $options): ?string {
return random_int(1, 100) > 50 ? $this->faker->company : null;
})
->setDefault('street', function (Options $options): string {
return $this->faker->streetAddress;
})
->setDefault('city', function (Options $options): string {
return $this->faker->city;
})
->setDefault('postcode', function (Options $options): string {
return $this->faker->postcode;
})
->setDefault('first_name', fn(Options $options): string => $this->faker->firstName)
->setDefault('last_name', fn(Options $options): string => $this->faker->lastName)
->setDefault('phone_number', fn(Options $options): ?string => random_int(1, 100) > 50 ? $this->faker->phoneNumber : null)
->setDefault('company', fn(Options $options): ?string => random_int(1, 100) > 50 ? $this->faker->company : null)
->setDefault('street', fn(Options $options): string => $this->faker->streetAddress)
->setDefault('city', fn(Options $options): string => $this->faker->city)
->setDefault('postcode', fn(Options $options): string => $this->faker->postcode)
->setDefault('country_code', function (Options $options): string {
$countries = $this->countryRepository->findAll();
shuffle($countries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,8 @@ public function create(array $options = []): AdminUserInterface
protected function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefault('email', function (Options $options): string {
return $this->faker->email;
})
->setDefault('username', function (Options $options): string {
return $this->faker->firstName . ' ' . $this->faker->lastName;
})
->setDefault('email', fn(Options $options): string => $this->faker->email)
->setDefault('username', fn(Options $options): string => $this->faker->firstName . ' ' . $this->faker->lastName)
->setDefault('enabled', true)
->setAllowedTypes('enabled', 'bool')
->setDefault('password', 'password123')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,10 @@ protected function configureOptions(OptionsResolver $resolver): void

return $words;
})
->setDefault('code', function (Options $options): string {
return StringInflector::nameToCode($options['name']);
})
->setDefault('hostname', function (Options $options): string {
return $options['code'] . '.localhost';
})
->setDefault('color', function (Options $options): string {
return $this->faker->colorName;
})
->setDefault('enabled', function (Options $options): bool {
return $this->faker->boolean(90);
})
->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
->setDefault('hostname', fn(Options $options): string => $options['code'] . '.localhost')
->setDefault('color', fn(Options $options): string => $this->faker->colorName)
->setDefault('enabled', fn(Options $options): bool => $this->faker->boolean(90))
->setAllowedTypes('enabled', 'bool')
->setDefault('skipping_shipping_step_allowed', false)
->setAllowedTypes('skipping_shipping_step_allowed', 'bool')
Expand All @@ -166,17 +158,13 @@ protected function configureOptions(OptionsResolver $resolver): void
)
->setDefault('tax_calculation_strategy', 'order_items_based')
->setAllowedTypes('tax_calculation_strategy', 'string')
->setDefault('default_locale', function (Options $options): LocaleInterface {
return $this->faker->randomElement($options['locales']);
})
->setDefault('default_locale', fn(Options $options): LocaleInterface => $this->faker->randomElement($options['locales']))
->setAllowedTypes('default_locale', ['string', LocaleInterface::class])
->setNormalizer('default_locale', LazyOption::getOneBy($this->localeRepository, 'code'))
->setDefault('locales', LazyOption::all($this->localeRepository))
->setAllowedTypes('locales', 'array')
->setNormalizer('locales', LazyOption::findBy($this->localeRepository, 'code'))
->setDefault('base_currency', function (Options $options): CurrencyInterface {
return $this->faker->randomElement($options['currencies']);
})
->setDefault('base_currency', fn(Options $options): CurrencyInterface => $this->faker->randomElement($options['currencies']))
->setAllowedTypes('base_currency', ['string', CurrencyInterface::class])
->setNormalizer('base_currency', LazyOption::getOneBy($this->currencyRepository, 'code'))
->setDefault('currencies', LazyOption::all($this->currencyRepository))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ protected function configureOptions(OptionsResolver $resolver): void

return $words;
})
->setDefault('code', function (Options $options): string {
return StringInflector::nameToCode($options['name']);
})
->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ protected function configureOptions(OptionsResolver $resolver): void
->setAllowedTypes('country', ['null', 'string', CountryInterface::class])
->setNormalizer('country', LazyOption::findOneBy($this->countryRepository, 'code'))

->setDefault('complete_date', function (Options $options): \DateTimeInterface {
return $this->faker->dateTimeBetween('-1 years', 'now');
})
->setDefault('complete_date', fn(Options $options): \DateTimeInterface => $this->faker->dateTimeBetween('-1 years', 'now'))
->setAllowedTypes('complete_date', ['null', \DateTime::class])

->setDefault('fulfilled', false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,14 @@ protected function configureOptions(OptionsResolver $resolver): void

return $words;
})
->setDefault('code', function (Options $options): string {
return StringInflector::nameToCode($options['name']);
})
->setDefault('description', function (Options $options): string {
return $this->faker->sentence();
})
->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
->setDefault('description', fn(Options $options): string => $this->faker->sentence())
->setDefault('instructions', null)
->setAllowedTypes('instructions', ['null', 'string'])
->setDefault('gatewayName', 'Offline')
->setDefault('gatewayFactory', 'offline')
->setDefault('gatewayConfig', [])
->setDefault('enabled', function (Options $options): bool {
return $this->faker->boolean(90);
})
->setDefault('enabled', fn(Options $options): bool => $this->faker->boolean(90))
->setDefault('channels', LazyOption::all($this->channelRepository))
->setAllowedTypes('channels', 'array')
->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ protected function configureOptions(OptionsResolver $resolver): void

return $words;
})
->setDefault('code', function (Options $options): string {
return StringInflector::nameToCode($options['name']);
})
->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,9 @@ protected function configureOptions(OptionsResolver $resolver): void
return $words;
})
->setDefault('translatable', true)
->setDefault('code', function (Options $options): string {
return StringInflector::nameToCode($options['name']);
})
->setDefault('type', function (Options $options): string {
return $this->faker->randomElement(array_keys($this->attributeTypes));
})
->setDefault('configuration', function (Options $options): array {
return [];
})
->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
->setDefault('type', fn(Options $options): string => $this->faker->randomElement(array_keys($this->attributeTypes)))
->setDefault('configuration', fn(Options $options): array => [])
->setAllowedValues('type', array_keys($this->attributeTypes))
;
}
Expand Down
Loading