Introduce arrow functions from PHP 7.4

This commit is contained in:
Mateusz Zalewski 2021-11-02 13:37:55 +01:00
parent cdc7be607d
commit e6a5c4e663
No known key found for this signature in database
GPG key ID: 9BECA0BB71612E52
94 changed files with 187 additions and 448 deletions

View file

@ -3,6 +3,7 @@
declare(strict_types=1); declare(strict_types=1);
use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php74\Rector\Property\TypedPropertyRector; use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList; use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@ -15,4 +16,5 @@ return static function (ContainerConfigurator $containerConfigurator): void
$services = $containerConfigurator->services(); $services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class); $services->set(TypedPropertyRector::class);
$services->set(ClosureToArrowFunctionRector::class);
}; };

View file

@ -65,9 +65,7 @@ final class CountryChoiceType extends AbstractType
$countries = array_filter($countries, $options['choice_filter']); $countries = array_filter($countries, $options['choice_filter']);
} }
usort($countries, static function (CountryInterface $firstCountry, CountryInterface $secondCountry): int { usort($countries, static fn(CountryInterface $firstCountry, CountryInterface $secondCountry): int => $firstCountry->getName() <=> $secondCountry->getName());
return $firstCountry->getName() <=> $secondCountry->getName();
});
return $countries; return $countries;
}) })

View file

@ -71,9 +71,7 @@ final class ZoneType extends AbstractResourceType
]; ];
if ($zone->getType() === ZoneInterface::TYPE_ZONE) { if ($zone->getType() === ZoneInterface::TYPE_ZONE) {
$entryOptions['entry_options']['choice_filter'] = static function (?ZoneInterface $subZone) use ($zone): bool { $entryOptions['entry_options']['choice_filter'] = static fn(?ZoneInterface $subZone): bool => $subZone !== null && $zone->getId() !== $subZone->getId();
return $subZone !== null && $zone->getId() !== $subZone->getId();
};
} }
$event->getForm()->add('members', CollectionType::class, [ $event->getForm()->add('members', CollectionType::class, [

View file

@ -110,9 +110,7 @@ final class CountryChoiceTypeTest extends TypeTestCase
$this->poland->reveal(), $this->poland->reveal(),
]); ]);
$this->assertChoicesLabels(['Poland'], ['choice_filter' => static function (?CountryInterface $country): bool { $this->assertChoicesLabels(['Poland'], ['choice_filter' => static fn(?CountryInterface $country): bool => $country !== null && $country->getName() === 'Poland']);
return $country !== null && $country->getName() === 'Poland';
}]);
} }
private function assertChoicesLabels(array $expectedLabels, array $formConfiguration = []): void private function assertChoicesLabels(array $expectedLabels, array $formConfiguration = []): void
@ -120,8 +118,6 @@ final class CountryChoiceTypeTest extends TypeTestCase
$form = $this->factory->create(CountryChoiceType::class, null, $formConfiguration); $form = $this->factory->create(CountryChoiceType::class, null, $formConfiguration);
$view = $form->createView(); $view = $form->createView();
Assert::assertSame($expectedLabels, array_map(static function (ChoiceView $choiceView): string { Assert::assertSame($expectedLabels, array_map(static fn(ChoiceView $choiceView): string => $choiceView->label, $view->vars['choices']));
return $choiceView->label;
}, $view->vars['choices']));
} }
} }

View file

@ -136,8 +136,6 @@ final class ZoneChoiceTypeTest extends TypeTestCase
$form = $this->factory->create(ZoneChoiceType::class, null, $formConfiguration); $form = $this->factory->create(ZoneChoiceType::class, null, $formConfiguration);
$view = $form->createView(); $view = $form->createView();
Assert::assertSame($expectedLabels, array_map(function (ChoiceView $choiceView): string { Assert::assertSame($expectedLabels, array_map(fn(ChoiceView $choiceView): string => $choiceView->label, $view->vars['choices']));
return $choiceView->label;
}, $view->vars['choices']));
} }
} }

View file

@ -30,9 +30,7 @@ final class SyliusAddressingBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -43,9 +43,7 @@ final class OrderUnitTaxesExtension extends AbstractExtension
{ {
$total = array_reduce( $total = array_reduce(
$orderItem->getAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->toArray(), $orderItem->getAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->toArray(),
static function (int $total, BaseAdjustmentInterface $adjustment) use ($neutral) { static fn(int $total, BaseAdjustmentInterface $adjustment) => $neutral === $adjustment->isNeutral() ? $total + $adjustment->getAmount() : $total,
return $neutral === $adjustment->isNeutral() ? $total + $adjustment->getAmount() : $total;
},
0 0
); );

View file

@ -28,9 +28,7 @@ final class ShopExtension extends AbstractExtension
public function getFunctions(): array public function getFunctions(): array
{ {
return [ return [
new TwigFunction('is_shop_enabled', function (): bool { new TwigFunction('is_shop_enabled', fn(): bool => $this->isShopEnabled),
return $this->isShopEnabled;
}),
]; ];
} }
} }

View file

@ -35,14 +35,10 @@ final class SelectAttributeValueTranslationsType extends AbstractType
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'entries' => $this->definedLocalesCodes, 'entries' => $this->definedLocalesCodes,
'entry_name' => function (string $localeCode): string { 'entry_name' => fn(string $localeCode): string => $localeCode,
return $localeCode; 'entry_options' => fn(string $localeCode): array => [
}, 'required' => $localeCode === $this->defaultLocaleCode,
'entry_options' => function (string $localeCode): array { ],
return [
'required' => $localeCode === $this->defaultLocaleCode,
];
},
]); ]);
} }

View file

@ -68,8 +68,6 @@ final class SelectAttributeTypeTest extends TypeTestCase
); );
$view = $form->createView(); $view = $form->createView();
Assert::assertSame($expectedLabels, array_map(function (ChoiceView $choiceView): string { Assert::assertSame($expectedLabels, array_map(fn(ChoiceView $choiceView): string => $choiceView->label, $view->vars['choices']));
return $choiceView->label;
}, $view->vars['choices']));
} }
} }

View file

@ -30,9 +30,7 @@ final class SyliusAttributeBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -40,9 +40,7 @@ final class ChannelChoiceType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'choices' => function (Options $options): array { 'choices' => fn(Options $options): array => $this->channelRepository->findAll(),
return $this->channelRepository->findAll();
},
'choice_value' => 'code', 'choice_value' => 'code',
'choice_label' => 'name', 'choice_label' => 'name',
'choice_translation_domain' => false, 'choice_translation_domain' => false,

View file

@ -67,9 +67,7 @@ final class FakeChannelPersisterSpec extends ObjectBehavior
$response->headers = $responseHeaderBag; $response->headers = $responseHeaderBag;
$responseHeaderBag $responseHeaderBag
->setCookie(Argument::that(static function (Cookie $cookie): bool { ->setCookie(Argument::that(static fn(Cookie $cookie): bool => $cookie->getName() === '_channel_code' && $cookie->getValue() === 'fake_channel_code'))
return $cookie->getName() === '_channel_code' && $cookie->getValue() === 'fake_channel_code';
}))
->shouldBeCalled() ->shouldBeCalled()
; ;

