From dabb69ad0d292096e14a99fe968dafc3490affcc Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Tue, 2 Nov 2021 13:37:55 +0100 Subject: [PATCH] Introduce arrow functions from PHP 7.4 --- rector.php | 2 ++ .../Form/Type/CountryChoiceType.php | 4 +-- .../AddressingBundle/Form/Type/ZoneType.php | 4 +-- .../Tests/Form/Type/CountryChoiceTypeTest.php | 8 ++---- .../Tests/Form/Type/ZoneChoiceTypeTest.php | 4 +-- .../src/Tests/SyliusAddressingBundleTest.php | 4 +-- .../Twig/OrderUnitTaxesExtension.php | 4 +-- .../Bundle/AdminBundle/Twig/ShopExtension.php | 4 +-- .../SelectAttributeValueTranslationsType.php | 12 +++----- .../AttributeType/SelectAttributeTypeTest.php | 4 +-- .../src/Tests/SyliusAttributeBundleTest.php | 4 +-- .../Form/Type/ChannelChoiceType.php | 4 +-- .../FakeChannel/FakeChannelPersisterSpec.php | 4 +-- .../src/Tests/SyliusChannelBundleTest.php | 4 +-- .../RegisterUriBasedSectionResolverPass.php | 4 +-- .../Fixture/Factory/AddressExampleFactory.php | 28 +++++-------------- .../Factory/AdminUserExampleFactory.php | 8 ++---- .../Fixture/Factory/ChannelExampleFactory.php | 24 ++++------------ .../Factory/CustomerGroupExampleFactory.php | 4 +-- .../Fixture/Factory/OrderExampleFactory.php | 4 +-- .../Factory/PaymentMethodExampleFactory.php | 12 ++------ .../ProductAssociationTypeExampleFactory.php | 4 +-- .../ProductAttributeExampleFactory.php | 12 ++------ .../Fixture/Factory/ProductExampleFactory.php | 20 ++++--------- .../Factory/ProductOptionExampleFactory.php | 4 +-- .../Factory/ProductReviewExampleFactory.php | 4 +-- .../Factory/PromotionExampleFactory.php | 4 +-- .../ShippingCategoryExampleFactory.php | 8 ++---- .../Factory/ShippingMethodExampleFactory.php | 12 ++------ .../Factory/ShopUserExampleFactory.php | 20 ++++--------- .../Factory/TaxCategoryExampleFactory.php | 8 ++---- .../Fixture/Factory/TaxRateExampleFactory.php | 12 ++------ .../Fixture/Factory/TaxonExampleFactory.php | 8 ++---- .../Fixture/OptionsResolver/LazyOption.php | 4 +-- .../TaxonsToCodesTransformer.php | 4 +-- .../Form/Extension/CartTypeExtension.php | 14 ++++------ .../ProductVariantGenerationTypeExtension.php | 10 +++---- .../Extension/ProductVariantTypeExtension.php | 12 ++++---- .../CoreBundle/Form/Type/AmountType.php | 4 +-- .../Form/Type/ChannelCollectionType.php | 4 +-- .../Form/Type/Product/ChannelPricingType.php | 4 +-- ...nelBasedFixedDiscountConfigurationType.php | 10 +++---- ...asedUnitFixedDiscountConfigurationType.php | 10 +++---- ...nitPercentageDiscountConfigurationType.php | 10 +++---- ...ChannelBasedItemTotalConfigurationType.php | 10 +++---- ...TotalOfItemsFromTaxonConfigurationType.php | 10 +++---- .../ChannelBasedFlatRateConfigurationType.php | 10 +++---- ...annelBasedPerUnitRateConfigurationType.php | 10 +++---- ...talGreaterThanOrEqualConfigurationType.php | 10 +++---- ...rTotalLessThanOrEqualConfigurationType.php | 10 +++---- .../CoreBundle/Security/UserImpersonator.php | 4 +-- .../Form/Type/CurrencyChoiceType.php | 4 +-- .../src/Tests/SyliusCurrencyBundleTest.php | 4 +-- .../Form/Type/CustomerChoiceType.php | 8 ++---- .../Form/Type/CustomerGroupChoiceType.php | 4 +-- .../src/Tests/SyliusCustomerBundleTest.php | 4 +-- .../src/Tests/SyliusInventoryBundleTest.php | 4 +-- .../test/src/Tests/SyliusLocaleBundleTest.php | 4 +-- .../test/src/Tests/SyliusMoneyBundleTest.php | 4 +-- .../test/src/Tests/SyliusOrderBundleTest.php | 4 +-- .../src/Tests/SyliusPaymentBundleTest.php | 4 +-- .../RegisterGatewayConfigTypePass.php | 4 +-- ...ductVariantToProductOptionsTransformer.php | 4 +-- .../BuildAttributesFormSubscriber.php | 4 +-- .../Type/ProductAssociationTypeChoiceType.php | 4 +-- .../Form/Type/ProductAssociationsType.php | 12 +++----- .../Form/Type/ProductChoiceType.php | 4 +-- .../Form/Type/ProductOptionChoiceType.php | 4 +-- .../Form/Type/ProductVariantChoiceType.php | 9 ++---- .../Form/Type/ProductVariantMatchType.php | 20 +++++-------- .../src/Tests/SyliusProductBundleTest.php | 4 +-- ...ePromotionCouponEligibilityCheckerPass.php | 4 +-- ...mpositePromotionEligibilityCheckerPass.php | 4 +-- .../src/Tests/SyliusPromotionBundleTest.php | 4 +-- .../test/src/Tests/SyliusReviewBundleTest.php | 4 +-- ...teShippingMethodEligibilityCheckerPass.php | 4 +-- .../Form/Type/ShippingCategoryChoiceType.php | 4 +-- .../src/Tests/SyliusShippingBundleTest.php | 4 +-- .../OrderItemsSubtotalCalculator.php | 4 +-- .../Controller/CurrencySwitchController.php | 4 +-- .../DependencyInjection/Configuration.php | 4 +-- .../Twig/OrderTaxesTotalExtension.php | 4 +-- .../Form/Type/TaxCategoryChoiceType.php | 4 +-- .../src/Tests/SyliusTaxationBundleTest.php | 4 +-- .../Functional/SyliusTaxonomyBundleTest.php | 4 +-- .../Command/DebugTemplateEventCommand.php | 14 ++++------ .../TemplateBlockDataCollector.php | 8 ++---- .../DependencyInjection/Configuration.php | 4 +-- .../Registry/TemplateBlockRegistry.php | 8 ++---- .../HtmlDebugTemplateEventRenderer.php | 4 +-- .../UiBundle/Twig/MergeRecursiveExtension.php | 4 +-- .../Command/AbstractRoleCommand.php | 4 +-- .../Bundle/UserBundle/Security/UserLogin.php | 2 +- .../Tests/Functional/SyliusUserBundleTest.php | 4 +-- 94 files changed, 188 insertions(+), 449 deletions(-) diff --git a/rector.php b/rector.php index 6566b71df8ff..036691adabc8 100644 --- a/rector.php +++ b/rector.php @@ -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; @@ -15,4 +16,5 @@ $services = $containerConfigurator->services(); $services->set(TypedPropertyRector::class); + $services->set(ClosureToArrowFunctionRector::class); }; diff --git a/src/Sylius/Bundle/AddressingBundle/Form/Type/CountryChoiceType.php b/src/Sylius/Bundle/AddressingBundle/Form/Type/CountryChoiceType.php index 1719c74eba6b..2be7cffd29f4 100644 --- a/src/Sylius/Bundle/AddressingBundle/Form/Type/CountryChoiceType.php +++ b/src/Sylius/Bundle/AddressingBundle/Form/Type/CountryChoiceType.php @@ -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; }) diff --git a/src/Sylius/Bundle/AddressingBundle/Form/Type/ZoneType.php b/src/Sylius/Bundle/AddressingBundle/Form/Type/ZoneType.php index 88d6a8023c8a..25c325289d7c 100644 --- a/src/Sylius/Bundle/AddressingBundle/Form/Type/ZoneType.php +++ b/src/Sylius/Bundle/AddressingBundle/Form/Type/ZoneType.php @@ -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, [ diff --git a/src/Sylius/Bundle/AddressingBundle/Tests/Form/Type/CountryChoiceTypeTest.php b/src/Sylius/Bundle/AddressingBundle/Tests/Form/Type/CountryChoiceTypeTest.php index 97d90b06abcf..59d40131b49c 100644 --- a/src/Sylius/Bundle/AddressingBundle/Tests/Form/Type/CountryChoiceTypeTest.php +++ b/src/Sylius/Bundle/AddressingBundle/Tests/Form/Type/CountryChoiceTypeTest.php @@ -110,9 +110,7 @@ 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 @@ -120,8 +118,6 @@ private function assertChoicesLabels(array $expectedLabels, array $formConfigura $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'])); } } diff --git a/src/Sylius/Bundle/AddressingBundle/Tests/Form/Type/ZoneChoiceTypeTest.php b/src/Sylius/Bundle/AddressingBundle/Tests/Form/Type/ZoneChoiceTypeTest.php index 1f00efdc9d25..e16f1b3b106d 100644 --- a/src/Sylius/Bundle/AddressingBundle/Tests/Form/Type/ZoneChoiceTypeTest.php +++ b/src/Sylius/Bundle/AddressingBundle/Tests/Form/Type/ZoneChoiceTypeTest.php @@ -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'])); } } diff --git a/src/Sylius/Bundle/AddressingBundle/test/src/Tests/SyliusAddressingBundleTest.php b/src/Sylius/Bundle/AddressingBundle/test/src/Tests/SyliusAddressingBundleTest.php index 7f488a954bb5..d014f639f132 100644 --- a/src/Sylius/Bundle/AddressingBundle/test/src/Tests/SyliusAddressingBundleTest.php +++ b/src/Sylius/Bundle/AddressingBundle/test/src/Tests/SyliusAddressingBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/AdminBundle/Twig/OrderUnitTaxesExtension.php b/src/Sylius/Bundle/AdminBundle/Twig/OrderUnitTaxesExtension.php index 91a470e973c0..e45984a04bfb 100644 --- a/src/Sylius/Bundle/AdminBundle/Twig/OrderUnitTaxesExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Twig/OrderUnitTaxesExtension.php @@ -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 ); diff --git a/src/Sylius/Bundle/AdminBundle/Twig/ShopExtension.php b/src/Sylius/Bundle/AdminBundle/Twig/ShopExtension.php index 5ea0ba5bd301..35b5f86b9c6b 100644 --- a/src/Sylius/Bundle/AdminBundle/Twig/ShopExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Twig/ShopExtension.php @@ -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), ]; } } diff --git a/src/Sylius/Bundle/AttributeBundle/Form/Type/AttributeType/Configuration/SelectAttributeValueTranslationsType.php b/src/Sylius/Bundle/AttributeBundle/Form/Type/AttributeType/Configuration/SelectAttributeValueTranslationsType.php index 489732fad207..6158c5f32b60 100644 --- a/src/Sylius/Bundle/AttributeBundle/Form/Type/AttributeType/Configuration/SelectAttributeValueTranslationsType.php +++ b/src/Sylius/Bundle/AttributeBundle/Form/Type/AttributeType/Configuration/SelectAttributeValueTranslationsType.php @@ -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, + ], ]); } diff --git a/src/Sylius/Bundle/AttributeBundle/Tests/Form/Type/AttributeType/SelectAttributeTypeTest.php b/src/Sylius/Bundle/AttributeBundle/Tests/Form/Type/AttributeType/SelectAttributeTypeTest.php index 41966b9a1d7f..8b76b04d6881 100644 --- a/src/Sylius/Bundle/AttributeBundle/Tests/Form/Type/AttributeType/SelectAttributeTypeTest.php +++ b/src/Sylius/Bundle/AttributeBundle/Tests/Form/Type/AttributeType/SelectAttributeTypeTest.php @@ -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'])); } } diff --git a/src/Sylius/Bundle/AttributeBundle/test/src/Tests/SyliusAttributeBundleTest.php b/src/Sylius/Bundle/AttributeBundle/test/src/Tests/SyliusAttributeBundleTest.php index 66079bb6ea59..cbd1f9a1164e 100644 --- a/src/Sylius/Bundle/AttributeBundle/test/src/Tests/SyliusAttributeBundleTest.php +++ b/src/Sylius/Bundle/AttributeBundle/test/src/Tests/SyliusAttributeBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/ChannelBundle/Form/Type/ChannelChoiceType.php b/src/Sylius/Bundle/ChannelBundle/Form/Type/ChannelChoiceType.php index 751030bbacac..58355f1b4100 100644 --- a/src/Sylius/Bundle/ChannelBundle/Form/Type/ChannelChoiceType.php +++ b/src/Sylius/Bundle/ChannelBundle/Form/Type/ChannelChoiceType.php @@ -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, diff --git a/src/Sylius/Bundle/ChannelBundle/spec/Context/FakeChannel/FakeChannelPersisterSpec.php b/src/Sylius/Bundle/ChannelBundle/spec/Context/FakeChannel/FakeChannelPersisterSpec.php index 0e79fd5375ac..8c205540d539 100644 --- a/src/Sylius/Bundle/ChannelBundle/spec/Context/FakeChannel/FakeChannelPersisterSpec.php +++ b/src/Sylius/Bundle/ChannelBundle/spec/Context/FakeChannel/FakeChannelPersisterSpec.php @@ -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() ; diff --git a/src/Sylius/Bundle/ChannelBundle/test/src/Tests/SyliusChannelBundleTest.php b/src/Sylius/Bundle/ChannelBundle/test/src/Tests/SyliusChannelBundleTest.php index 9a0104329435..400b5571b9bf 100644 --- a/src/Sylius/Bundle/ChannelBundle/test/src/Tests/SyliusChannelBundleTest.php +++ b/src/Sylius/Bundle/ChannelBundle/test/src/Tests/SyliusChannelBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/CoreBundle/DependencyInjection/Compiler/RegisterUriBasedSectionResolverPass.php b/src/Sylius/Bundle/CoreBundle/DependencyInjection/Compiler/RegisterUriBasedSectionResolverPass.php index a014a6d41017..74f5335ba17c 100644 --- a/src/Sylius/Bundle/CoreBundle/DependencyInjection/Compiler/RegisterUriBasedSectionResolverPass.php +++ b/src/Sylius/Bundle/CoreBundle/DependencyInjection/Compiler/RegisterUriBasedSectionResolverPass.php @@ -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')); } diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/AddressExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/AddressExampleFactory.php index e8ef4890e38f..6077004f97a8 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/AddressExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/AddressExampleFactory.php @@ -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); diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/AdminUserExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/AdminUserExampleFactory.php index 921a12494fa9..068c7cda0532 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/AdminUserExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/AdminUserExampleFactory.php @@ -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') diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ChannelExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ChannelExampleFactory.php index 2e166a929b42..ebb23eec7310 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ChannelExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ChannelExampleFactory.php @@ -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') @@ -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)) diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/CustomerGroupExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/CustomerGroupExampleFactory.php index 31f89d1d2e6c..6f43f3b2b481 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/CustomerGroupExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/CustomerGroupExampleFactory.php @@ -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'])) ; } } diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/OrderExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/OrderExampleFactory.php index a70d0596d593..69a22036f20e 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/OrderExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/OrderExampleFactory.php @@ -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) diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/PaymentMethodExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/PaymentMethodExampleFactory.php index 9599f17cb016..0640d779323f 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/PaymentMethodExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/PaymentMethodExampleFactory.php @@ -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')) diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductAssociationTypeExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductAssociationTypeExampleFactory.php index ac887f037323..fe7abb5868a1 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductAssociationTypeExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductAssociationTypeExampleFactory.php @@ -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'])) ; } diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductAttributeExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductAttributeExampleFactory.php index c882b06cc4f2..8073ce3dca8b 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductAttributeExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductAttributeExampleFactory.php @@ -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)) ; } diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductExampleFactory.php index e54891afec63..2cfadf799db0 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductExampleFactory.php @@ -155,9 +155,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'])) ->setDefault('enabled', true) ->setAllowedTypes('enabled', 'bool') @@ -165,13 +163,9 @@ protected function configureOptions(OptionsResolver $resolver): void ->setDefault('tracked', false) ->setAllowedTypes('tracked', 'bool') - ->setDefault('slug', function (Options $options): string { - return $this->slugGenerator->generate($options['name']); - }) + ->setDefault('slug', fn(Options $options): string => $this->slugGenerator->generate($options['name'])) - ->setDefault('short_description', function (Options $options): string { - return $this->faker->paragraph; - }) + ->setDefault('short_description', fn(Options $options): string => $this->faker->paragraph) ->setDefault('description', function (Options $options): string { /** @var string $paragraphs */ @@ -197,9 +191,7 @@ protected function configureOptions(OptionsResolver $resolver): void ->setDefault('product_attributes', []) ->setAllowedTypes('product_attributes', 'array') - ->setNormalizer('product_attributes', function (Options $options, array $productAttributes): array { - return $this->setAttributeValues($productAttributes); - }) + ->setNormalizer('product_attributes', fn(Options $options, array $productAttributes): array => $this->setAttributeValues($productAttributes)) ->setDefault('product_options', []) ->setAllowedTypes('product_options', 'array') @@ -417,9 +409,7 @@ private function generateProductVariantName(ProductVariantInterface $variant): s { return trim(array_reduce( $variant->getOptionValues()->toArray(), - static function (?string $variantName, ProductOptionValueInterface $variantOption) { - return $variantName . sprintf('%s ', $variantOption->getValue()); - }, + static fn(?string $variantName, ProductOptionValueInterface $variantOption) => $variantName . sprintf('%s ', $variantOption->getValue()), '' )); } diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductOptionExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductOptionExampleFactory.php index 0da6426f6259..b7b991acf238 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductOptionExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductOptionExampleFactory.php @@ -93,9 +93,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'])) ->setDefault('values', null) ->setDefault('values', function (Options $options, ?array $values): array { if (is_array($values)) { diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductReviewExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductReviewExampleFactory.php index 9c958cc8c657..03539aedf67e 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductReviewExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductReviewExampleFactory.php @@ -84,9 +84,7 @@ protected function configureOptions(OptionsResolver $resolver): void return $words; }) - ->setDefault('rating', function (Options $options): int { - return $this->faker->numberBetween(1, 5); - }) + ->setDefault('rating', fn(Options $options): int => $this->faker->numberBetween(1, 5)) ->setDefault('comment', function (Options $options): string { /** @var string $sentences */ $sentences = $this->faker->sentences(3, true); diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/PromotionExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/PromotionExampleFactory.php index 86f0a8159ae8..a29643db902a 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/PromotionExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/PromotionExampleFactory.php @@ -114,9 +114,7 @@ public function create(array $options = []): PromotionInterface protected function configureOptions(OptionsResolver $resolver): void { $resolver - ->setDefault('code', function (Options $options): string { - return StringInflector::nameToCode($options['name']); - }) + ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name'])) ->setDefault('name', $this->faker->words(3, true)) ->setDefault('description', $this->faker->sentence()) ->setDefault('usage_limit', null) diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ShippingCategoryExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ShippingCategoryExampleFactory.php index d2b7623868af..4265e6a6c2cb 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ShippingCategoryExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ShippingCategoryExampleFactory.php @@ -62,12 +62,8 @@ 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->paragraph; - }) + ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name'])) + ->setDefault('description', fn(Options $options): string => $this->faker->paragraph) ; } } diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ShippingMethodExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ShippingMethodExampleFactory.php index f472d77d5fca..9875590cd5c9 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ShippingMethodExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ShippingMethodExampleFactory.php @@ -111,21 +111,15 @@ public function create(array $options = []): ShippingMethodInterface protected function configureOptions(OptionsResolver $resolver): void { $resolver - ->setDefault('code', function (Options $options): string { - return StringInflector::nameToCode($options['name']); - }) + ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name'])) ->setDefault('name', function (Options $options): string { /** @var string $words */ $words = $this->faker->words(3, true); return $words; }) - ->setDefault('description', function (Options $options): string { - return $this->faker->sentence(); - }) - ->setDefault('enabled', function (Options $options): bool { - return $this->faker->boolean(90); - }) + ->setDefault('description', fn(Options $options): string => $this->faker->sentence()) + ->setDefault('enabled', fn(Options $options): bool => $this->faker->boolean(90)) ->setAllowedTypes('enabled', 'bool') ->setDefault('zone', LazyOption::randomOne($this->zoneRepository)) ->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class]) diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ShopUserExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ShopUserExampleFactory.php index 5d406ba431f7..331e58a599f7 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ShopUserExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ShopUserExampleFactory.php @@ -79,15 +79,9 @@ public function create(array $options = []): ShopUserInterface protected function configureOptions(OptionsResolver $resolver): void { $resolver - ->setDefault('email', function (Options $options): string { - return $this->faker->email; - }) - ->setDefault('first_name', function (Options $options): string { - return $this->faker->firstName; - }) - ->setDefault('last_name', function (Options $options): string { - return $this->faker->lastName; - }) + ->setDefault('email', fn(Options $options): string => $this->faker->email) + ->setDefault('first_name', fn(Options $options): string => $this->faker->firstName) + ->setDefault('last_name', fn(Options $options): string => $this->faker->lastName) ->setDefault('enabled', true) ->setAllowedTypes('enabled', 'bool') ->setDefault('password', 'password123') @@ -99,12 +93,8 @@ protected function configureOptions(OptionsResolver $resolver): void 'gender', [CustomerComponent::UNKNOWN_GENDER, CustomerComponent::MALE_GENDER, CustomerComponent::FEMALE_GENDER] ) - ->setDefault('phone_number', function (Options $options): string { - return $this->faker->phoneNumber; - }) - ->setDefault('birthday', function (Options $options): \DateTime { - return $this->faker->dateTimeThisCentury(); - }) + ->setDefault('phone_number', fn(Options $options): string => $this->faker->phoneNumber) + ->setDefault('birthday', fn(Options $options): \DateTime => $this->faker->dateTimeThisCentury()) ->setAllowedTypes('birthday', ['null', 'string', \DateTimeInterface::class]) ->setNormalizer( 'birthday', diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/TaxCategoryExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/TaxCategoryExampleFactory.php index 66dcafce96ef..866a54ad0740 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/TaxCategoryExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/TaxCategoryExampleFactory.php @@ -62,12 +62,8 @@ 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->paragraph; - }) + ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name'])) + ->setDefault('description', fn(Options $options): string => $this->faker->paragraph) ; } } diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/TaxRateExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/TaxRateExampleFactory.php index f071f67ec36d..7715f36c8f8d 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/TaxRateExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/TaxRateExampleFactory.php @@ -73,22 +73,16 @@ public function create(array $options = []): TaxRateInterface protected function configureOptions(OptionsResolver $resolver): void { $resolver - ->setDefault('code', function (Options $options): string { - return StringInflector::nameToCode($options['name']); - }) + ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name'])) ->setDefault('name', function (Options $options): string { /** @var string $words */ $words = $this->faker->words(3, true); return $words; }) - ->setDefault('amount', function (Options $options): float { - return $this->faker->randomFloat(2, 0, 0.4); - }) + ->setDefault('amount', fn(Options $options): float => $this->faker->randomFloat(2, 0, 0.4)) ->setAllowedTypes('amount', 'float') - ->setDefault('included_in_price', function (Options $options): bool { - return $this->faker->boolean(); - }) + ->setDefault('included_in_price', fn(Options $options): bool => $this->faker->boolean()) ->setAllowedTypes('included_in_price', 'bool') ->setDefault('calculator', 'default') ->setDefault('zone', LazyOption::randomOne($this->zoneRepository)) diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/TaxonExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/TaxonExampleFactory.php index cbf6642fbf79..ec3d7970c804 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/TaxonExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/TaxonExampleFactory.php @@ -117,13 +117,9 @@ 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'])) ->setDefault('slug', null) - ->setDefault('description', function (Options $options): string { - return $this->faker->paragraph; - }) + ->setDefault('description', fn(Options $options): string => $this->faker->paragraph) ->setDefault('translations', []) ->setAllowedTypes('translations', ['array']) ->setDefault('children', []) diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/OptionsResolver/LazyOption.php b/src/Sylius/Bundle/CoreBundle/Fixture/OptionsResolver/LazyOption.php index 49072eb6aad5..dbc70c06d368 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/OptionsResolver/LazyOption.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/OptionsResolver/LazyOption.php @@ -95,9 +95,7 @@ public static function randomOnes(RepositoryInterface $repository, int $amount, public static function all(RepositoryInterface $repository): \Closure { - return function (Options $options) use ($repository): iterable { - return $repository->findAll(); - }; + return fn(Options $options): iterable => $repository->findAll(); } public static function findBy(RepositoryInterface $repository, string $field, array $criteria = []): \Closure diff --git a/src/Sylius/Bundle/CoreBundle/Form/DataTransformer/TaxonsToCodesTransformer.php b/src/Sylius/Bundle/CoreBundle/Form/DataTransformer/TaxonsToCodesTransformer.php index fc280fbfbd07..5b0273e83ebf 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/DataTransformer/TaxonsToCodesTransformer.php +++ b/src/Sylius/Bundle/CoreBundle/Form/DataTransformer/TaxonsToCodesTransformer.php @@ -50,8 +50,6 @@ public function reverseTransform($taxons): array { Assert::isInstanceOf($taxons, Collection::class); - return array_map(function (TaxonInterface $taxon) { - return $taxon->getCode(); - }, $taxons->toArray()); + return array_map(fn(TaxonInterface $taxon) => $taxon->getCode(), $taxons->toArray()); } } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Extension/CartTypeExtension.php b/src/Sylius/Bundle/CoreBundle/Form/Extension/CartTypeExtension.php index 39ee8165241d..3742c25fe24b 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Extension/CartTypeExtension.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Extension/CartTypeExtension.php @@ -39,14 +39,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { - $resolver->setNormalizer('validation_groups', function (Options $options, array $validationGroups) { - return function (FormInterface $form) use ($validationGroups) { - if ((bool) $form->get('promotionCoupon')->getNormData()) { // Validate the coupon if it was sent - $validationGroups[] = 'sylius_promotion_coupon'; - } - - return $validationGroups; - }; + $resolver->setNormalizer('validation_groups', fn(Options $options, array $validationGroups) => function (FormInterface $form) use ($validationGroups) { + if ((bool) $form->get('promotionCoupon')->getNormData()) { // Validate the coupon if it was sent + $validationGroups[] = 'sylius_promotion_coupon'; + } + + return $validationGroups; }); } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Extension/ProductVariantGenerationTypeExtension.php b/src/Sylius/Bundle/CoreBundle/Form/Extension/ProductVariantGenerationTypeExtension.php index d855a8cd8c58..2123e443746b 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Extension/ProductVariantGenerationTypeExtension.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Extension/ProductVariantGenerationTypeExtension.php @@ -31,12 +31,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $event->getForm()->add('channelPricings', ChannelCollectionType::class, [ 'entry_type' => ChannelPricingType::class, - 'entry_options' => function (ChannelInterface $channel) use ($productVariant) { - return [ - 'channel' => $channel, - 'product_variant' => $productVariant, - ]; - }, + 'entry_options' => fn(ChannelInterface $channel) => [ + 'channel' => $channel, + 'product_variant' => $productVariant, + ], 'label' => 'sylius.form.variant.price', ]); }); diff --git a/src/Sylius/Bundle/CoreBundle/Form/Extension/ProductVariantTypeExtension.php b/src/Sylius/Bundle/CoreBundle/Form/Extension/ProductVariantTypeExtension.php index 699f76a48b3b..4a2d10070eb3 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Extension/ProductVariantTypeExtension.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Extension/ProductVariantTypeExtension.php @@ -81,13 +81,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $event->getForm()->add('channelPricings', ChannelCollectionType::class, [ 'entry_type' => ChannelPricingType::class, - 'entry_options' => function (ChannelInterface $channel) use ($productVariant) { - return [ - 'channel' => $channel, - 'product_variant' => $productVariant, - 'required' => false, - ]; - }, + 'entry_options' => fn(ChannelInterface $channel) => [ + 'channel' => $channel, + 'product_variant' => $productVariant, + 'required' => false, + ], 'label' => 'sylius.form.variant.price', ]); }); diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/AmountType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/AmountType.php index 596ae88877c0..630f376068f5 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/AmountType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/AmountType.php @@ -47,9 +47,7 @@ public function configureOptions(OptionsResolver $resolver): void ->setAllowedTypes('channel', [ChannelInterface::class]) ->setDefaults([ - 'label' => static function (Options $options): string { - return $options['channel']->getName(); - }, + 'label' => static fn(Options $options): string => $options['channel']->getName(), ]) ; } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/ChannelCollectionType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/ChannelCollectionType.php index 3c49b0df08a8..e8eaab222551 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/ChannelCollectionType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/ChannelCollectionType.php @@ -32,9 +32,7 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'entries' => $this->channelRepository->findAll(), - 'entry_name' => function (ChannelInterface $channel) { - return $channel->getCode(); - }, + 'entry_name' => fn(ChannelInterface $channel) => $channel->getCode(), 'error_bubbling' => false, ]); } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Product/ChannelPricingType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Product/ChannelPricingType.php index e1b86c94f3e6..e118ca49dfbb 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Product/ChannelPricingType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Product/ChannelPricingType.php @@ -91,9 +91,7 @@ public function configureOptions(OptionsResolver $resolver): void ->setAllowedTypes('product_variant', ['null', ProductVariantInterface::class]) ->setDefaults([ - 'label' => function (Options $options): string { - return $options['channel']->getName(); - }, + 'label' => fn(Options $options): string => $options['channel']->getName(), ]) ; } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Action/ChannelBasedFixedDiscountConfigurationType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Action/ChannelBasedFixedDiscountConfigurationType.php index dcf95598a80b..c65a5fb5328b 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Action/ChannelBasedFixedDiscountConfigurationType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Action/ChannelBasedFixedDiscountConfigurationType.php @@ -25,12 +25,10 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'entry_type' => FixedDiscountConfigurationType::class, - 'entry_options' => function (ChannelInterface $channel) { - return [ - 'label' => $channel->getName(), - 'currency' => $channel->getBaseCurrency()->getCode(), - ]; - }, + 'entry_options' => fn(ChannelInterface $channel) => [ + 'label' => $channel->getName(), + 'currency' => $channel->getBaseCurrency()->getCode(), + ], ]); } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Action/ChannelBasedUnitFixedDiscountConfigurationType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Action/ChannelBasedUnitFixedDiscountConfigurationType.php index 7daa5a7bfa2a..e75a29e47442 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Action/ChannelBasedUnitFixedDiscountConfigurationType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Action/ChannelBasedUnitFixedDiscountConfigurationType.php @@ -25,12 +25,10 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'entry_type' => UnitFixedDiscountConfigurationType::class, - 'entry_options' => function (ChannelInterface $channel) { - return [ - 'label' => $channel->getName(), - 'currency' => $channel->getBaseCurrency()->getCode(), - ]; - }, + 'entry_options' => fn(ChannelInterface $channel) => [ + 'label' => $channel->getName(), + 'currency' => $channel->getBaseCurrency()->getCode(), + ], ]); } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Action/ChannelBasedUnitPercentageDiscountConfigurationType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Action/ChannelBasedUnitPercentageDiscountConfigurationType.php index ecf9e112656c..8805e1bb1d29 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Action/ChannelBasedUnitPercentageDiscountConfigurationType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Action/ChannelBasedUnitPercentageDiscountConfigurationType.php @@ -25,12 +25,10 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'entry_type' => UnitPercentageDiscountConfigurationType::class, - 'entry_options' => function (ChannelInterface $channel) { - return [ - 'label' => $channel->getName(), - 'currency' => $channel->getBaseCurrency()->getCode(), - ]; - }, + 'entry_options' => fn(ChannelInterface $channel) => [ + 'label' => $channel->getName(), + 'currency' => $channel->getBaseCurrency()->getCode(), + ], ]); } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/ChannelBasedItemTotalConfigurationType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/ChannelBasedItemTotalConfigurationType.php index 58ec4d6d8d15..933e63b0686c 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/ChannelBasedItemTotalConfigurationType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/ChannelBasedItemTotalConfigurationType.php @@ -25,12 +25,10 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'entry_type' => ItemTotalConfigurationType::class, - 'entry_options' => function (ChannelInterface $channel) { - return [ - 'label' => $channel->getName(), - 'currency' => $channel->getBaseCurrency()->getCode(), - ]; - }, + 'entry_options' => fn(ChannelInterface $channel) => [ + 'label' => $channel->getName(), + 'currency' => $channel->getBaseCurrency()->getCode(), + ], ]); } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/ChannelBasedTotalOfItemsFromTaxonConfigurationType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/ChannelBasedTotalOfItemsFromTaxonConfigurationType.php index 420a54b607d5..56b44ab47e7a 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/ChannelBasedTotalOfItemsFromTaxonConfigurationType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/ChannelBasedTotalOfItemsFromTaxonConfigurationType.php @@ -24,12 +24,10 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'entry_type' => TotalOfItemsFromTaxonConfigurationType::class, - 'entry_options' => function (ChannelInterface $channel): array { - return [ - 'label' => $channel->getName(), - 'currency' => $channel->getBaseCurrency()->getCode(), - ]; - }, + 'entry_options' => fn(ChannelInterface $channel): array => [ + 'label' => $channel->getName(), + 'currency' => $channel->getBaseCurrency()->getCode(), + ], ]); } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Calculator/ChannelBasedFlatRateConfigurationType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Calculator/ChannelBasedFlatRateConfigurationType.php index b189caf66843..b26df4db2921 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Calculator/ChannelBasedFlatRateConfigurationType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Calculator/ChannelBasedFlatRateConfigurationType.php @@ -25,12 +25,10 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'entry_type' => FlatRateConfigurationType::class, - 'entry_options' => function (ChannelInterface $channel): array { - return [ - 'label' => $channel->getName(), - 'currency' => $channel->getBaseCurrency()->getCode(), - ]; - }, + 'entry_options' => fn(ChannelInterface $channel): array => [ + 'label' => $channel->getName(), + 'currency' => $channel->getBaseCurrency()->getCode(), + ], ]); } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Calculator/ChannelBasedPerUnitRateConfigurationType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Calculator/ChannelBasedPerUnitRateConfigurationType.php index 96a109284c37..6f904793e78f 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Calculator/ChannelBasedPerUnitRateConfigurationType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Calculator/ChannelBasedPerUnitRateConfigurationType.php @@ -25,12 +25,10 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'entry_type' => PerUnitRateConfigurationType::class, - 'entry_options' => function (ChannelInterface $channel): array { - return [ - 'label' => $channel->getName(), - 'currency' => $channel->getBaseCurrency()->getCode(), - ]; - }, + 'entry_options' => fn(ChannelInterface $channel): array => [ + 'label' => $channel->getName(), + 'currency' => $channel->getBaseCurrency()->getCode(), + ], ]); } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Rule/ChannelBasedOrderTotalGreaterThanOrEqualConfigurationType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Rule/ChannelBasedOrderTotalGreaterThanOrEqualConfigurationType.php index 4af4fe696489..99853ce87f81 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Rule/ChannelBasedOrderTotalGreaterThanOrEqualConfigurationType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Rule/ChannelBasedOrderTotalGreaterThanOrEqualConfigurationType.php @@ -24,12 +24,10 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'entry_type' => OrderTotalGreaterThanOrEqualConfigurationType::class, - 'entry_options' => function (ChannelInterface $channel): array { - return [ - 'label' => $channel->getName(), - 'currency' => $channel->getBaseCurrency()->getCode(), - ]; - }, + 'entry_options' => fn(ChannelInterface $channel): array => [ + 'label' => $channel->getName(), + 'currency' => $channel->getBaseCurrency()->getCode(), + ], ]); } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Rule/ChannelBasedOrderTotalLessThanOrEqualConfigurationType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Rule/ChannelBasedOrderTotalLessThanOrEqualConfigurationType.php index 581b33f27f76..fc622b8ed4f2 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Rule/ChannelBasedOrderTotalLessThanOrEqualConfigurationType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Shipping/Rule/ChannelBasedOrderTotalLessThanOrEqualConfigurationType.php @@ -24,12 +24,10 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'entry_type' => OrderTotalLessThanOrEqualConfigurationType::class, - 'entry_options' => function (ChannelInterface $channel): array { - return [ - 'label' => $channel->getName(), - 'currency' => $channel->getBaseCurrency()->getCode(), - ]; - }, + 'entry_options' => fn(ChannelInterface $channel): array => [ + 'label' => $channel->getName(), + 'currency' => $channel->getBaseCurrency()->getCode(), + ], ]); } diff --git a/src/Sylius/Bundle/CoreBundle/Security/UserImpersonator.php b/src/Sylius/Bundle/CoreBundle/Security/UserImpersonator.php index 9fcce049727f..13c2c97f947d 100644 --- a/src/Sylius/Bundle/CoreBundle/Security/UserImpersonator.php +++ b/src/Sylius/Bundle/CoreBundle/Security/UserImpersonator.php @@ -45,14 +45,14 @@ public function impersonate(UserInterface $user): void $token = new UsernamePasswordToken( $user, $this->firewallContextName, - array_map(/** @param object|string $role */ static function ($role): string { return (string) $role; }, $user->getRoles()) + array_map(/** @param object|string $role */ static fn($role): string => (string) $role, $user->getRoles()) ); } else { $token = new UsernamePasswordToken( $user, $user->getPassword(), $this->firewallContextName, - array_map(/** @param object|string $role */ static function ($role): string { return (string) $role; }, $user->getRoles()) + array_map(/** @param object|string $role */ static fn($role): string => (string) $role, $user->getRoles()) ); } diff --git a/src/Sylius/Bundle/CurrencyBundle/Form/Type/CurrencyChoiceType.php b/src/Sylius/Bundle/CurrencyBundle/Form/Type/CurrencyChoiceType.php index b989bd028a57..f946b06ee020 100644 --- a/src/Sylius/Bundle/CurrencyBundle/Form/Type/CurrencyChoiceType.php +++ b/src/Sylius/Bundle/CurrencyBundle/Form/Type/CurrencyChoiceType.php @@ -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->currencyRepository->findAll(); - }, + 'choices' => fn(Options $options): array => $this->currencyRepository->findAll(), 'choice_value' => 'code', 'choice_label' => 'name', 'choice_translation_domain' => false, diff --git a/src/Sylius/Bundle/CurrencyBundle/test/src/Tests/SyliusCurrencyBundleTest.php b/src/Sylius/Bundle/CurrencyBundle/test/src/Tests/SyliusCurrencyBundleTest.php index d0a08792fec1..3c86a00646ea 100644 --- a/src/Sylius/Bundle/CurrencyBundle/test/src/Tests/SyliusCurrencyBundleTest.php +++ b/src/Sylius/Bundle/CurrencyBundle/test/src/Tests/SyliusCurrencyBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerChoiceType.php b/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerChoiceType.php index 7cb7ff5d27dd..30631c67772e 100644 --- a/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerChoiceType.php +++ b/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerChoiceType.php @@ -41,13 +41,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'choices' => function (Options $options): array { - return $this->customerRepository->findAll(); - }, + 'choices' => fn(Options $options): array => $this->customerRepository->findAll(), 'choice_value' => 'email', - 'choice_label' => function (CustomerInterface $customer): string { - return sprintf('%s (%s)', $customer->getFullName(), $customer->getEmail()); - }, + 'choice_label' => fn(CustomerInterface $customer): string => sprintf('%s (%s)', $customer->getFullName(), $customer->getEmail()), 'choice_translation_domain' => false, ]); } diff --git a/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerGroupChoiceType.php b/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerGroupChoiceType.php index ed1c17151a50..6f1e6427c285 100644 --- a/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerGroupChoiceType.php +++ b/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerGroupChoiceType.php @@ -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->customerGroupRepository->findAll(); - }, + 'choices' => fn(Options $options): array => $this->customerGroupRepository->findAll(), 'choice_value' => 'code', 'choice_label' => 'name', 'choice_translation_domain' => false, diff --git a/src/Sylius/Bundle/CustomerBundle/test/src/Tests/SyliusCustomerBundleTest.php b/src/Sylius/Bundle/CustomerBundle/test/src/Tests/SyliusCustomerBundleTest.php index 47d6f16c1cbf..22d63d986eeb 100644 --- a/src/Sylius/Bundle/CustomerBundle/test/src/Tests/SyliusCustomerBundleTest.php +++ b/src/Sylius/Bundle/CustomerBundle/test/src/Tests/SyliusCustomerBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/InventoryBundle/test/src/Tests/SyliusInventoryBundleTest.php b/src/Sylius/Bundle/InventoryBundle/test/src/Tests/SyliusInventoryBundleTest.php index 614afee8d641..acf95a6539e9 100644 --- a/src/Sylius/Bundle/InventoryBundle/test/src/Tests/SyliusInventoryBundleTest.php +++ b/src/Sylius/Bundle/InventoryBundle/test/src/Tests/SyliusInventoryBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/LocaleBundle/test/src/Tests/SyliusLocaleBundleTest.php b/src/Sylius/Bundle/LocaleBundle/test/src/Tests/SyliusLocaleBundleTest.php index 32d018fcd734..9cda6dd1200f 100644 --- a/src/Sylius/Bundle/LocaleBundle/test/src/Tests/SyliusLocaleBundleTest.php +++ b/src/Sylius/Bundle/LocaleBundle/test/src/Tests/SyliusLocaleBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/MoneyBundle/test/src/Tests/SyliusMoneyBundleTest.php b/src/Sylius/Bundle/MoneyBundle/test/src/Tests/SyliusMoneyBundleTest.php index b6ab70edabc3..50cea2da0dd5 100644 --- a/src/Sylius/Bundle/MoneyBundle/test/src/Tests/SyliusMoneyBundleTest.php +++ b/src/Sylius/Bundle/MoneyBundle/test/src/Tests/SyliusMoneyBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/OrderBundle/test/src/Tests/SyliusOrderBundleTest.php b/src/Sylius/Bundle/OrderBundle/test/src/Tests/SyliusOrderBundleTest.php index eed719a56953..a1271845307d 100644 --- a/src/Sylius/Bundle/OrderBundle/test/src/Tests/SyliusOrderBundleTest.php +++ b/src/Sylius/Bundle/OrderBundle/test/src/Tests/SyliusOrderBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/PaymentBundle/test/src/Tests/SyliusPaymentBundleTest.php b/src/Sylius/Bundle/PaymentBundle/test/src/Tests/SyliusPaymentBundleTest.php index 378a194d7c62..69adefe2efbb 100644 --- a/src/Sylius/Bundle/PaymentBundle/test/src/Tests/SyliusPaymentBundleTest.php +++ b/src/Sylius/Bundle/PaymentBundle/test/src/Tests/SyliusPaymentBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/PayumBundle/DependencyInjection/Compiler/RegisterGatewayConfigTypePass.php b/src/Sylius/Bundle/PayumBundle/DependencyInjection/Compiler/RegisterGatewayConfigTypePass.php index f08010d18887..82e618c8529b 100644 --- a/src/Sylius/Bundle/PayumBundle/DependencyInjection/Compiler/RegisterGatewayConfigTypePass.php +++ b/src/Sylius/Bundle/PayumBundle/DependencyInjection/Compiler/RegisterGatewayConfigTypePass.php @@ -48,9 +48,7 @@ public function process(ContainerBuilder $container): void } } - usort($gatewayFactories, function (array $firstGateway, array $secondGateway): int { - return $secondGateway['priority'] - $firstGateway['priority']; - }); + usort($gatewayFactories, fn(array $firstGateway, array $secondGateway): int => $secondGateway['priority'] - $firstGateway['priority']); $sortedGatewayFactories = []; foreach ($gatewayFactories as $key => $factory) { diff --git a/src/Sylius/Bundle/ProductBundle/Form/DataTransformer/ProductVariantToProductOptionsTransformer.php b/src/Sylius/Bundle/ProductBundle/Form/DataTransformer/ProductVariantToProductOptionsTransformer.php index e9d2df5e3c80..eb1a1d94f065 100644 --- a/src/Sylius/Bundle/ProductBundle/Form/DataTransformer/ProductVariantToProductOptionsTransformer.php +++ b/src/Sylius/Bundle/ProductBundle/Form/DataTransformer/ProductVariantToProductOptionsTransformer.php @@ -44,9 +44,7 @@ public function transform($value): array return array_combine( array_map( - function (ProductOptionValueInterface $productOptionValue): string { - return (string) $productOptionValue->getOptionCode(); - }, + fn(ProductOptionValueInterface $productOptionValue): string => (string) $productOptionValue->getOptionCode(), $value->getOptionValues()->toArray() ), $value->getOptionValues()->toArray() diff --git a/src/Sylius/Bundle/ProductBundle/Form/EventSubscriber/BuildAttributesFormSubscriber.php b/src/Sylius/Bundle/ProductBundle/Form/EventSubscriber/BuildAttributesFormSubscriber.php index c30c5a56a8bb..30b2cad65242 100644 --- a/src/Sylius/Bundle/ProductBundle/Form/EventSubscriber/BuildAttributesFormSubscriber.php +++ b/src/Sylius/Bundle/ProductBundle/Form/EventSubscriber/BuildAttributesFormSubscriber.php @@ -59,9 +59,7 @@ public function preSetData(FormEvent $event): void $defaultLocaleCode = $this->localeProvider->getDefaultLocaleCode(); $attributes = $product->getAttributes()->filter( - function (ProductAttributeValueInterface $attribute) use ($defaultLocaleCode) { - return $attribute->getLocaleCode() === $defaultLocaleCode; - } + fn(ProductAttributeValueInterface $attribute) => $attribute->getLocaleCode() === $defaultLocaleCode ); /** @var ProductAttributeValueInterface $attribute */ diff --git a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductAssociationTypeChoiceType.php b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductAssociationTypeChoiceType.php index 374f05925e91..e216a11d450f 100644 --- a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductAssociationTypeChoiceType.php +++ b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductAssociationTypeChoiceType.php @@ -40,9 +40,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'choices' => function (Options $options) { - return $this->productAssociationTypeRepository->findAll(); - }, + 'choices' => fn(Options $options) => $this->productAssociationTypeRepository->findAll(), 'choice_value' => 'code', 'choice_label' => 'name', 'choice_translation_domain' => false, diff --git a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductAssociationsType.php b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductAssociationsType.php index cbfbab0d86c4..45b2dd4d9467 100644 --- a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductAssociationsType.php +++ b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductAssociationsType.php @@ -46,14 +46,10 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setDefaults([ 'entries' => $this->productAssociationTypeRepository->findAll(), 'entry_type' => TextType::class, - 'entry_name' => function (ProductAssociationTypeInterface $productAssociationType) { - return $productAssociationType->getCode(); - }, - 'entry_options' => function (ProductAssociationTypeInterface $productAssociationType) { - return [ - 'label' => $productAssociationType->getName(), - ]; - }, + 'entry_name' => fn(ProductAssociationTypeInterface $productAssociationType) => $productAssociationType->getCode(), + 'entry_options' => fn(ProductAssociationTypeInterface $productAssociationType) => [ + 'label' => $productAssociationType->getName(), + ], ]); } diff --git a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductChoiceType.php b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductChoiceType.php index a76e9b8e18f5..5756c3050f83 100644 --- a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductChoiceType.php +++ b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductChoiceType.php @@ -40,9 +40,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'choices' => function (Options $options) { - return $this->productRepository->findAll(); - }, + 'choices' => fn(Options $options) => $this->productRepository->findAll(), 'choice_value' => 'code', 'choice_label' => 'name', 'choice_translation_domain' => false, diff --git a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductOptionChoiceType.php b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductOptionChoiceType.php index af84273bb53d..27ab230b76bc 100644 --- a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductOptionChoiceType.php +++ b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductOptionChoiceType.php @@ -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->productOptionRepository->findAll(); - }, + 'choices' => fn(Options $options): array => $this->productOptionRepository->findAll(), 'choice_value' => 'code', 'choice_label' => 'name', 'choice_translation_domain' => false, diff --git a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductVariantChoiceType.php b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductVariantChoiceType.php index 48dc68f82db8..82edb1ccc7f4 100644 --- a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductVariantChoiceType.php +++ b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductVariantChoiceType.php @@ -35,14 +35,9 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver ->setDefaults([ - 'choices' => function (Options $options): iterable { - return $options['product']->getVariants(); - }, + 'choices' => fn(Options $options): iterable => $options['product']->getVariants(), 'choice_value' => 'code', - 'choice_label' => function (ProductVariantInterface $variant): string { - /** @psalm-suppress InvalidCast */ - return (string) $variant; - }, + 'choice_label' => fn(ProductVariantInterface $variant): string => (string) $variant, 'choice_translation_domain' => false, 'multiple' => false, 'expanded' => true, diff --git a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductVariantMatchType.php b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductVariantMatchType.php index 8bf7abc15f90..4cb3fff17dd1 100644 --- a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductVariantMatchType.php +++ b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductVariantMatchType.php @@ -40,19 +40,13 @@ public function configureOptions(OptionsResolver $resolver): void return $product->getOptions(); }, 'entry_type' => ProductOptionValueChoiceType::class, - 'entry_name' => function (ProductOptionInterface $productOption) { - return $productOption->getCode(); - }, - 'entry_options' => function (Options $options) { - return function (ProductOptionInterface $productOption) use ($options) { - return [ - 'label' => $productOption->getName(), - 'option' => $productOption, - 'only_available_values' => true, - 'product' => $options['product'], - ]; - }; - }, + 'entry_name' => fn(ProductOptionInterface $productOption) => $productOption->getCode(), + 'entry_options' => fn(Options $options) => fn(ProductOptionInterface $productOption) => [ + 'label' => $productOption->getName(), + 'option' => $productOption, + 'only_available_values' => true, + 'product' => $options['product'], + ], ]) ->setRequired('product') diff --git a/src/Sylius/Bundle/ProductBundle/test/src/Tests/SyliusProductBundleTest.php b/src/Sylius/Bundle/ProductBundle/test/src/Tests/SyliusProductBundleTest.php index 7dba6d4c6866..81f59ca93cef 100644 --- a/src/Sylius/Bundle/ProductBundle/test/src/Tests/SyliusProductBundleTest.php +++ b/src/Sylius/Bundle/ProductBundle/test/src/Tests/SyliusProductBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/PromotionBundle/DependencyInjection/Compiler/CompositePromotionCouponEligibilityCheckerPass.php b/src/Sylius/Bundle/PromotionBundle/DependencyInjection/Compiler/CompositePromotionCouponEligibilityCheckerPass.php index 080938f38e8f..93a4ff81f24b 100644 --- a/src/Sylius/Bundle/PromotionBundle/DependencyInjection/Compiler/CompositePromotionCouponEligibilityCheckerPass.php +++ b/src/Sylius/Bundle/PromotionBundle/DependencyInjection/Compiler/CompositePromotionCouponEligibilityCheckerPass.php @@ -27,9 +27,7 @@ public function process(ContainerBuilder $container): void $container->getDefinition('sylius.promotion_coupon_eligibility_checker')->setArguments([ array_map( - function ($id) { - return new Reference($id); - }, + fn($id) => new Reference($id), array_keys($container->findTaggedServiceIds('sylius.promotion_coupon_eligibility_checker')) ), ]); diff --git a/src/Sylius/Bundle/PromotionBundle/DependencyInjection/Compiler/CompositePromotionEligibilityCheckerPass.php b/src/Sylius/Bundle/PromotionBundle/DependencyInjection/Compiler/CompositePromotionEligibilityCheckerPass.php index 5f612ec5c0ab..fb8212e5043f 100644 --- a/src/Sylius/Bundle/PromotionBundle/DependencyInjection/Compiler/CompositePromotionEligibilityCheckerPass.php +++ b/src/Sylius/Bundle/PromotionBundle/DependencyInjection/Compiler/CompositePromotionEligibilityCheckerPass.php @@ -27,9 +27,7 @@ public function process(ContainerBuilder $container): void $container->getDefinition('sylius.promotion_eligibility_checker')->setArguments([ array_map( - function ($id) { - return new Reference($id); - }, + fn($id) => new Reference($id), array_keys($container->findTaggedServiceIds('sylius.promotion_eligibility_checker')) ), ]); diff --git a/src/Sylius/Bundle/PromotionBundle/test/src/Tests/SyliusPromotionBundleTest.php b/src/Sylius/Bundle/PromotionBundle/test/src/Tests/SyliusPromotionBundleTest.php index 34b5f339b26b..3ffed0e79773 100644 --- a/src/Sylius/Bundle/PromotionBundle/test/src/Tests/SyliusPromotionBundleTest.php +++ b/src/Sylius/Bundle/PromotionBundle/test/src/Tests/SyliusPromotionBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/ReviewBundle/test/src/Tests/SyliusReviewBundleTest.php b/src/Sylius/Bundle/ReviewBundle/test/src/Tests/SyliusReviewBundleTest.php index 9447627b060c..facaa5e35165 100644 --- a/src/Sylius/Bundle/ReviewBundle/test/src/Tests/SyliusReviewBundleTest.php +++ b/src/Sylius/Bundle/ReviewBundle/test/src/Tests/SyliusReviewBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/ShippingBundle/DependencyInjection/Compiler/CompositeShippingMethodEligibilityCheckerPass.php b/src/Sylius/Bundle/ShippingBundle/DependencyInjection/Compiler/CompositeShippingMethodEligibilityCheckerPass.php index 2218b2a7ec24..5df596a4acb9 100644 --- a/src/Sylius/Bundle/ShippingBundle/DependencyInjection/Compiler/CompositeShippingMethodEligibilityCheckerPass.php +++ b/src/Sylius/Bundle/ShippingBundle/DependencyInjection/Compiler/CompositeShippingMethodEligibilityCheckerPass.php @@ -27,9 +27,7 @@ public function process(ContainerBuilder $container): void $container->getDefinition('sylius.shipping_method_eligibility_checker')->setArguments([ array_map( - static function ($id): Reference { - return new Reference($id); - }, + static fn($id): Reference => new Reference($id), array_keys($container->findTaggedServiceIds('sylius.shipping_method_eligibility_checker')) ), ]); diff --git a/src/Sylius/Bundle/ShippingBundle/Form/Type/ShippingCategoryChoiceType.php b/src/Sylius/Bundle/ShippingBundle/Form/Type/ShippingCategoryChoiceType.php index 12e1979bc211..ea0ea931381f 100644 --- a/src/Sylius/Bundle/ShippingBundle/Form/Type/ShippingCategoryChoiceType.php +++ b/src/Sylius/Bundle/ShippingBundle/Form/Type/ShippingCategoryChoiceType.php @@ -40,9 +40,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'choices' => function (Options $options) { - return $this->shippingCategoryRepository->findAll(); - }, + 'choices' => fn(Options $options) => $this->shippingCategoryRepository->findAll(), 'choice_value' => 'code', 'choice_label' => 'name', 'choice_translation_domain' => false, diff --git a/src/Sylius/Bundle/ShippingBundle/test/src/Tests/SyliusShippingBundleTest.php b/src/Sylius/Bundle/ShippingBundle/test/src/Tests/SyliusShippingBundleTest.php index 2497151967fa..63e8f44821d8 100644 --- a/src/Sylius/Bundle/ShippingBundle/test/src/Tests/SyliusShippingBundleTest.php +++ b/src/Sylius/Bundle/ShippingBundle/test/src/Tests/SyliusShippingBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/ShopBundle/Calculator/OrderItemsSubtotalCalculator.php b/src/Sylius/Bundle/ShopBundle/Calculator/OrderItemsSubtotalCalculator.php index 95b108d96efb..bb0c92c2e3f4 100644 --- a/src/Sylius/Bundle/ShopBundle/Calculator/OrderItemsSubtotalCalculator.php +++ b/src/Sylius/Bundle/ShopBundle/Calculator/OrderItemsSubtotalCalculator.php @@ -22,9 +22,7 @@ public function getSubtotal(OrderInterface $order): int { return array_reduce( $order->getItems()->toArray(), - static function (int $subtotal, OrderItemInterface $item): int { - return $subtotal + $item->getSubtotal(); - }, + static fn(int $subtotal, OrderItemInterface $item): int => $subtotal + $item->getSubtotal(), 0 ); } diff --git a/src/Sylius/Bundle/ShopBundle/Controller/CurrencySwitchController.php b/src/Sylius/Bundle/ShopBundle/Controller/CurrencySwitchController.php index dedef5a24a21..5127c2c6a444 100644 --- a/src/Sylius/Bundle/ShopBundle/Controller/CurrencySwitchController.php +++ b/src/Sylius/Bundle/ShopBundle/Controller/CurrencySwitchController.php @@ -59,9 +59,7 @@ public function renderAction(): Response $channel = $this->channelContext->getChannel(); $availableCurrencies = array_map( - function (CurrencyInterface $currency) { - return $currency->getCode(); - }, + fn(CurrencyInterface $currency) => $currency->getCode(), $channel->getCurrencies()->toArray() ); diff --git a/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php index 3600173cfd70..f788743cf215 100644 --- a/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php @@ -40,9 +40,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->validate() ->ifTrue( /** @param mixed $pattern */ - function ($pattern) { - return !is_string($pattern); - } + fn($pattern) => !is_string($pattern) ) ->thenInvalid('Invalid pattern "%s"') ->end() diff --git a/src/Sylius/Bundle/ShopBundle/Twig/OrderTaxesTotalExtension.php b/src/Sylius/Bundle/ShopBundle/Twig/OrderTaxesTotalExtension.php index 1f3fad12bf38..555dc8107199 100644 --- a/src/Sylius/Bundle/ShopBundle/Twig/OrderTaxesTotalExtension.php +++ b/src/Sylius/Bundle/ShopBundle/Twig/OrderTaxesTotalExtension.php @@ -43,9 +43,7 @@ private function getAmount(OrderInterface $order, bool $isNeutral): int { return array_reduce( $order->getAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->toArray(), - static function (int $total, BaseAdjustmentInterface $adjustment) use ($isNeutral) { - return $isNeutral === $adjustment->isNeutral() ? $total + $adjustment->getAmount() : $total; - }, + static fn(int $total, BaseAdjustmentInterface $adjustment) => $isNeutral === $adjustment->isNeutral() ? $total + $adjustment->getAmount() : $total, 0 ); } diff --git a/src/Sylius/Bundle/TaxationBundle/Form/Type/TaxCategoryChoiceType.php b/src/Sylius/Bundle/TaxationBundle/Form/Type/TaxCategoryChoiceType.php index eb6af43b007b..d2f8f311c309 100644 --- a/src/Sylius/Bundle/TaxationBundle/Form/Type/TaxCategoryChoiceType.php +++ b/src/Sylius/Bundle/TaxationBundle/Form/Type/TaxCategoryChoiceType.php @@ -40,9 +40,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'choices' => function (Options $options) { - return $this->taxCategoryRepository->findAll(); - }, + 'choices' => fn(Options $options) => $this->taxCategoryRepository->findAll(), 'choice_value' => 'code', 'choice_label' => 'name', 'choice_translation_domain' => false, diff --git a/src/Sylius/Bundle/TaxationBundle/test/src/Tests/SyliusTaxationBundleTest.php b/src/Sylius/Bundle/TaxationBundle/test/src/Tests/SyliusTaxationBundleTest.php index cd95df045df7..8fb87d9d1241 100644 --- a/src/Sylius/Bundle/TaxationBundle/test/src/Tests/SyliusTaxationBundleTest.php +++ b/src/Sylius/Bundle/TaxationBundle/test/src/Tests/SyliusTaxationBundleTest.php @@ -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)); diff --git a/src/Sylius/Bundle/TaxonomyBundle/Tests/Functional/SyliusTaxonomyBundleTest.php b/src/Sylius/Bundle/TaxonomyBundle/Tests/Functional/SyliusTaxonomyBundleTest.php index d1e5f1baa2c8..f8b72fbec2ea 100644 --- a/src/Sylius/Bundle/TaxonomyBundle/Tests/Functional/SyliusTaxonomyBundleTest.php +++ b/src/Sylius/Bundle/TaxonomyBundle/Tests/Functional/SyliusTaxonomyBundleTest.php @@ -30,9 +30,7 @@ public function its_services_are_initializable() /** @var Container $container */ $container = self::$kernel->getContainer(); - $serviceIds = array_filter($container->getServiceIds(), function (string $serviceId): bool { - return 0 === strpos($serviceId, 'sylius.'); - }); + $serviceIds = array_filter($container->getServiceIds(), fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.')); foreach ($serviceIds as $id) { Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); diff --git a/src/Sylius/Bundle/UiBundle/Command/DebugTemplateEventCommand.php b/src/Sylius/Bundle/UiBundle/Command/DebugTemplateEventCommand.php index 748a90fceba1..d0a3c405efdd 100644 --- a/src/Sylius/Bundle/UiBundle/Command/DebugTemplateEventCommand.php +++ b/src/Sylius/Bundle/UiBundle/Command/DebugTemplateEventCommand.php @@ -63,14 +63,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->table( ['Block name', 'Template', 'Priority', 'Enabled'], array_map( - static function (TemplateBlock $templateBlock): array { - return [ - $templateBlock->getName(), - $templateBlock->getTemplate(), - $templateBlock->getPriority(), - $templateBlock->isEnabled() ? 'TRUE' : 'FALSE', - ]; - }, + static fn(TemplateBlock $templateBlock): array => [ + $templateBlock->getName(), + $templateBlock->getTemplate(), + $templateBlock->getPriority(), + $templateBlock->isEnabled() ? 'TRUE' : 'FALSE', + ], $this->templateBlockRegistry->all()[$eventName] ?? [] ) ); diff --git a/src/Sylius/Bundle/UiBundle/DataCollector/TemplateBlockDataCollector.php b/src/Sylius/Bundle/UiBundle/DataCollector/TemplateBlockDataCollector.php index 9cd052df6d0d..a732fec5b1e0 100644 --- a/src/Sylius/Bundle/UiBundle/DataCollector/TemplateBlockDataCollector.php +++ b/src/Sylius/Bundle/UiBundle/DataCollector/TemplateBlockDataCollector.php @@ -48,16 +48,12 @@ public function getNumberOfRenderedEvents(): int public function getNumberOfRenderedBlocks(): int { - return array_reduce($this->data['renderedEvents'], static function (int $accumulator, array $event): int { - return $accumulator + count($event['blocks']); - }, 0); + return array_reduce($this->data['renderedEvents'], static fn(int $accumulator, array $event): int => $accumulator + count($event['blocks']), 0); } public function getTotalDuration(): float { - return array_reduce($this->data['renderedEvents'], static function (float $accumulator, array $event): float { - return $accumulator + $event['time']; - }, 0.0); + return array_reduce($this->data['renderedEvents'], static fn(float $accumulator, array $event): float => $accumulator + $event['time'], 0.0); } public function getName(): string diff --git a/src/Sylius/Bundle/UiBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/UiBundle/DependencyInjection/Configuration.php index 1f1aa7453ad3..ffb17b4f38f3 100644 --- a/src/Sylius/Bundle/UiBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/UiBundle/DependencyInjection/Configuration.php @@ -40,9 +40,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->canBeDisabled() ->beforeNormalization() ->ifString() - ->then(static function (?string $template): array { - return ['template' => $template]; - }) + ->then(static fn(?string $template): array => ['template' => $template]) ->end() ->children() ->booleanNode('enabled')->defaultNull()->end() diff --git a/src/Sylius/Bundle/UiBundle/Registry/TemplateBlockRegistry.php b/src/Sylius/Bundle/UiBundle/Registry/TemplateBlockRegistry.php index e513607d6cce..6efda450bf1c 100644 --- a/src/Sylius/Bundle/UiBundle/Registry/TemplateBlockRegistry.php +++ b/src/Sylius/Bundle/UiBundle/Registry/TemplateBlockRegistry.php @@ -46,17 +46,13 @@ public function findEnabledForEvents(array $eventNames): array return array_values(array_filter( $this->eventsToTemplateBlocks[$eventName] ?? [], - static function (TemplateBlock $templateBlock): bool { - return $templateBlock->isEnabled(); - } + static fn(TemplateBlock $templateBlock): bool => $templateBlock->isEnabled() )); } $enabledFinalizedTemplateBlocks = array_filter( $this->findFinalizedForEvents($eventNames), - static function (TemplateBlock $templateBlock): bool { - return $templateBlock->isEnabled(); - } + static fn(TemplateBlock $templateBlock): bool => $templateBlock->isEnabled() ); $templateBlocksPriorityQueue = new SplPriorityQueue(); diff --git a/src/Sylius/Bundle/UiBundle/Renderer/HtmlDebugTemplateEventRenderer.php b/src/Sylius/Bundle/UiBundle/Renderer/HtmlDebugTemplateEventRenderer.php index f5b1d18f873e..f26c674a2591 100644 --- a/src/Sylius/Bundle/UiBundle/Renderer/HtmlDebugTemplateEventRenderer.php +++ b/src/Sylius/Bundle/UiBundle/Renderer/HtmlDebugTemplateEventRenderer.php @@ -61,8 +61,6 @@ public function render(array $eventNames, array $context = []): string */ private function shouldRenderHtmlDebug(array $templateBlocks): bool { - return count($templateBlocks) === 0 || count(array_filter($templateBlocks, static function (TemplateBlock $templateBlock): bool { - return strrpos($templateBlock->getTemplate(), '.html.twig') !== false; - })) >= 1; + return count($templateBlocks) === 0 || count(array_filter($templateBlocks, static fn(TemplateBlock $templateBlock): bool => strrpos($templateBlock->getTemplate(), '.html.twig') !== false)) >= 1; } } diff --git a/src/Sylius/Bundle/UiBundle/Twig/MergeRecursiveExtension.php b/src/Sylius/Bundle/UiBundle/Twig/MergeRecursiveExtension.php index c4d669a4d2b5..a27feb63b3af 100644 --- a/src/Sylius/Bundle/UiBundle/Twig/MergeRecursiveExtension.php +++ b/src/Sylius/Bundle/UiBundle/Twig/MergeRecursiveExtension.php @@ -23,9 +23,7 @@ public function getFilters(): array return [ new TwigFilter( 'sylius_merge_recursive', - function (array $firstArray, array $secondArray): array { - return array_merge_recursive($firstArray, $secondArray); - } + fn(array $firstArray, array $secondArray): array => array_merge_recursive($firstArray, $secondArray) ), ]; } diff --git a/src/Sylius/Bundle/UserBundle/Command/AbstractRoleCommand.php b/src/Sylius/Bundle/UserBundle/Command/AbstractRoleCommand.php index 42d2d498b1e9..bd2028b85af7 100644 --- a/src/Sylius/Bundle/UserBundle/Command/AbstractRoleCommand.php +++ b/src/Sylius/Bundle/UserBundle/Command/AbstractRoleCommand.php @@ -127,9 +127,7 @@ protected function getAvailableUserTypes(): array $config = $this->getContainer()->getParameter('sylius.user.users'); // Keep only users types which implement \Sylius\Component\User\Model\UserInterface - $userTypes = array_filter($config, function (array $userTypeConfig): bool { - return isset($userTypeConfig['user']['classes']['model']) && is_a($userTypeConfig['user']['classes']['model'], UserInterface::class, true); - }); + $userTypes = array_filter($config, fn(array $userTypeConfig): bool => isset($userTypeConfig['user']['classes']['model']) && is_a($userTypeConfig['user']['classes']['model'], UserInterface::class, true)); return array_keys($userTypes); } diff --git a/src/Sylius/Bundle/UserBundle/Security/UserLogin.php b/src/Sylius/Bundle/UserBundle/Security/UserLogin.php index 60337c95785b..8d33cc4d170b 100644 --- a/src/Sylius/Bundle/UserBundle/Security/UserLogin.php +++ b/src/Sylius/Bundle/UserBundle/Security/UserLogin.php @@ -71,7 +71,7 @@ protected function createToken(UserInterface $user, string $firewallName): Usern $user, null, $firewallName, - array_map(/** @param object|string $role */ static function ($role): string { return (string) $role; }, $user->getRoles()) + array_map(/** @param object|string $role */ static fn($role): string => (string) $role, $user->getRoles()) ); } } diff --git a/src/Sylius/Bundle/UserBundle/Tests/Functional/SyliusUserBundleTest.php b/src/Sylius/Bundle/UserBundle/Tests/Functional/SyliusUserBundleTest.php index b0f670756654..da29714feac9 100644 --- a/src/Sylius/Bundle/UserBundle/Tests/Functional/SyliusUserBundleTest.php +++ b/src/Sylius/Bundle/UserBundle/Tests/Functional/SyliusUserBundleTest.php @@ -30,9 +30,7 @@ public function its_services_are_initializable() /** @var Container $container */ $container = self::$kernel->getContainer(); - $serviceIds = array_filter($container->getServiceIds(), function (string $serviceId): bool { - return 0 === strpos($serviceId, 'sylius.'); - }); + $serviceIds = array_filter($container->getServiceIds(), fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.')); foreach ($serviceIds as $id) { Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));