View file

@ -30,9 +30,7 @@ final class SyliusChannelBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -37,9 +37,7 @@ final class RegisterUriBasedSectionResolverPass implements CompilerPassInterface
} }
} }
usort($uriBasedSectionProviders, static function (array $a, array $b): int { usort($uriBasedSectionProviders, static fn(array $a, array $b): int => -($a['priority'] <=> $b['priority']));
return -($a['priority'] <=> $b['priority']);
});
$uriBasedSectionResolver->setArgument(1, array_column($uriBasedSectionProviders, 'id')); $uriBasedSectionResolver->setArgument(1, array_column($uriBasedSectionProviders, 'id'));
} }

View file

@ -57,27 +57,13 @@ class AddressExampleFactory extends AbstractExampleFactory
protected function configureOptions(OptionsResolver $resolver): void protected function configureOptions(OptionsResolver $resolver): void
{ {
$resolver $resolver
->setDefault('first_name', function (Options $options): string { ->setDefault('first_name', fn(Options $options): string => $this->faker->firstName)
return $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('last_name', function (Options $options): string { ->setDefault('company', fn(Options $options): ?string => random_int(1, 100) > 50 ? $this->faker->company : null)
return $this->faker->lastName; ->setDefault('street', fn(Options $options): string => $this->faker->streetAddress)
}) ->setDefault('city', fn(Options $options): string => $this->faker->city)
->setDefault('phone_number', function (Options $options): ?string { ->setDefault('postcode', fn(Options $options): string => $this->faker->postcode)
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('country_code', function (Options $options): string { ->setDefault('country_code', function (Options $options): string {
$countries = $this->countryRepository->findAll(); $countries = $this->countryRepository->findAll();
shuffle($countries); shuffle($countries);

View file

@ -101,12 +101,8 @@ class AdminUserExampleFactory extends AbstractExampleFactory implements ExampleF
protected function configureOptions(OptionsResolver $resolver): void protected function configureOptions(OptionsResolver $resolver): void
{ {
$resolver $resolver
->setDefault('email', function (Options $options): string { ->setDefault('email', fn(Options $options): string => $this->faker->email)
return $this->faker->email; ->setDefault('username', fn(Options $options): string => $this->faker->firstName . ' ' . $this->faker->lastName)
})
->setDefault('username', function (Options $options): string {
return $this->faker->firstName . ' ' . $this->faker->lastName;
})
->setDefault('enabled', true) ->setDefault('enabled', true)
->setAllowedTypes('enabled', 'bool') ->setAllowedTypes('enabled', 'bool')
->setDefault('password', 'password123') ->setDefault('password', 'password123')

View file

@ -136,18 +136,10 @@ class ChannelExampleFactory extends AbstractExampleFactory implements ExampleFac
return $words; return $words;
}) })
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']); ->setDefault('hostname', fn(Options $options): string => $options['code'] . '.localhost')
}) ->setDefault('color', fn(Options $options): string => $this->faker->colorName)
->setDefault('hostname', function (Options $options): string { ->setDefault('enabled', fn(Options $options): bool => $this->faker->boolean(90))
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);
})
->setAllowedTypes('enabled', 'bool') ->setAllowedTypes('enabled', 'bool')
->setDefault('skipping_shipping_step_allowed', false) ->setDefault('skipping_shipping_step_allowed', false)
->setAllowedTypes('skipping_shipping_step_allowed', 'bool') ->setAllowedTypes('skipping_shipping_step_allowed', 'bool')
@ -166,17 +158,13 @@ class ChannelExampleFactory extends AbstractExampleFactory implements ExampleFac
) )
->setDefault('tax_calculation_strategy', 'order_items_based') ->setDefault('tax_calculation_strategy', 'order_items_based')
->setAllowedTypes('tax_calculation_strategy', 'string') ->setAllowedTypes('tax_calculation_strategy', 'string')
->setDefault('default_locale', function (Options $options): LocaleInterface { ->setDefault('default_locale', fn(Options $options): LocaleInterface => $this->faker->randomElement($options['locales']))
return $this->faker->randomElement($options['locales']);
})
->setAllowedTypes('default_locale', ['string', LocaleInterface::class]) ->setAllowedTypes('default_locale', ['string', LocaleInterface::class])
->setNormalizer('default_locale', LazyOption::getOneBy($this->localeRepository, 'code')) ->setNormalizer('default_locale', LazyOption::getOneBy($this->localeRepository, 'code'))
->setDefault('locales', LazyOption::all($this->localeRepository)) ->setDefault('locales', LazyOption::all($this->localeRepository))
->setAllowedTypes('locales', 'array') ->setAllowedTypes('locales', 'array')
->setNormalizer('locales', LazyOption::findBy($this->localeRepository, 'code')) ->setNormalizer('locales', LazyOption::findBy($this->localeRepository, 'code'))
->setDefault('base_currency', function (Options $options): CurrencyInterface { ->setDefault('base_currency', fn(Options $options): CurrencyInterface => $this->faker->randomElement($options['currencies']))
return $this->faker->randomElement($options['currencies']);
})
->setAllowedTypes('base_currency', ['string', CurrencyInterface::class]) ->setAllowedTypes('base_currency', ['string', CurrencyInterface::class])
->setNormalizer('base_currency', LazyOption::getOneBy($this->currencyRepository, 'code')) ->setNormalizer('base_currency', LazyOption::getOneBy($this->currencyRepository, 'code'))
->setDefault('currencies', LazyOption::all($this->currencyRepository)) ->setDefault('currencies', LazyOption::all($this->currencyRepository))

View file

@ -60,9 +60,7 @@ class CustomerGroupExampleFactory extends AbstractExampleFactory implements Exam
return $words; return $words;
}) })
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']);
})
; ;
} }
} }

View file

@ -157,9 +157,7 @@ class OrderExampleFactory extends AbstractExampleFactory implements ExampleFacto
->setAllowedTypes('country', ['null', 'string', CountryInterface::class]) ->setAllowedTypes('country', ['null', 'string', CountryInterface::class])
->setNormalizer('country', LazyOption::findOneBy($this->countryRepository, 'code')) ->setNormalizer('country', LazyOption::findOneBy($this->countryRepository, 'code'))
->setDefault('complete_date', function (Options $options): \DateTimeInterface { ->setDefault('complete_date', fn(Options $options): \DateTimeInterface => $this->faker->dateTimeBetween('-1 years', 'now'))
return $this->faker->dateTimeBetween('-1 years', 'now');
})
->setAllowedTypes('complete_date', ['null', \DateTime::class]) ->setAllowedTypes('complete_date', ['null', \DateTime::class])
->setDefault('fulfilled', false) ->setDefault('fulfilled', false)

View file

@ -91,20 +91,14 @@ class PaymentMethodExampleFactory extends AbstractExampleFactory implements Exam
return $words; return $words;
}) })
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']); ->setDefault('description', fn(Options $options): string => $this->faker->sentence())
})
->setDefault('description', function (Options $options): string {
return $this->faker->sentence();
})
->setDefault('instructions', null) ->setDefault('instructions', null)
->setAllowedTypes('instructions', ['null', 'string']) ->setAllowedTypes('instructions', ['null', 'string'])
->setDefault('gatewayName', 'Offline') ->setDefault('gatewayName', 'Offline')
->setDefault('gatewayFactory', 'offline') ->setDefault('gatewayFactory', 'offline')
->setDefault('gatewayConfig', []) ->setDefault('gatewayConfig', [])
->setDefault('enabled', function (Options $options): bool { ->setDefault('enabled', fn(Options $options): bool => $this->faker->boolean(90))
return $this->faker->boolean(90);
})
->setDefault('channels', LazyOption::all($this->channelRepository)) ->setDefault('channels', LazyOption::all($this->channelRepository))
->setAllowedTypes('channels', 'array') ->setAllowedTypes('channels', 'array')
->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code')) ->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code'))

View file

@ -73,9 +73,7 @@ class ProductAssociationTypeExampleFactory extends AbstractExampleFactory implem
return $words; return $words;
}) })
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']);
})
; ;
} }

View file

@ -81,15 +81,9 @@ class ProductAttributeExampleFactory extends AbstractExampleFactory implements E
return $words; return $words;
}) })
->setDefault('translatable', true) ->setDefault('translatable', true)
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']); ->setDefault('type', fn(Options $options): string => $this->faker->randomElement(array_keys($this->attributeTypes)))
}) ->setDefault('configuration', fn(Options $options): array => [])
->setDefault('type', function (Options $options): string {
return $this->faker->randomElement(array_keys($this->attributeTypes));
})
->setDefault('configuration', function (Options $options): array {
return [];
})
->setAllowedValues('type', array_keys($this->attributeTypes)) ->setAllowedValues('type', array_keys($this->attributeTypes))
; ;
} }

View file

@ -155,9 +155,7 @@ class ProductExampleFactory extends AbstractExampleFactory implements ExampleFac
return $words; return $words;
}) })
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']);
})
->setDefault('enabled', true) ->setDefault('enabled', true)
->setAllowedTypes('enabled', 'bool') ->setAllowedTypes('enabled', 'bool')
@ -165,13 +163,9 @@ class ProductExampleFactory extends AbstractExampleFactory implements ExampleFac
->setDefault('tracked', false) ->setDefault('tracked', false)
->setAllowedTypes('tracked', 'bool') ->setAllowedTypes('tracked', 'bool')
->setDefault('slug', function (Options $options): string { ->setDefault('slug', fn(Options $options): string => $this->slugGenerator->generate($options['name']))
return $this->slugGenerator->generate($options['name']);
})
->setDefault('short_description', function (Options $options): string { ->setDefault('short_description', fn(Options $options): string => $this->faker->paragraph)
return $this->faker->paragraph;
})
->setDefault('description', function (Options $options): string { ->setDefault('description', function (Options $options): string {
/** @var string $paragraphs */ /** @var string $paragraphs */
@ -197,9 +191,7 @@ class ProductExampleFactory extends AbstractExampleFactory implements ExampleFac
->setDefault('product_attributes', []) ->setDefault('product_attributes', [])
->setAllowedTypes('product_attributes', 'array') ->setAllowedTypes('product_attributes', 'array')
->setNormalizer('product_attributes', function (Options $options, array $productAttributes): array { ->setNormalizer('product_attributes', fn(Options $options, array $productAttributes): array => $this->setAttributeValues($productAttributes))
return $this->setAttributeValues($productAttributes);
})
->setDefault('product_options', []) ->setDefault('product_options', [])
->setAllowedTypes('product_options', 'array') ->setAllowedTypes('product_options', 'array')
@ -417,9 +409,7 @@ class ProductExampleFactory extends AbstractExampleFactory implements ExampleFac
{ {
return trim(array_reduce( return trim(array_reduce(
$variant->getOptionValues()->toArray(), $variant->getOptionValues()->toArray(),
static function (?string $variantName, ProductOptionValueInterface $variantOption) { static fn(?string $variantName, ProductOptionValueInterface $variantOption) => $variantName . sprintf('%s ', $variantOption->getValue()),
return $variantName . sprintf('%s ', $variantOption->getValue());
},
'' ''
)); ));
} }

View file

@ -93,9 +93,7 @@ class ProductOptionExampleFactory extends AbstractExampleFactory implements Exam
return $words; return $words;
}) })
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']);
})
->setDefault('values', null) ->setDefault('values', null)
->setDefault('values', function (Options $options, ?array $values): array { ->setDefault('values', function (Options $options, ?array $values): array {
if (is_array($values)) { if (is_array($values)) {

View file

@ -84,9 +84,7 @@ class ProductReviewExampleFactory extends AbstractExampleFactory implements Exam
return $words; return $words;
}) })
->setDefault('rating', function (Options $options): int { ->setDefault('rating', fn(Options $options): int => $this->faker->numberBetween(1, 5))
return $this->faker->numberBetween(1, 5);
})
->setDefault('comment', function (Options $options): string { ->setDefault('comment', function (Options $options): string {
/** @var string $sentences */ /** @var string $sentences */
$sentences = $this->faker->sentences(3, true); $sentences = $this->faker->sentences(3, true);

View file

@ -114,9 +114,7 @@ class PromotionExampleFactory extends AbstractExampleFactory implements ExampleF
protected function configureOptions(OptionsResolver $resolver): void protected function configureOptions(OptionsResolver $resolver): void
{ {
$resolver $resolver
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']);
})
->setDefault('name', $this->faker->words(3, true)) ->setDefault('name', $this->faker->words(3, true))
->setDefault('description', $this->faker->sentence()) ->setDefault('description', $this->faker->sentence())
->setDefault('usage_limit', null) ->setDefault('usage_limit', null)

View file

@ -62,12 +62,8 @@ class ShippingCategoryExampleFactory extends AbstractExampleFactory implements E
return $words; return $words;
}) })
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']); ->setDefault('description', fn(Options $options): string => $this->faker->paragraph)
})
->setDefault('description', function (Options $options): string {
return $this->faker->paragraph;
})
; ;
} }
} }

View file

@ -111,21 +111,15 @@ class ShippingMethodExampleFactory extends AbstractExampleFactory implements Exa
protected function configureOptions(OptionsResolver $resolver): void protected function configureOptions(OptionsResolver $resolver): void
{ {
$resolver $resolver
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']);
})
->setDefault('name', function (Options $options): string { ->setDefault('name', function (Options $options): string {
/** @var string $words */ /** @var string $words */
$words = $this->faker->words(3, true); $words = $this->faker->words(3, true);
return $words; return $words;
}) })
->setDefault('description', function (Options $options): string { ->setDefault('description', fn(Options $options): string => $this->faker->sentence())
return $this->faker->sentence(); ->setDefault('enabled', fn(Options $options): bool => $this->faker->boolean(90))
})
->setDefault('enabled', function (Options $options): bool {
return $this->faker->boolean(90);
})
->setAllowedTypes('enabled', 'bool') ->setAllowedTypes('enabled', 'bool')
->setDefault('zone', LazyOption::randomOne($this->zoneRepository)) ->setDefault('zone', LazyOption::randomOne($this->zoneRepository))
->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class]) ->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])

View file

@ -79,15 +79,9 @@ class ShopUserExampleFactory extends AbstractExampleFactory implements ExampleFa
protected function configureOptions(OptionsResolver $resolver): void protected function configureOptions(OptionsResolver $resolver): void
{ {
$resolver $resolver
->setDefault('email', function (Options $options): string { ->setDefault('email', fn(Options $options): string => $this->faker->email)
return $this->faker->email; ->setDefault('first_name', fn(Options $options): string => $this->faker->firstName)
}) ->setDefault('last_name', fn(Options $options): string => $this->faker->lastName)
->setDefault('first_name', function (Options $options): string {
return $this->faker->firstName;
})
->setDefault('last_name', function (Options $options): string {
return $this->faker->lastName;
})
->setDefault('enabled', true) ->setDefault('enabled', true)
->setAllowedTypes('enabled', 'bool') ->setAllowedTypes('enabled', 'bool')
->setDefault('password', 'password123') ->setDefault('password', 'password123')
@ -99,12 +93,8 @@ class ShopUserExampleFactory extends AbstractExampleFactory implements ExampleFa
'gender', 'gender',
[CustomerComponent::UNKNOWN_GENDER, CustomerComponent::MALE_GENDER, CustomerComponent::FEMALE_GENDER] [CustomerComponent::UNKNOWN_GENDER, CustomerComponent::MALE_GENDER, CustomerComponent::FEMALE_GENDER]
) )
->setDefault('phone_number', function (Options $options): string { ->setDefault('phone_number', fn(Options $options): string => $this->faker->phoneNumber)
return $this->faker->phoneNumber; ->setDefault('birthday', fn(Options $options): \DateTime => $this->faker->dateTimeThisCentury())
})
->setDefault('birthday', function (Options $options): \DateTime {
return $this->faker->dateTimeThisCentury();
})
->setAllowedTypes('birthday', ['null', 'string', \DateTimeInterface::class]) ->setAllowedTypes('birthday', ['null', 'string', \DateTimeInterface::class])
->setNormalizer( ->setNormalizer(
'birthday', 'birthday',

View file

@ -62,12 +62,8 @@ class TaxCategoryExampleFactory extends AbstractExampleFactory implements Exampl
return $words; return $words;
}) })
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']); ->setDefault('description', fn(Options $options): string => $this->faker->paragraph)
})
->setDefault('description', function (Options $options): string {
return $this->faker->paragraph;
})
; ;
} }
} }

View file

@ -73,22 +73,16 @@ class TaxRateExampleFactory extends AbstractExampleFactory implements ExampleFac
protected function configureOptions(OptionsResolver $resolver): void protected function configureOptions(OptionsResolver $resolver): void
{ {
$resolver $resolver
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']);
})
->setDefault('name', function (Options $options): string { ->setDefault('name', function (Options $options): string {
/** @var string $words */ /** @var string $words */
$words = $this->faker->words(3, true); $words = $this->faker->words(3, true);
return $words; return $words;
}) })
->setDefault('amount', function (Options $options): float { ->setDefault('amount', fn(Options $options): float => $this->faker->randomFloat(2, 0, 0.4))
return $this->faker->randomFloat(2, 0, 0.4);
})
->setAllowedTypes('amount', 'float') ->setAllowedTypes('amount', 'float')
->setDefault('included_in_price', function (Options $options): bool { ->setDefault('included_in_price', fn(Options $options): bool => $this->faker->boolean())
return $this->faker->boolean();
})
->setAllowedTypes('included_in_price', 'bool') ->setAllowedTypes('included_in_price', 'bool')
->setDefault('calculator', 'default') ->setDefault('calculator', 'default')
->setDefault('zone', LazyOption::randomOne($this->zoneRepository)) ->setDefault('zone', LazyOption::randomOne($this->zoneRepository))

View file

@ -117,13 +117,9 @@ class TaxonExampleFactory extends AbstractExampleFactory implements ExampleFacto
return $words; return $words;
}) })
->setDefault('code', function (Options $options): string { ->setDefault('code', fn(Options $options): string => StringInflector::nameToCode($options['name']))
return StringInflector::nameToCode($options['name']);
})
->setDefault('slug', null) ->setDefault('slug', null)
->setDefault('description', function (Options $options): string { ->setDefault('description', fn(Options $options): string => $this->faker->paragraph)
return $this->faker->paragraph;
})
->setDefault('translations', []) ->setDefault('translations', [])
->setAllowedTypes('translations', ['array']) ->setAllowedTypes('translations', ['array'])
->setDefault('children', []) ->setDefault('children', [])

View file

@ -95,9 +95,7 @@ final class LazyOption
public static function all(RepositoryInterface $repository): \Closure public static function all(RepositoryInterface $repository): \Closure
{ {
return function (Options $options) use ($repository): iterable { return fn(Options $options): iterable => $repository->findAll();
return $repository->findAll();
};
} }
public static function findBy(RepositoryInterface $repository, string $field, array $criteria = []): \Closure public static function findBy(RepositoryInterface $repository, string $field, array $criteria = []): \Closure

View file

@ -50,8 +50,6 @@ final class TaxonsToCodesTransformer implements DataTransformerInterface
{ {
Assert::isInstanceOf($taxons, Collection::class); Assert::isInstanceOf($taxons, Collection::class);
return array_map(function (TaxonInterface $taxon) { return array_map(fn(TaxonInterface $taxon) => $taxon->getCode(), $taxons->toArray());
return $taxon->getCode();
}, $taxons->toArray());
} }
} }

View file

@ -39,14 +39,12 @@ final class CartTypeExtension extends AbstractTypeExtension
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setNormalizer('validation_groups', function (Options $options, array $validationGroups) { $resolver->setNormalizer('validation_groups', fn(Options $options, array $validationGroups) => function (FormInterface $form) use ($validationGroups) {
return function (FormInterface $form) use ($validationGroups) { if ((bool) $form->get('promotionCoupon')->getNormData()) { // Validate the coupon if it was sent
if ((bool) $form->get('promotionCoupon')->getNormData()) { // Validate the coupon if it was sent $validationGroups[] = 'sylius_promotion_coupon';
$validationGroups[] = 'sylius_promotion_coupon'; }
}
return $validationGroups; return $validationGroups;
};
}); });
} }

View file

@ -31,12 +31,10 @@ final class ProductVariantGenerationTypeExtension extends AbstractTypeExtension
$event->getForm()->add('channelPricings', ChannelCollectionType::class, [ $event->getForm()->add('channelPricings', ChannelCollectionType::class, [
'entry_type' => ChannelPricingType::class, 'entry_type' => ChannelPricingType::class,
'entry_options' => function (ChannelInterface $channel) use ($productVariant) { 'entry_options' => fn(ChannelInterface $channel) => [
return [ 'channel' => $channel,
'channel' => $channel, 'product_variant' => $productVariant,
'product_variant' => $productVariant, ],
];
},
'label' => 'sylius.form.variant.price', 'label' => 'sylius.form.variant.price',
]); ]);
}); });

View file

@ -81,13 +81,11 @@ final class ProductVariantTypeExtension extends AbstractTypeExtension
$event->getForm()->add('channelPricings', ChannelCollectionType::class, [ $event->getForm()->add('channelPricings', ChannelCollectionType::class, [
'entry_type' => ChannelPricingType::class, 'entry_type' => ChannelPricingType::class,
'entry_options' => function (ChannelInterface $channel) use ($productVariant) { 'entry_options' => fn(ChannelInterface $channel) => [
return [ 'channel' => $channel,
'channel' => $channel, 'product_variant' => $productVariant,
'product_variant' => $productVariant, 'required' => false,
'required' => false, ],
];
},
'label' => 'sylius.form.variant.price', 'label' => 'sylius.form.variant.price',
]); ]);
}); });

View file

@ -47,9 +47,7 @@ final class AmountType extends AbstractType
->setAllowedTypes('channel', [ChannelInterface::class]) ->setAllowedTypes('channel', [ChannelInterface::class])
->setDefaults([ ->setDefaults([
'label' => static function (Options $options): string { 'label' => static fn(Options $options): string => $options['channel']->getName(),
return $options['channel']->getName();
},
]) ])
; ;
} }

View file

@ -32,9 +32,7 @@ final class ChannelCollectionType extends AbstractType
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'entries' => $this->channelRepository->findAll(), 'entries' => $this->channelRepository->findAll(),
'entry_name' => function (ChannelInterface $channel) { 'entry_name' => fn(ChannelInterface $channel) => $channel->getCode(),
return $channel->getCode();
},
'error_bubbling' => false, 'error_bubbling' => false,
]); ]);
} }

View file

@ -91,9 +91,7 @@ final class ChannelPricingType extends AbstractResourceType
->setAllowedTypes('product_variant', ['null', ProductVariantInterface::class]) ->setAllowedTypes('product_variant', ['null', ProductVariantInterface::class])
->setDefaults([ ->setDefaults([
'label' => function (Options $options): string { 'label' => fn(Options $options): string => $options['channel']->getName(),
return $options['channel']->getName();
},
]) ])
; ;
} }

View file

@ -25,12 +25,10 @@ final class ChannelBasedFixedDiscountConfigurationType extends AbstractType
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'entry_type' => FixedDiscountConfigurationType::class, 'entry_type' => FixedDiscountConfigurationType::class,
'entry_options' => function (ChannelInterface $channel) { 'entry_options' => fn(ChannelInterface $channel) => [
return [ 'label' => $channel->getName(),
'label' => $channel->getName(), 'currency' => $channel->getBaseCurrency()->getCode(),
'currency' => $channel->getBaseCurrency()->getCode(), ],
];
},
]); ]);
} }

View file

@ -25,12 +25,10 @@ final class ChannelBasedUnitFixedDiscountConfigurationType extends AbstractType
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'entry_type' => UnitFixedDiscountConfigurationType::class, 'entry_type' => UnitFixedDiscountConfigurationType::class,
'entry_options' => function (ChannelInterface $channel) { 'entry_options' => fn(ChannelInterface $channel) => [
return [ 'label' => $channel->getName(),
'label' => $channel->getName(), 'currency' => $channel->getBaseCurrency()->getCode(),
'currency' => $channel->getBaseCurrency()->getCode(), ],
];
},
]); ]);
} }

View file

@ -25,12 +25,10 @@ final class ChannelBasedUnitPercentageDiscountConfigurationType extends Abstract
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'entry_type' => UnitPercentageDiscountConfigurationType::class, 'entry_type' => UnitPercentageDiscountConfigurationType::class,
'entry_options' => function (ChannelInterface $channel) { 'entry_options' => fn(ChannelInterface $channel) => [
return [ 'label' => $channel->getName(),
'label' => $channel->getName(), 'currency' => $channel->getBaseCurrency()->getCode(),
'currency' => $channel->getBaseCurrency()->getCode(), ],
];
},
]); ]);
} }

View file

@ -25,12 +25,10 @@ final class ChannelBasedItemTotalConfigurationType extends AbstractType
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'entry_type' => ItemTotalConfigurationType::class, 'entry_type' => ItemTotalConfigurationType::class,
'entry_options' => function (ChannelInterface $channel) { 'entry_options' => fn(ChannelInterface $channel) => [
return [ 'label' => $channel->getName(),
'label' => $channel->getName(), 'currency' => $channel->getBaseCurrency()->getCode(),
'currency' => $channel->getBaseCurrency()->getCode(), ],
];
},
]); ]);
} }

View file

@ -24,12 +24,10 @@ final class ChannelBasedTotalOfItemsFromTaxonConfigurationType extends AbstractT
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'entry_type' => TotalOfItemsFromTaxonConfigurationType::class, 'entry_type' => TotalOfItemsFromTaxonConfigurationType::class,
'entry_options' => function (ChannelInterface $channel): array { 'entry_options' => fn(ChannelInterface $channel): array => [
return [ 'label' => $channel->getName(),
'label' => $channel->getName(), 'currency' => $channel->getBaseCurrency()->getCode(),
'currency' => $channel->getBaseCurrency()->getCode(), ],
];
},
]); ]);
} }

View file

@ -25,12 +25,10 @@ final class ChannelBasedFlatRateConfigurationType extends AbstractType
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'entry_type' => FlatRateConfigurationType::class, 'entry_type' => FlatRateConfigurationType::class,
'entry_options' => function (ChannelInterface $channel): array { 'entry_options' => fn(ChannelInterface $channel): array => [
return [ 'label' => $channel->getName(),
'label' => $channel->getName(), 'currency' => $channel->getBaseCurrency()->getCode(),
'currency' => $channel->getBaseCurrency()->getCode(), ],
];
},
]); ]);
} }

View file

@ -25,12 +25,10 @@ final class ChannelBasedPerUnitRateConfigurationType extends AbstractType
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'entry_type' => PerUnitRateConfigurationType::class, 'entry_type' => PerUnitRateConfigurationType::class,
'entry_options' => function (ChannelInterface $channel): array { 'entry_options' => fn(ChannelInterface $channel): array => [
return [ 'label' => $channel->getName(),
'label' => $channel->getName(), 'currency' => $channel->getBaseCurrency()->getCode(),
'currency' => $channel->getBaseCurrency()->getCode(), ],
];
},
]); ]);
} }

View file

@ -24,12 +24,10 @@ final class ChannelBasedOrderTotalGreaterThanOrEqualConfigurationType extends Ab
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'entry_type' => OrderTotalGreaterThanOrEqualConfigurationType::class, 'entry_type' => OrderTotalGreaterThanOrEqualConfigurationType::class,
'entry_options' => function (ChannelInterface $channel): array { 'entry_options' => fn(ChannelInterface $channel): array => [
return [ 'label' => $channel->getName(),
'label' => $channel->getName(), 'currency' => $channel->getBaseCurrency()->getCode(),
'currency' => $channel->getBaseCurrency()->getCode(), ],
];
},
]); ]);
} }

View file

@ -24,12 +24,10 @@ final class ChannelBasedOrderTotalLessThanOrEqualConfigurationType extends Abstr
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'entry_type' => OrderTotalLessThanOrEqualConfigurationType::class, 'entry_type' => OrderTotalLessThanOrEqualConfigurationType::class,
'entry_options' => function (ChannelInterface $channel): array { 'entry_options' => fn(ChannelInterface $channel): array => [
return [ 'label' => $channel->getName(),
'label' => $channel->getName(), 'currency' => $channel->getBaseCurrency()->getCode(),
'currency' => $channel->getBaseCurrency()->getCode(), ],
];
},
]); ]);
} }

View file

@ -45,14 +45,14 @@ final class UserImpersonator implements UserImpersonatorInterface
$token = new UsernamePasswordToken( $token = new UsernamePasswordToken(
$user, $user,
$this->firewallContextName, $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 { } else {
$token = new UsernamePasswordToken( $token = new UsernamePasswordToken(
$user, $user,
$user->getPassword(), $user->getPassword(),
$this->firewallContextName, $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())
); );
} }

View file

@ -40,9 +40,7 @@ final class CurrencyChoiceType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'choices' => function (Options $options): array { 'choices' => fn(Options $options): array => $this->currencyRepository->findAll(),
return $this->currencyRepository->findAll();
},
'choice_value' => 'code', 'choice_value' => 'code',
'choice_label' => 'name', 'choice_label' => 'name',
'choice_translation_domain' => false, 'choice_translation_domain' => false,

View file

@ -30,9 +30,7 @@ final class SyliusCurrencyBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -41,13 +41,9 @@ final class CustomerChoiceType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'choices' => function (Options $options): array { 'choices' => fn(Options $options): array => $this->customerRepository->findAll(),
return $this->customerRepository->findAll();
},
'choice_value' => 'email', 'choice_value' => 'email',
'choice_label' => function (CustomerInterface $customer): string { 'choice_label' => fn(CustomerInterface $customer): string => sprintf('%s (%s)', $customer->getFullName(), $customer->getEmail()),
return sprintf('%s (%s)', $customer->getFullName(), $customer->getEmail());
},
'choice_translation_domain' => false, 'choice_translation_domain' => false,
]); ]);
} }

View file

@ -40,9 +40,7 @@ final class CustomerGroupChoiceType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'choices' => function (Options $options): array { 'choices' => fn(Options $options): array => $this->customerGroupRepository->findAll(),
return $this->customerGroupRepository->findAll();
},
'choice_value' => 'code', 'choice_value' => 'code',
'choice_label' => 'name', 'choice_label' => 'name',
'choice_translation_domain' => false, 'choice_translation_domain' => false,

View file

@ -30,9 +30,7 @@ final class SyliusCustomerBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -30,9 +30,7 @@ final class SyliusInventoryBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -30,9 +30,7 @@ final class SyliusLocaleBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -30,9 +30,7 @@ final class SyliusMoneyBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -30,9 +30,7 @@ final class SyliusOrderBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -30,9 +30,7 @@ final class SyliusPaymentBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -48,9 +48,7 @@ final class RegisterGatewayConfigTypePass implements CompilerPassInterface
} }
} }
usort($gatewayFactories, function (array $firstGateway, array $secondGateway): int { usort($gatewayFactories, fn(array $firstGateway, array $secondGateway): int => $secondGateway['priority'] - $firstGateway['priority']);
return $secondGateway['priority'] - $firstGateway['priority'];
});
$sortedGatewayFactories = []; $sortedGatewayFactories = [];
foreach ($gatewayFactories as $key => $factory) { foreach ($gatewayFactories as $key => $factory) {

View file

@ -44,9 +44,7 @@ final class ProductVariantToProductOptionsTransformer implements DataTransformer
return array_combine( return array_combine(
array_map( array_map(
function (ProductOptionValueInterface $productOptionValue): string { fn(ProductOptionValueInterface $productOptionValue): string => (string) $productOptionValue->getOptionCode(),
return (string) $productOptionValue->getOptionCode();
},
$value->getOptionValues()->toArray() $value->getOptionValues()->toArray()
), ),
$value->getOptionValues()->toArray() $value->getOptionValues()->toArray()

View file

@ -59,9 +59,7 @@ final class BuildAttributesFormSubscriber implements EventSubscriberInterface
$defaultLocaleCode = $this->localeProvider->getDefaultLocaleCode(); $defaultLocaleCode = $this->localeProvider->getDefaultLocaleCode();
$attributes = $product->getAttributes()->filter( $attributes = $product->getAttributes()->filter(
function (ProductAttributeValueInterface $attribute) use ($defaultLocaleCode) { fn(ProductAttributeValueInterface $attribute) => $attribute->getLocaleCode() === $defaultLocaleCode
return $attribute->getLocaleCode() === $defaultLocaleCode;
}
); );
/** @var ProductAttributeValueInterface $attribute */ /** @var ProductAttributeValueInterface $attribute */

View file

@ -40,9 +40,7 @@ final class ProductAssociationTypeChoiceType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'choices' => function (Options $options) { 'choices' => fn(Options $options) => $this->productAssociationTypeRepository->findAll(),
return $this->productAssociationTypeRepository->findAll();
},
'choice_value' => 'code', 'choice_value' => 'code',
'choice_label' => 'name', 'choice_label' => 'name',
'choice_translation_domain' => false, 'choice_translation_domain' => false,

View file

@ -46,14 +46,10 @@ final class ProductAssociationsType extends AbstractType
$resolver->setDefaults([ $resolver->setDefaults([
'entries' => $this->productAssociationTypeRepository->findAll(), 'entries' => $this->productAssociationTypeRepository->findAll(),
'entry_type' => TextType::class, 'entry_type' => TextType::class,
'entry_name' => function (ProductAssociationTypeInterface $productAssociationType) { 'entry_name' => fn(ProductAssociationTypeInterface $productAssociationType) => $productAssociationType->getCode(),
return $productAssociationType->getCode(); 'entry_options' => fn(ProductAssociationTypeInterface $productAssociationType) => [
}, 'label' => $productAssociationType->getName(),
'entry_options' => function (ProductAssociationTypeInterface $productAssociationType) { ],
return [
'label' => $productAssociationType->getName(),
];
},
]); ]);
} }

View file

@ -40,9 +40,7 @@ final class ProductChoiceType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'choices' => function (Options $options) { 'choices' => fn(Options $options) => $this->productRepository->findAll(),
return $this->productRepository->findAll();
},
'choice_value' => 'code', 'choice_value' => 'code',
'choice_label' => 'name', 'choice_label' => 'name',
'choice_translation_domain' => false, 'choice_translation_domain' => false,

View file

@ -40,9 +40,7 @@ final class ProductOptionChoiceType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'choices' => function (Options $options): array { 'choices' => fn(Options $options): array => $this->productOptionRepository->findAll(),
return $this->productOptionRepository->findAll();
},
'choice_value' => 'code', 'choice_value' => 'code',
'choice_label' => 'name', 'choice_label' => 'name',
'choice_translation_domain' => false, 'choice_translation_domain' => false,

View file

@ -35,14 +35,9 @@ final class ProductVariantChoiceType extends AbstractType
{ {
$resolver $resolver
->setDefaults([ ->setDefaults([
'choices' => function (Options $options): iterable { 'choices' => fn(Options $options): iterable => $options['product']->getVariants(),
return $options['product']->getVariants();
},
'choice_value' => 'code', 'choice_value' => 'code',
'choice_label' => function (ProductVariantInterface $variant): string { 'choice_label' => fn(ProductVariantInterface $variant): string => $variant->getName(),
/** @psalm-suppress InvalidCast */
return (string) $variant;
},
'choice_translation_domain' => false, 'choice_translation_domain' => false,
'multiple' => false, 'multiple' => false,
'expanded' => true, 'expanded' => true,

View file

@ -40,19 +40,13 @@ final class ProductVariantMatchType extends AbstractType
return $product->getOptions(); return $product->getOptions();
}, },
'entry_type' => ProductOptionValueChoiceType::class, 'entry_type' => ProductOptionValueChoiceType::class,
'entry_name' => function (ProductOptionInterface $productOption) { 'entry_name' => fn(ProductOptionInterface $productOption) => $productOption->getCode(),
return $productOption->getCode(); 'entry_options' => fn(Options $options) => fn(ProductOptionInterface $productOption) => [
}, 'label' => $productOption->getName(),
'entry_options' => function (Options $options) { 'option' => $productOption,
return function (ProductOptionInterface $productOption) use ($options) { 'only_available_values' => true,
return [ 'product' => $options['product'],
'label' => $productOption->getName(), ],
'option' => $productOption,
'only_available_values' => true,
'product' => $options['product'],
];
};
},
]) ])
->setRequired('product') ->setRequired('product')

View file

@ -30,9 +30,7 @@ final class SyliusProductBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -27,9 +27,7 @@ final class CompositePromotionCouponEligibilityCheckerPass implements CompilerPa
$container->getDefinition('sylius.promotion_coupon_eligibility_checker')->setArguments([ $container->getDefinition('sylius.promotion_coupon_eligibility_checker')->setArguments([
array_map( array_map(
function ($id) { fn($id) => new Reference($id),
return new Reference($id);
},
array_keys($container->findTaggedServiceIds('sylius.promotion_coupon_eligibility_checker')) array_keys($container->findTaggedServiceIds('sylius.promotion_coupon_eligibility_checker'))
), ),
]); ]);

View file

@ -27,9 +27,7 @@ final class CompositePromotionEligibilityCheckerPass implements CompilerPassInte
$container->getDefinition('sylius.promotion_eligibility_checker')->setArguments([ $container->getDefinition('sylius.promotion_eligibility_checker')->setArguments([
array_map( array_map(
function ($id) { fn($id) => new Reference($id),
return new Reference($id);
},
array_keys($container->findTaggedServiceIds('sylius.promotion_eligibility_checker')) array_keys($container->findTaggedServiceIds('sylius.promotion_eligibility_checker'))
), ),
]); ]);

View file

@ -30,9 +30,7 @@ final class SyliusPromotionBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -30,9 +30,7 @@ final class SyliusReviewBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -27,9 +27,7 @@ final class CompositeShippingMethodEligibilityCheckerPass implements CompilerPas
$container->getDefinition('sylius.shipping_method_eligibility_checker')->setArguments([ $container->getDefinition('sylius.shipping_method_eligibility_checker')->setArguments([
array_map( array_map(
static function ($id): Reference { static fn($id): Reference => new Reference($id),
return new Reference($id);
},
array_keys($container->findTaggedServiceIds('sylius.shipping_method_eligibility_checker')) array_keys($container->findTaggedServiceIds('sylius.shipping_method_eligibility_checker'))
), ),
]); ]);

View file

@ -40,9 +40,7 @@ final class ShippingCategoryChoiceType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'choices' => function (Options $options) { 'choices' => fn(Options $options) => $this->shippingCategoryRepository->findAll(),
return $this->shippingCategoryRepository->findAll();
},
'choice_value' => 'code', 'choice_value' => 'code',
'choice_label' => 'name', 'choice_label' => 'name',
'choice_translation_domain' => false, 'choice_translation_domain' => false,

View file

@ -30,9 +30,7 @@ final class SyliusShippingBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -22,9 +22,7 @@ final class OrderItemsSubtotalCalculator implements OrderItemsSubtotalCalculator
{ {
return array_reduce( return array_reduce(
$order->getItems()->toArray(), $order->getItems()->toArray(),
static function (int $subtotal, OrderItemInterface $item): int { static fn(int $subtotal, OrderItemInterface $item): int => $subtotal + $item->getSubtotal(),
return $subtotal + $item->getSubtotal();
},
0 0
); );
} }

View file

@ -59,9 +59,7 @@ final class CurrencySwitchController
$channel = $this->channelContext->getChannel(); $channel = $this->channelContext->getChannel();
$availableCurrencies = array_map( $availableCurrencies = array_map(
function (CurrencyInterface $currency) { fn(CurrencyInterface $currency) => $currency->getCode(),
return $currency->getCode();
},
$channel->getCurrencies()->toArray() $channel->getCurrencies()->toArray()
); );

View file

@ -40,9 +40,7 @@ final class Configuration implements ConfigurationInterface
->validate() ->validate()
->ifTrue( ->ifTrue(
/** @param mixed $pattern */ /** @param mixed $pattern */
function ($pattern) { fn($pattern) => !is_string($pattern)
return !is_string($pattern);
}
) )
->thenInvalid('Invalid pattern "%s"') ->thenInvalid('Invalid pattern "%s"')
->end() ->end()

View file

@ -43,9 +43,7 @@ class OrderTaxesTotalExtension extends AbstractExtension
{ {
return array_reduce( return array_reduce(
$order->getAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->toArray(), $order->getAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->toArray(),
static function (int $total, BaseAdjustmentInterface $adjustment) use ($isNeutral) { static fn(int $total, BaseAdjustmentInterface $adjustment) => $isNeutral === $adjustment->isNeutral() ? $total + $adjustment->getAmount() : $total,
return $isNeutral === $adjustment->isNeutral() ? $total + $adjustment->getAmount() : $total;
},
0 0
); );
} }

View file

@ -40,9 +40,7 @@ final class TaxCategoryChoiceType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'choices' => function (Options $options) { 'choices' => fn(Options $options) => $this->taxCategoryRepository->findAll(),
return $this->taxCategoryRepository->findAll();
},
'choice_value' => 'code', 'choice_value' => 'code',
'choice_label' => 'name', 'choice_label' => 'name',
'choice_translation_domain' => false, 'choice_translation_domain' => false,

View file

@ -30,9 +30,7 @@ final class SyliusTaxationBundleTest extends WebTestCase
$services = $container->getServiceIds(); $services = $container->getServiceIds();
$services = array_filter($services, function (string $serviceId): bool { $services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) { foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -30,9 +30,7 @@ final class SyliusTaxonomyBundleTest extends KernelTestCase
/** @var Container $container */ /** @var Container $container */
$container = self::$kernel->getContainer(); $container = self::$kernel->getContainer();
$serviceIds = array_filter($container->getServiceIds(), function (string $serviceId): bool { $serviceIds = array_filter($container->getServiceIds(), fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($serviceIds as $id) { foreach ($serviceIds as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));

View file

@ -63,14 +63,12 @@ final class DebugTemplateEventCommand extends Command
$io->table( $io->table(
['Block name', 'Template', 'Priority', 'Enabled'], ['Block name', 'Template', 'Priority', 'Enabled'],
array_map( array_map(
static function (TemplateBlock $templateBlock): array { static fn(TemplateBlock $templateBlock): array => [
return [ $templateBlock->getName(),
$templateBlock->getName(), $templateBlock->getTemplate(),
$templateBlock->getTemplate(), $templateBlock->getPriority(),
$templateBlock->getPriority(), $templateBlock->isEnabled() ? 'TRUE' : 'FALSE',
$templateBlock->isEnabled() ? 'TRUE' : 'FALSE', ],
];
},
$this->templateBlockRegistry->all()[$eventName] ?? [] $this->templateBlockRegistry->all()[$eventName] ?? []
) )
); );

View file

@ -48,16 +48,12 @@ final class TemplateBlockDataCollector extends DataCollector
public function getNumberOfRenderedBlocks(): int public function getNumberOfRenderedBlocks(): int
{ {
return array_reduce($this->data['renderedEvents'], static function (int $accumulator, array $event): int { return array_reduce($this->data['renderedEvents'], static fn(int $accumulator, array $event): int => $accumulator + count($event['blocks']), 0);
return $accumulator + count($event['blocks']);
}, 0);
} }
public function getTotalDuration(): float public function getTotalDuration(): float
{ {
return array_reduce($this->data['renderedEvents'], static function (float $accumulator, array $event): float { return array_reduce($this->data['renderedEvents'], static fn(float $accumulator, array $event): float => $accumulator + $event['time'], 0.0);
return $accumulator + $event['time'];
}, 0.0);
} }
public function getName(): string public function getName(): string

View file

@ -40,9 +40,7 @@ final class Configuration implements ConfigurationInterface
->canBeDisabled() ->canBeDisabled()
->beforeNormalization() ->beforeNormalization()
->ifString() ->ifString()
->then(static function (?string $template): array { ->then(static fn(?string $template): array => ['template' => $template])
return ['template' => $template];
})
->end() ->end()
->children() ->children()
->booleanNode('enabled')->defaultNull()->end() ->booleanNode('enabled')->defaultNull()->end()

View file

@ -46,17 +46,13 @@ final class TemplateBlockRegistry implements TemplateBlockRegistryInterface
return array_values(array_filter( return array_values(array_filter(
$this->eventsToTemplateBlocks[$eventName] ?? [], $this->eventsToTemplateBlocks[$eventName] ?? [],
static function (TemplateBlock $templateBlock): bool { static fn(TemplateBlock $templateBlock): bool => $templateBlock->isEnabled()
return $templateBlock->isEnabled();
}
)); ));
} }
$enabledFinalizedTemplateBlocks = array_filter( $enabledFinalizedTemplateBlocks = array_filter(
$this->findFinalizedForEvents($eventNames), $this->findFinalizedForEvents($eventNames),
static function (TemplateBlock $templateBlock): bool { static fn(TemplateBlock $templateBlock): bool => $templateBlock->isEnabled()
return $templateBlock->isEnabled();
}
); );
$templateBlocksPriorityQueue = new SplPriorityQueue(); $templateBlocksPriorityQueue = new SplPriorityQueue();

View file

@ -61,8 +61,6 @@ final class HtmlDebugTemplateEventRenderer implements TemplateEventRendererInter
*/ */
private function shouldRenderHtmlDebug(array $templateBlocks): bool private function shouldRenderHtmlDebug(array $templateBlocks): bool
{ {
return count($templateBlocks) === 0 || count(array_filter($templateBlocks, static function (TemplateBlock $templateBlock): bool { return count($templateBlocks) === 0 || count(array_filter($templateBlocks, static fn(TemplateBlock $templateBlock): bool => strrpos($templateBlock->getTemplate(), '.html.twig') !== false)) >= 1;
return strrpos($templateBlock->getTemplate(), '.html.twig') !== false;
})) >= 1;
} }
} }

View file

@ -23,9 +23,7 @@ final class MergeRecursiveExtension extends AbstractExtension
return [ return [
new TwigFilter( new TwigFilter(
'sylius_merge_recursive', 'sylius_merge_recursive',
function (array $firstArray, array $secondArray): array { fn(array $firstArray, array $secondArray): array => array_merge_recursive($firstArray, $secondArray)
return array_merge_recursive($firstArray, $secondArray);
}
), ),
]; ];
} }

View file

@ -127,9 +127,7 @@ abstract class AbstractRoleCommand extends ContainerAwareCommand
$config = $this->getContainer()->getParameter('sylius.user.users'); $config = $this->getContainer()->getParameter('sylius.user.users');
// Keep only users types which implement \Sylius\Component\User\Model\UserInterface // Keep only users types which implement \Sylius\Component\User\Model\UserInterface
$userTypes = array_filter($config, function (array $userTypeConfig): bool { $userTypes = array_filter($config, fn(array $userTypeConfig): bool => isset($userTypeConfig['user']['classes']['model']) && is_a($userTypeConfig['user']['classes']['model'], UserInterface::class, true));
return isset($userTypeConfig['user']['classes']['model']) && is_a($userTypeConfig['user']['classes']['model'], UserInterface::class, true);
});
return array_keys($userTypes); return array_keys($userTypes);
} }

View file

@ -71,7 +71,7 @@ class UserLogin implements UserLoginInterface
$user, $user,
null, null,
$firewallName, $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())
); );
} }
} }

View file

@ -30,9 +30,7 @@ final class SyliusUserBundleTest extends KernelTestCase
/** @var Container $container */ /** @var Container $container */
$container = self::$kernel->getContainer(); $container = self::$kernel->getContainer();
$serviceIds = array_filter($container->getServiceIds(), function (string $serviceId): bool { $serviceIds = array_filter($container->getServiceIds(), fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($serviceIds as $id) { foreach ($serviceIds as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)); Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));