PHP CS Fixer: enable static_lambda for Form

This commit is contained in:
Dariusz Ruminski
2025-12-27 00:28:40 +01:00
committed by Nicolas Grekas
parent 355c7001e9
commit 0bb5ccb77d
38 changed files with 184 additions and 176 deletions

View File

@@ -46,7 +46,7 @@ abstract class AbstractChoiceLoader implements ChoiceLoaderInterface
if ($value) {
// if a value callback exists, use it
return array_map(fn ($item) => (string) $value($item), $choices);
return array_map(static fn ($item) => (string) $value($item), $choices);
}
return $this->doLoadValuesForChoices($choices);

View File

@@ -85,14 +85,14 @@ class FormFlow extends Form implements FormFlowInterface
return;
}
if (!$this->move(fn (FormFlowCursor $cursor) => $cursor->getPreviousStep())) {
if (!$this->move(static fn (FormFlowCursor $cursor) => $cursor->getPreviousStep())) {
throw new RuntimeException('Cannot determine previous step.');
}
}
public function moveNext(): void
{
if (!$this->move(fn (FormFlowCursor $cursor) => $cursor->getNextStep())) {
if (!$this->move(static fn (FormFlowCursor $cursor) => $cursor->getNextStep())) {
throw new RuntimeException('Cannot determine next step.');
}
}

View File

@@ -36,9 +36,9 @@ class ButtonFlowType extends AbstractType implements ButtonFlowTypeInterface
->info('Decide whether to include this button in the current form')
->default(null)
->allowedTypes('null', 'array', 'callable')
->normalize(function (Options $options, mixed $value) {
->normalize(static function (Options $options, mixed $value) {
if (\is_array($value)) {
return fn (FormFlowCursor $cursor): bool => \in_array($cursor->getCurrentStep(), $value, true);
return static fn (FormFlowCursor $cursor): bool => \in_array($cursor->getCurrentStep(), $value, true);
}
return $value;
@@ -49,11 +49,11 @@ class ButtonFlowType extends AbstractType implements ButtonFlowTypeInterface
->default(false)
->allowedTypes('bool');
$resolver->setDefault('validate', function (Options $options) {
$resolver->setDefault('validate', static function (Options $options) {
return !$options['clear_submission'];
});
$resolver->setDefault('validation_groups', function (Options $options) {
$resolver->setDefault('validation_groups', static function (Options $options) {
return $options['clear_submission'] ? false : null;
});
}

View File

@@ -28,8 +28,8 @@ class FinishFlowType extends AbstractButtonFlowType
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'handler' => fn (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) => $flow->reset(),
'include_if' => fn (FormFlowCursor $cursor): bool => $cursor->isLastStep(),
'handler' => static fn (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) => $flow->reset(),
'include_if' => static fn (FormFlowCursor $cursor): bool => $cursor->isLastStep(),
]);
}
}

View File

@@ -97,7 +97,7 @@ class FormFlowType extends AbstractFlowType
$resolver->define('step_property_path')
->info('Required if the default step_accessor is being used')
->allowedTypes('string', PropertyPathInterface::class)
->normalize(function (Options $options, string|PropertyPathInterface $value): PropertyPathInterface {
->normalize(static function (Options $options, string|PropertyPathInterface $value): PropertyPathInterface {
return \is_string($value) ? new PropertyPath($value) : $value;
});
@@ -106,7 +106,7 @@ class FormFlowType extends AbstractFlowType
->default(true)
->allowedTypes('bool');
$resolver->setDefault('validation_groups', function (FormFlowInterface $flow) {
$resolver->setDefault('validation_groups', static function (FormFlowInterface $flow) {
return ['Default', $flow->getCursor()->getCurrentStep()];
});
}

View File

@@ -28,8 +28,8 @@ class NextFlowType extends AbstractButtonFlowType
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'handler' => fn (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) => $flow->moveNext(),
'include_if' => fn (FormFlowCursor $cursor): bool => $cursor->canMoveNext(),
'handler' => static fn (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) => $flow->moveNext(),
'include_if' => static fn (FormFlowCursor $cursor): bool => $cursor->canMoveNext(),
]);
}
}

View File

@@ -28,8 +28,8 @@ class PreviousFlowType extends AbstractButtonFlowType
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'handler' => fn (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) => $flow->movePrevious($button->getViewData()),
'include_if' => fn (FormFlowCursor $cursor): bool => $cursor->canMoveBack(),
'handler' => static fn (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) => $flow->movePrevious($button->getViewData()),
'include_if' => static fn (FormFlowCursor $cursor): bool => $cursor->canMoveBack(),
'clear_submission' => true,
]);
}

View File

@@ -27,7 +27,7 @@ class ResetFlowType extends AbstractButtonFlowType
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'handler' => fn (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) => $flow->reset(),
'handler' => static fn (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) => $flow->reset(),
'clear_submission' => true,
]);
}

View File

@@ -19,8 +19,8 @@ class CallbackTransformerTest extends TestCase
public function testTransform()
{
$transformer = new CallbackTransformer(
fn ($value) => $value.' has been transformed',
fn ($value) => $value.' has reversely been transformed'
static fn ($value) => $value.' has been transformed',
static fn ($value) => $value.' has reversely been transformed'
);
$this->assertEquals('foo has been transformed', $transformer->transform('foo'));

View File

@@ -45,7 +45,7 @@ class ArrayChoiceListTest extends AbstractChoiceListTestCase
public function testCreateChoiceListWithValueCallback()
{
$callback = fn ($choice) => ':'.$choice;
$callback = static fn ($choice) => ':'.$choice;
$choiceList = new ArrayChoiceList([2 => 'foo', 7 => 'bar', 10 => 'baz'], $callback);
@@ -110,7 +110,7 @@ class ArrayChoiceListTest extends AbstractChoiceListTestCase
public function testCompareChoicesByIdentityByDefault()
{
$callback = fn ($choice) => $choice->value;
$callback = static fn ($choice) => $choice->value;
$obj1 = (object) ['value' => 'value1'];
$obj2 = (object) ['value' => 'value2'];

View File

@@ -100,7 +100,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateFromChoicesSameValueClosure()
{
$choices = [1];
$closure = function () {};
$closure = static function () {};
$list1 = $this->factory->createListFromChoices($choices, $closure);
$list2 = $this->factory->createListFromChoices($choices, $closure);
@@ -114,21 +114,21 @@ class CachingFactoryDecoratorTest extends TestCase
{
$choices = [1];
$formType = new FormType();
$valueCallback = function () {};
$valueCallback = static function () {};
$list1 = $this->factory->createListFromChoices($choices, ChoiceList::value($formType, $valueCallback));
$list2 = $this->factory->createListFromChoices($choices, ChoiceList::value($formType, function () {}));
$list2 = $this->factory->createListFromChoices($choices, ChoiceList::value($formType, static function () {}));
$this->assertSame($list1, $list2);
self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, $valueCallback), $list1);
self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, function () {}), $list2);
self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, static function () {}), $list2);
}
public function testCreateFromChoicesDifferentValueClosure()
{
$choices = [1];
$closure1 = function () {};
$closure2 = function () {};
$closure1 = static function () {};
$closure2 = static function () {};
$list1 = $this->factory->createListFromChoices($choices, $closure1);
$list2 = $this->factory->createListFromChoices($choices, $closure2);
@@ -140,7 +140,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateFromChoicesSameFilterClosure()
{
$choices = [1];
$filter = function () {};
$filter = static function () {};
$list1 = $this->factory->createListFromChoices($choices, null, $filter);
$list2 = $this->factory->createListFromChoices($choices, null, $filter);
$lazyChoiceList = new LazyChoiceList(new FilterChoiceLoaderDecorator(new CallbackChoiceLoader(static fn () => $choices), $filter), null);
@@ -154,10 +154,10 @@ class CachingFactoryDecoratorTest extends TestCase
{
$choices = [1];
$formType = new FormType();
$filterCallback = function () {};
$filterCallback = static function () {};
$list1 = $this->factory->createListFromChoices($choices, null, ChoiceList::filter($formType, $filterCallback));
$list2 = $this->factory->createListFromChoices($choices, null, ChoiceList::filter($formType, function () {}));
$lazyChoiceList = new LazyChoiceList(new FilterChoiceLoaderDecorator(new CallbackChoiceLoader(static fn () => $choices), function () {}), null);
$list2 = $this->factory->createListFromChoices($choices, null, ChoiceList::filter($formType, static function () {}));
$lazyChoiceList = new LazyChoiceList(new FilterChoiceLoaderDecorator(new CallbackChoiceLoader(static fn () => $choices), static function () {}), null);
$this->assertSame($list1, $list2);
self::assertEqualsLazyChoiceList($lazyChoiceList, $list1);
@@ -167,11 +167,11 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateFromChoicesDifferentFilterClosure()
{
$choices = [1];
$closure1 = function () {};
$closure2 = function () {};
$closure1 = static function () {};
$closure2 = static function () {};
$list1 = $this->factory->createListFromChoices($choices, null, $closure1);
$list2 = $this->factory->createListFromChoices($choices, null, $closure2);
$lazyChoiceList = new LazyChoiceList(new FilterChoiceLoaderDecorator(new CallbackChoiceLoader(static fn () => $choices), function () {}), null);
$lazyChoiceList = new LazyChoiceList(new FilterChoiceLoaderDecorator(new CallbackChoiceLoader(static fn () => $choices), static function () {}), null);
$this->assertNotSame($list1, $list2);
self::assertEqualsLazyChoiceList($lazyChoiceList, $list1);
@@ -208,7 +208,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateFromLoaderSameValueClosure()
{
$loader = new ArrayChoiceLoader();
$closure = function () {};
$closure = static function () {};
$list1 = $this->factory->createListFromLoader($loader, $closure);
$list2 = $this->factory->createListFromLoader($loader, $closure);
@@ -221,20 +221,20 @@ class CachingFactoryDecoratorTest extends TestCase
{
$type = new FormType();
$loader = new ArrayChoiceLoader();
$closure = function () {};
$closure = static function () {};
$list1 = $this->factory->createListFromLoader(ChoiceList::loader($type, $loader), ChoiceList::value($type, $closure));
$list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), ChoiceList::value($type, function () {}));
$list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), ChoiceList::value($type, static function () {}));
$this->assertSame($list1, $list2);
self::assertEqualsLazyChoiceList(new LazyChoiceList($loader, $closure), $list1);
self::assertEqualsLazyChoiceList(new LazyChoiceList(new ArrayChoiceLoader(), function () {}), $list2);
self::assertEqualsLazyChoiceList(new LazyChoiceList(new ArrayChoiceLoader(), static function () {}), $list2);
}
public function testCreateFromLoaderDifferentValueClosure()
{
$loader = new ArrayChoiceLoader();
$closure1 = function () {};
$closure2 = function () {};
$closure1 = static function () {};
$closure2 = static function () {};
$this->assertNotSame($this->factory->createListFromLoader($loader, $closure1), $this->factory->createListFromLoader($loader, $closure2));
}
@@ -243,7 +243,7 @@ class CachingFactoryDecoratorTest extends TestCase
{
$loader = new ArrayChoiceLoader();
$type = new FormType();
$closure = function () {};
$closure = static function () {};
$list1 = $this->factory->createListFromLoader(ChoiceList::loader($type, $loader), null, $closure);
$list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), null, $closure);
@@ -256,20 +256,20 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateFromLoaderSameFilterClosureUseCache()
{
$type = new FormType();
$choiceFilter = ChoiceList::filter($type, function () {});
$choiceFilter = ChoiceList::filter($type, static function () {});
$list1 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), null, $choiceFilter);
$list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), null, $choiceFilter);
$this->assertSame($list1, $list2);
self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), function () {})), $list1);
self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), function () {})), $list2);
self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), static function () {})), $list1);
self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), static function () {})), $list2);
}
public function testCreateFromLoaderDifferentFilterClosure()
{
$type = new FormType();
$closure1 = function () {};
$closure2 = function () {};
$closure1 = static function () {};
$closure2 = static function () {};
$list1 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), null, $closure1);
$list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), null, $closure2);
@@ -318,7 +318,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewSamePreferredChoicesClosure()
{
$preferred = function () {};
$preferred = static function () {};
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, $preferred);
$view2 = $this->factory->createView($list, $preferred);
@@ -330,11 +330,11 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewSamePreferredChoicesClosureUseCache()
{
$preferredCallback = function () {};
$preferredCallback = static function () {};
$type = new FormType();
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, ChoiceList::preferred($type, $preferredCallback));
$view2 = $this->factory->createView($list, ChoiceList::preferred($type, function () {}));
$view2 = $this->factory->createView($list, ChoiceList::preferred($type, static function () {}));
$this->assertSame($view1, $view2);
$this->assertEquals(new ChoiceListView(), $view1);
@@ -343,8 +343,8 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewDifferentPreferredChoicesClosure()
{
$preferred1 = function () {};
$preferred2 = function () {};
$preferred1 = static function () {};
$preferred2 = static function () {};
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, $preferred1);
$view2 = $this->factory->createView($list, $preferred2);
@@ -356,7 +356,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewSameLabelClosure()
{
$labels = function () {};
$labels = static function () {};
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, null, $labels);
$view2 = $this->factory->createView($list, null, $labels);
@@ -368,11 +368,11 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewSameLabelClosureUseCache()
{
$labelsCallback = function () {};
$labelsCallback = static function () {};
$type = new FormType();
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, null, ChoiceList::label($type, $labelsCallback));
$view2 = $this->factory->createView($list, null, ChoiceList::label($type, function () {}));
$view2 = $this->factory->createView($list, null, ChoiceList::label($type, static function () {}));
$this->assertSame($view1, $view2);
$this->assertEquals(new ChoiceListView(), $view1);
@@ -381,8 +381,8 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewDifferentLabelClosure()
{
$labels1 = function () {};
$labels2 = function () {};
$labels1 = static function () {};
$labels2 = static function () {};
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, null, $labels1);
$view2 = $this->factory->createView($list, null, $labels2);
@@ -394,7 +394,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewSameIndexClosure()
{
$index = function () {};
$index = static function () {};
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, null, null, $index);
$view2 = $this->factory->createView($list, null, null, $index);
@@ -406,11 +406,11 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewSameIndexClosureUseCache()
{
$indexCallback = function () {};
$indexCallback = static function () {};
$type = new FormType();
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, null, null, ChoiceList::fieldName($type, $indexCallback));
$view2 = $this->factory->createView($list, null, null, ChoiceList::fieldName($type, function () {}));
$view2 = $this->factory->createView($list, null, null, ChoiceList::fieldName($type, static function () {}));
$this->assertSame($view1, $view2);
$this->assertEquals(new ChoiceListView(), $view1);
@@ -419,8 +419,8 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewDifferentIndexClosure()
{
$index1 = function () {};
$index2 = function () {};
$index1 = static function () {};
$index2 = static function () {};
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, null, null, $index1);
$view2 = $this->factory->createView($list, null, null, $index2);
@@ -432,7 +432,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewSameGroupByClosure()
{
$groupBy = function () {};
$groupBy = static function () {};
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, null, null, null, $groupBy);
$view2 = $this->factory->createView($list, null, null, null, $groupBy);
@@ -444,11 +444,11 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewSameGroupByClosureUseCache()
{
$groupByCallback = function () {};
$groupByCallback = static function () {};
$type = new FormType();
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, null, null, null, ChoiceList::groupBy($type, $groupByCallback));
$view2 = $this->factory->createView($list, null, null, null, ChoiceList::groupBy($type, function () {}));
$view2 = $this->factory->createView($list, null, null, null, ChoiceList::groupBy($type, static function () {}));
$this->assertSame($view1, $view2);
$this->assertEquals(new ChoiceListView(), $view1);
@@ -457,8 +457,8 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewDifferentGroupByClosure()
{
$groupBy1 = function () {};
$groupBy2 = function () {};
$groupBy1 = static function () {};
$groupBy2 = static function () {};
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, null, null, null, $groupBy1);
$view2 = $this->factory->createView($list, null, null, null, $groupBy2);
@@ -509,7 +509,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewSameAttributesClosure()
{
$attr = function () {};
$attr = static function () {};
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, null, null, null, null, $attr);
$view2 = $this->factory->createView($list, null, null, null, null, $attr);
@@ -521,11 +521,11 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewSameAttributesClosureUseCache()
{
$attrCallback = function () {};
$attrCallback = static function () {};
$type = new FormType();
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, null, null, null, null, ChoiceList::attr($type, $attrCallback));
$view2 = $this->factory->createView($list, null, null, null, null, ChoiceList::attr($type, function () {}));
$view2 = $this->factory->createView($list, null, null, null, null, ChoiceList::attr($type, static function () {}));
$this->assertSame($view1, $view2);
$this->assertEquals(new ChoiceListView(), $view1);
@@ -534,8 +534,8 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateViewDifferentAttributesClosure()
{
$attr1 = function () {};
$attr2 = function () {};
$attr1 = static function () {};
$attr2 = static function () {};
$list = new ArrayChoiceList([]);
$view1 = $this->factory->createView($list, null, null, null, null, $attr1);

View File

@@ -142,7 +142,7 @@ class DefaultChoiceListFactoryTest extends TestCase
{
$list = $this->factory->createListFromChoices(
['A' => $this->obj1, 'B' => $this->obj2, 'C' => $this->obj3, 'D' => $this->obj4],
fn ($object) => $object->value
static fn ($object) => $object->value
);
$this->assertObjectListWithCustomValues($list);
@@ -190,7 +190,7 @@ class DefaultChoiceListFactoryTest extends TestCase
'Group 1' => ['A' => $this->obj1, 'B' => $this->obj2],
'Group 2' => ['C' => $this->obj3, 'D' => $this->obj4],
],
fn ($object) => $object->value
static fn ($object) => $object->value
);
$this->assertObjectListWithCustomValues($list);
@@ -201,7 +201,7 @@ class DefaultChoiceListFactoryTest extends TestCase
$list = $this->factory->createListFromChoices(
['A' => $this->obj1, 'B' => $this->obj2, 'C' => $this->obj3, 'D' => $this->obj4, 'E' => null, 'F' => null],
null,
fn ($choice) => null !== $choice
static fn ($choice) => null !== $choice
);
$this->assertObjectListWithGeneratedValues($list);
@@ -217,7 +217,7 @@ class DefaultChoiceListFactoryTest extends TestCase
'Group 4' => [/* empty group should be filtered */],
],
null,
fn ($choice) => null !== $choice
static fn ($choice) => null !== $choice
);
$this->assertObjectListWithGeneratedValues($list);
@@ -233,7 +233,7 @@ class DefaultChoiceListFactoryTest extends TestCase
'Group 4' => [/* empty group should be filtered */],
]),
null,
fn ($choice) => null !== $choice
static fn ($choice) => null !== $choice
);
$this->assertObjectListWithGeneratedValues($list);
@@ -252,7 +252,7 @@ class DefaultChoiceListFactoryTest extends TestCase
{
$loader = new ArrayChoiceLoader();
$value = function () {};
$value = static function () {};
$list = $this->factory->createListFromLoader($loader, $value);
$this->assertEquals(new LazyChoiceList($loader, $value), $list);
@@ -260,7 +260,7 @@ class DefaultChoiceListFactoryTest extends TestCase
public function testCreateFromLoaderWithFilter()
{
$filter = function () {};
$filter = static function () {};
$list = $this->factory->createListFromLoader(new ArrayChoiceLoader(), null, $filter);
@@ -372,7 +372,7 @@ class DefaultChoiceListFactoryTest extends TestCase
$view = $this->factory->createView(
$this->list,
fn ($object) => $obj2 === $object || $obj3 === $object
static fn ($object) => $obj2 === $object || $obj3 === $object
);
$this->assertFlatView($view);
@@ -382,7 +382,7 @@ class DefaultChoiceListFactoryTest extends TestCase
{
$view = $this->factory->createView(
$this->list,
fn ($object, $key) => 'B' === $key || 'C' === $key
static fn ($object, $key) => 'B' === $key || 'C' === $key
);
$this->assertFlatView($view);
@@ -392,7 +392,7 @@ class DefaultChoiceListFactoryTest extends TestCase
{
$view = $this->factory->createView(
$this->list,
fn ($object, $key, $value) => '1' === $value || '2' === $value
static fn ($object, $key, $value) => '1' === $value || '2' === $value
);
$this->assertFlatView($view);
@@ -414,7 +414,7 @@ class DefaultChoiceListFactoryTest extends TestCase
$view = $this->factory->createView(
$this->list,
[$this->obj2, $this->obj3],
fn ($object) => $object->label
static fn ($object) => $object->label
);
$this->assertFlatView($view);
@@ -425,7 +425,7 @@ class DefaultChoiceListFactoryTest extends TestCase
$view = $this->factory->createView(
$this->list,
[$this->obj2, $this->obj3],
fn ($object, $key) => $key
static fn ($object, $key) => $key
);
$this->assertFlatView($view);
@@ -436,7 +436,7 @@ class DefaultChoiceListFactoryTest extends TestCase
$view = $this->factory->createView(
$this->list,
[$this->obj2, $this->obj3],
function ($object, $key, $value) {
static function ($object, $key, $value) {
switch ($value) {
case '0': return 'A';
case '1': return 'B';
@@ -467,7 +467,7 @@ class DefaultChoiceListFactoryTest extends TestCase
$this->list,
[$this->obj2, $this->obj3],
null, // label
fn ($object) => $object->index
static fn ($object) => $object->index
);
$this->assertFlatViewWithCustomIndices($view);
@@ -479,7 +479,7 @@ class DefaultChoiceListFactoryTest extends TestCase
$this->list,
[$this->obj2, $this->obj3],
null, // label
function ($object, $key) {
static function ($object, $key) {
switch ($key) {
case 'A': return 'w';
case 'B': return 'x';
@@ -498,7 +498,7 @@ class DefaultChoiceListFactoryTest extends TestCase
$this->list,
[$this->obj2, $this->obj3],
null, // label
function ($object, $key, $value) {
static function ($object, $key, $value) {
switch ($value) {
case '0': return 'w';
case '1': return 'x';
@@ -589,7 +589,7 @@ class DefaultChoiceListFactoryTest extends TestCase
[$this->obj2, $this->obj3],
null, // label
null, // index
fn ($object) => $obj1 === $object || $obj2 === $object ? 'Group 1' : 'Group 2'
static fn ($object) => $obj1 === $object || $obj2 === $object ? 'Group 1' : 'Group 2'
);
$this->assertGroupedView($view);
@@ -602,7 +602,7 @@ class DefaultChoiceListFactoryTest extends TestCase
[$this->obj2, $this->obj3],
null, // label
null, // index
fn ($object, $key) => 'A' === $key || 'B' === $key ? 'Group 1' : 'Group 2'
static fn ($object, $key) => 'A' === $key || 'B' === $key ? 'Group 1' : 'Group 2'
);
$this->assertGroupedView($view);
@@ -615,7 +615,7 @@ class DefaultChoiceListFactoryTest extends TestCase
[$this->obj2, $this->obj3],
null, // label
null, // index
fn ($object, $key, $value) => '0' === $value || '1' === $value ? 'Group 1' : 'Group 2'
static fn ($object, $key, $value) => '0' === $value || '1' === $value ? 'Group 1' : 'Group 2'
);
$this->assertGroupedView($view);
@@ -674,7 +674,7 @@ class DefaultChoiceListFactoryTest extends TestCase
null, // label
null, // index
null, // group
fn ($object) => $object->attr
static fn ($object) => $object->attr
);
$this->assertFlatViewWithAttr($view);
@@ -688,7 +688,7 @@ class DefaultChoiceListFactoryTest extends TestCase
null, // label
null, // index
null, // group
fn ($object, $key) => match ($key) {
static fn ($object, $key) => match ($key) {
'B' => ['attr1' => 'value1'],
'C' => ['attr2' => 'value2'],
default => [],
@@ -706,7 +706,7 @@ class DefaultChoiceListFactoryTest extends TestCase
null, // label
null, // index
null, // group
fn ($object, $key, $value) => match ($value) {
static fn ($object, $key, $value) => match ($value) {
'1' => ['attr1' => 'value1'],
'2' => ['attr2' => 'value2'],
default => [],
@@ -803,7 +803,7 @@ class DefaultChoiceListFactoryTest extends TestCase
null, // index
null, // group
null, // attr
fn ($object) => $object->labelTranslationParameters
static fn ($object) => $object->labelTranslationParameters
);
$this->assertFlatViewWithlabelTranslationParameters($view);
@@ -818,7 +818,7 @@ class DefaultChoiceListFactoryTest extends TestCase
null, // index
null, // group
null, // attr
fn ($object, $key) => match ($key) {
static fn ($object, $key) => match ($key) {
'D' => ['%placeholder1%' => 'value1'],
default => [],
}
@@ -836,7 +836,7 @@ class DefaultChoiceListFactoryTest extends TestCase
null, // index
null, // group
null, // attr
fn ($object, $key, $value) => match ($value) {
static fn ($object, $key, $value) => match ($value) {
'3' => ['%placeholder1%' => 'value1'],
default => [],
}

View File

@@ -24,7 +24,7 @@ class LazyChoiceListTest extends TestCase
{
$choices = ['RESULT'];
$calls = 0;
$list = new LazyChoiceList(new ArrayChoiceLoader($choices), function ($choice) use ($choices, &$calls) {
$list = new LazyChoiceList(new ArrayChoiceLoader($choices), static function ($choice) use ($choices, &$calls) {
++$calls;
return array_search($choice, $choices);
@@ -38,7 +38,7 @@ class LazyChoiceListTest extends TestCase
public function testGetValuesLoadsLoadedListOnFirstCall()
{
$calls = 0;
$list = new LazyChoiceList(new ArrayChoiceLoader(['RESULT']), function ($choice) use (&$calls) {
$list = new LazyChoiceList(new ArrayChoiceLoader(['RESULT']), static function ($choice) use (&$calls) {
++$calls;
return $choice;
@@ -52,7 +52,7 @@ class LazyChoiceListTest extends TestCase
public function testGetStructuredValuesLoadsLoadedListOnFirstCall()
{
$calls = 0;
$list = new LazyChoiceList(new ArrayChoiceLoader(['RESULT']), function ($choice) use (&$calls) {
$list = new LazyChoiceList(new ArrayChoiceLoader(['RESULT']), static function ($choice) use (&$calls) {
++$calls;
return $choice;
@@ -71,7 +71,7 @@ class LazyChoiceListTest extends TestCase
'b' => 'bar',
'c' => 'baz',
];
$list = new LazyChoiceList(new ArrayChoiceLoader($choices), function ($choice) use (&$calls) {
$list = new LazyChoiceList(new ArrayChoiceLoader($choices), static function ($choice) use (&$calls) {
++$calls;
return $choice;
@@ -90,7 +90,7 @@ class LazyChoiceListTest extends TestCase
'b' => 'bar',
'c' => 'baz',
];
$list = new LazyChoiceList(new ArrayChoiceLoader($choices), function ($choice) use ($choices, &$calls) {
$list = new LazyChoiceList(new ArrayChoiceLoader($choices), static function ($choice) use ($choices, &$calls) {
++$calls;
return array_search($choice, $choices);
@@ -108,7 +108,7 @@ class LazyChoiceListTest extends TestCase
'b' => 'bar',
'c' => 'baz',
];
$list = new LazyChoiceList(new ArrayChoiceLoader($choices), fn ($choice) => array_search($choice, $choices));
$list = new LazyChoiceList(new ArrayChoiceLoader($choices), static fn ($choice) => array_search($choice, $choices));
// load choice list
$list->getChoices();
@@ -124,7 +124,7 @@ class LazyChoiceListTest extends TestCase
'b' => 'bar',
'c' => 'baz',
];
$list = new LazyChoiceList(new ArrayChoiceLoader($choices), fn ($choice) => array_search($choice, $choices));
$list = new LazyChoiceList(new ArrayChoiceLoader($choices), static fn ($choice) => array_search($choice, $choices));
// load choice list
$list->getChoices();

View File

@@ -29,8 +29,8 @@ class CallbackChoiceLoaderTest extends TestCase
public static function setUpBeforeClass(): void
{
self::$loader = new CallbackChoiceLoader(fn () => self::$choices);
self::$value = fn ($choice) => $choice->value ?? null;
self::$loader = new CallbackChoiceLoader(static fn () => self::$choices);
self::$value = static fn ($choice) => $choice->value ?? null;
self::$choices = [
(object) ['value' => 'choice_one'],
(object) ['value' => 'choice_two'],
@@ -46,7 +46,7 @@ class CallbackChoiceLoaderTest extends TestCase
public function testLoadChoicesOnlyOnce()
{
$calls = 0;
$loader = new CallbackChoiceLoader(function () use (&$calls) {
$loader = new CallbackChoiceLoader(static function () use (&$calls) {
++$calls;
return [1];
@@ -73,7 +73,7 @@ class CallbackChoiceLoaderTest extends TestCase
(object) ['id' => 3],
];
$value = fn ($item) => $item->id;
$value = static fn ($item) => $item->id;
$this->assertSame(['2', '3'], self::$loader->loadValuesForChoices($choices, $value));
}

View File

@@ -23,7 +23,7 @@ class FilterChoiceLoaderDecoratorTest extends TestCase
public function testLoadChoiceList()
{
$filter = fn ($choice) => 0 === $choice % 2;
$filter = static fn ($choice) => 0 === $choice % 2;
$loader = new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(range(1, 4)), $filter);
@@ -32,7 +32,7 @@ class FilterChoiceLoaderDecoratorTest extends TestCase
public function testLoadChoiceListWithGroupedChoices()
{
$filter = fn ($choice) => $choice < 9 && 0 === $choice % 2;
$filter = static fn ($choice) => $choice < 9 && 0 === $choice % 2;
$loader = new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(['units' => range(1, 9), 'tens' => range(10, 90, 10)]), $filter);
@@ -48,7 +48,7 @@ class FilterChoiceLoaderDecoratorTest extends TestCase
public function testLoadChoiceListMixedWithGroupedAndNonGroupedChoices()
{
$filter = fn ($choice) => 0 === $choice % 2;
$filter = static fn ($choice) => 0 === $choice % 2;
$choices = array_merge(range(1, 9), ['grouped' => range(10, 40, 5)]);
$loader = new FilterChoiceLoaderDecorator(new ArrayChoiceLoader($choices), $filter);
@@ -71,7 +71,7 @@ class FilterChoiceLoaderDecoratorTest extends TestCase
{
$evenValues = [1 => '2', 3 => '4'];
$filter = fn ($choice) => 0 === $choice % 2;
$filter = static fn ($choice) => 0 === $choice % 2;
$loader = new FilterChoiceLoaderDecorator(new ArrayChoiceLoader([range(1, 4)]), $filter);
@@ -83,7 +83,7 @@ class FilterChoiceLoaderDecoratorTest extends TestCase
$evenChoices = [1 => 2, 3 => 4];
$values = array_map('strval', range(1, 4));
$filter = fn ($choice) => 0 === $choice % 2;
$filter = static fn ($choice) => 0 === $choice % 2;
$loader = new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(range(1, 4)), $filter);

View File

@@ -30,8 +30,8 @@ class IntlCallbackChoiceLoaderTest extends TestCase
public static function setUpBeforeClass(): void
{
self::$loader = new IntlCallbackChoiceLoader(fn () => self::$choices);
self::$value = fn ($choice) => $choice->value ?? null;
self::$loader = new IntlCallbackChoiceLoader(static fn () => self::$choices);
self::$value = static fn ($choice) => $choice->value ?? null;
self::$choices = [
(object) ['value' => 'choice_one'],
(object) ['value' => 'choice_two'],
@@ -47,7 +47,7 @@ class IntlCallbackChoiceLoaderTest extends TestCase
public function testLoadChoicesOnlyOnce()
{
$calls = 0;
$loader = new IntlCallbackChoiceLoader(function () use (&$calls) {
$loader = new IntlCallbackChoiceLoader(static function () use (&$calls) {
++$calls;
return self::$choices;

View File

@@ -269,7 +269,7 @@ class DebugCommandTest extends TestCase
$coreExtension = new CoreExtension();
$loadTypesRefMethod = (new \ReflectionObject($coreExtension))->getMethod('loadTypes');
$coreTypes = $loadTypesRefMethod->invoke($coreExtension);
$coreTypes = array_map(fn (FormTypeInterface $type) => $type::class, $coreTypes);
$coreTypes = array_map(static fn (FormTypeInterface $type) => $type::class, $coreTypes);
sort($coreTypes);
return $coreTypes;
@@ -293,14 +293,18 @@ class FooType extends AbstractType
$resolver->setRequired('foo');
$resolver->setDefined('bar');
$resolver->setDeprecated('bar', 'vendor/package', '1.1');
$resolver->setDefault('empty_data', function (Options $options) {
$resolver->setDefault('empty_data', static function (Options $options) {
$foo = $options['foo'];
return fn (FormInterface $form) => $form->getConfig()->getCompound() ? [$foo] : $foo;
return static fn (FormInterface $form) => $form->getConfig()->getCompound() ? [$foo] : $foo;
});
$resolver->setAllowedTypes('foo', 'string');
$resolver->setAllowedValues('foo', ['bar', 'baz']);
$resolver->setNormalizer('foo', fn (Options $options, $value) => (string) $value);
$resolver->setNormalizer('foo', function (Options $options, $value) {
\assert(null !== $this); // explicitly test non-static normalizer
return (string) $value;
});
$resolver->setInfo('foo', 'Info');
}
}

View File

@@ -407,7 +407,7 @@ class CompoundFormTest extends TestCase
$child = $this->getBuilder('child')
->setCompound(true)
->setDataMapper(new DataMapper())
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($form, $childToBeAdded) {
->addEventListener(FormEvents::PRE_SET_DATA, static function (FormEvent $event) use ($form, $childToBeAdded) {
$form->remove('removed');
$form->add($childToBeAdded);
})
@@ -477,7 +477,7 @@ class CompoundFormTest extends TestCase
$childToBeRemoved = $this->createForm('removed');
$childToBeAdded = $this->createForm('added');
$child = $this->getBuilder('child')
->addEventListener(FormEvents::PRE_SUBMIT, function () use ($form, $childToBeAdded) {
->addEventListener(FormEvents::PRE_SUBMIT, static function () use ($form, $childToBeAdded) {
$form->remove('removed');
$form->add($childToBeAdded);
})

View File

@@ -170,15 +170,19 @@ class FooType extends AbstractType
$resolver->setRequired('foo');
$resolver->setDefined('bar');
$resolver->setDeprecated('bar', 'vendor/package', '1.1');
$resolver->setDefault('empty_data', function (Options $options, $value) {
$resolver->setDefault('empty_data', static function (Options $options, $value) {
$foo = $options['foo'];
return fn (FormInterface $form) => $form->getConfig()->getCompound() ? [$foo] : $foo;
return static fn (FormInterface $form) => $form->getConfig()->getCompound() ? [$foo] : $foo;
});
$resolver->setAllowedTypes('foo', 'string');
$resolver->setAllowedValues('foo', ['bar', 'baz']);
$resolver->setNormalizer('foo', fn (Options $options, $value) => (string) $value);
$resolver->setOptions('baz', function (OptionsResolver $baz) {
$resolver->setNormalizer('foo', function (Options $options, $value) {
\assert(null !== $this); // explicitly test non-static normalizer
return (string) $value;
});
$resolver->setOptions('baz', static function (OptionsResolver $baz) {
$baz->setRequired('foo');
$baz->setDefaults(['foo' => true, 'bar' => true]);
});

View File

@@ -299,7 +299,7 @@ class FormPassTest extends TestCase
'my.type',
'stdClass',
'form.type',
function (ContainerBuilder $container) {
static function (ContainerBuilder $container) {
$formTypes = $container->getDefinition('form.extension')->getArgument(0);
self::assertInstanceOf(Reference::class, $formTypes);
@@ -317,7 +317,7 @@ class FormPassTest extends TestCase
'my.type_extension',
Type1TypeExtension::class,
'form.type_extension',
function (ContainerBuilder $container) {
static function (ContainerBuilder $container) {
self::assertEquals(
['Symfony\Component\Form\Extension\Core\Type\FormType' => new IteratorArgument([new Reference('my.type_extension')])],
$container->getDefinition('form.extension')->getArgument(1)
@@ -325,7 +325,7 @@ class FormPassTest extends TestCase
},
['extended_type' => 'Symfony\Component\Form\Extension\Core\Type\FormType'],
],
['my.guesser', 'stdClass', 'form.type_guesser', function (ContainerBuilder $container) {
['my.guesser', 'stdClass', 'form.type_guesser', static function (ContainerBuilder $container) {
self::assertEquals(new IteratorArgument([new Reference('my.guesser')]), $container->getDefinition('form.extension')->getArgument(2));
}],
];

View File

@@ -412,7 +412,7 @@ class DataMapperTest extends TestCase
->getFormFactory()
->createBuilder(FormType::class, $person)
->add('name', TextType::class, [
'getter' => function (DummyPerson $person) {
'getter' => static function (DummyPerson $person) {
return $person->myName();
},
])

View File

@@ -292,7 +292,7 @@ class ResizeFormListenerTest extends TestCase
$this->builder->setData(['0' => ['name' => 'John'], '1' => ['name' => 'Jane']]);
$this->builder->add('0', NestedType::class);
$this->builder->add('1', NestedType::class);
$callback = fn ($data) => empty($data['name']);
$callback = static fn ($data) => empty($data['name']);
$this->builder->addEventSubscriber(new ResizeFormListener(NestedType::class, [], false, true, $callback));
$form = $this->builder->getForm();

View File

@@ -146,8 +146,8 @@ class CheckboxTypeTest extends BaseTypeTestCase
{
// present a binary status field as a checkbox
$transformer = new CallbackTransformer(
fn ($value) => 'checked' == $value,
fn ($value) => $value ? 'checked' : 'unchecked'
static fn ($value) => 'checked' == $value,
static fn ($value) => $value ? 'checked' : 'unchecked'
);
$form = $this->factory->createBuilder(static::TESTED_TYPE)

View File

@@ -539,7 +539,7 @@ class ChoiceTypeTest extends BaseTypeTestCase
'choices' => [
'Empty' => 'EMPTY_CHOICE',
],
'choice_value' => fn () => '',
'choice_value' => static fn () => '',
]);
$form->submit('');
@@ -2206,7 +2206,7 @@ class ChoiceTypeTest extends BaseTypeTestCase
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
'choices' => $this->choices,
'choice_filter' => fn ($choice) => \in_array($choice, range('a', 'c'), true),
'choice_filter' => static fn ($choice) => \in_array($choice, range('a', 'c'), true),
]);
$this->assertEquals([
@@ -2220,7 +2220,7 @@ class ChoiceTypeTest extends BaseTypeTestCase
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
'choices' => $this->groupedChoices,
'choice_filter' => fn ($choice) => \in_array($choice, range('a', 'c'), true),
'choice_filter' => static fn ($choice) => \in_array($choice, range('a', 'c'), true),
]);
$this->assertEquals(['Symfony' => new ChoiceGroupView('Symfony', [
@@ -2234,7 +2234,7 @@ class ChoiceTypeTest extends BaseTypeTestCase
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
'choice_loader' => new CallbackChoiceLoader(fn () => $this->choices),
'choice_filter' => fn ($choice) => \in_array($choice, range('a', 'c'), true),
'choice_filter' => static fn ($choice) => \in_array($choice, range('a', 'c'), true),
]);
$this->assertEquals([
@@ -2246,7 +2246,7 @@ class ChoiceTypeTest extends BaseTypeTestCase
public function testWithSameLoaderAndDifferentChoiceValueCallbacks()
{
$choiceLoader = new CallbackChoiceLoader(fn () => [1, 2, 3]);
$choiceLoader = new CallbackChoiceLoader(static fn () => [1, 2, 3]);
$view = $this->factory->create(FormTypeTest::TESTED_TYPE)
->add('choice_one', self::TESTED_TYPE, [
@@ -2254,7 +2254,7 @@ class ChoiceTypeTest extends BaseTypeTestCase
])
->add('choice_two', self::TESTED_TYPE, [
'choice_loader' => $choiceLoader,
'choice_value' => fn ($choice) => $choice ? (string) $choice * 10 : '',
'choice_value' => static fn ($choice) => $choice ? (string) $choice * 10 : '',
])
->createView()
;
@@ -2281,7 +2281,7 @@ class ChoiceTypeTest extends BaseTypeTestCase
public function testChoiceLazyLoadsAndRendersNothingWhenNoDataSet()
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
'choice_loader' => new CallbackChoiceLoader(fn () => ['a' => 'A', 'b' => 'B']),
'choice_loader' => new CallbackChoiceLoader(static fn () => ['a' => 'A', 'b' => 'B']),
'choice_lazy' => true,
]);
@@ -2295,7 +2295,7 @@ class ChoiceTypeTest extends BaseTypeTestCase
public function testChoiceLazyLoadsAndRendersOnlyDataSetViaDefault()
{
$form = $this->factory->create(static::TESTED_TYPE, 'A', [
'choice_loader' => new CallbackChoiceLoader(fn () => ['a' => 'A', 'b' => 'B']),
'choice_loader' => new CallbackChoiceLoader(static fn () => ['a' => 'A', 'b' => 'B']),
'choice_lazy' => true,
]);
@@ -2310,7 +2310,7 @@ class ChoiceTypeTest extends BaseTypeTestCase
public function testChoiceLazyLoadsAndRendersOnlyDataSetViaSubmit()
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
'choice_loader' => new CallbackChoiceLoader(fn () => ['a' => 'A', 'b' => 'B']),
'choice_loader' => new CallbackChoiceLoader(static fn () => ['a' => 'A', 'b' => 'B']),
'choice_lazy' => true,
]);
@@ -2326,7 +2326,7 @@ class ChoiceTypeTest extends BaseTypeTestCase
public function testChoiceLazyErrorWhenInvalidSubmitData()
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
'choice_loader' => new CallbackChoiceLoader(fn () => ['a' => 'A', 'b' => 'B']),
'choice_loader' => new CallbackChoiceLoader(static fn () => ['a' => 'A', 'b' => 'B']),
'choice_lazy' => true,
]);
@@ -2343,7 +2343,7 @@ class ChoiceTypeTest extends BaseTypeTestCase
public function testChoiceLazyMultipleWithDefaultData()
{
$form = $this->factory->create(static::TESTED_TYPE, ['A', 'B'], [
'choice_loader' => new CallbackChoiceLoader(fn () => ['a' => 'A', 'b' => 'B', 'c' => 'C']),
'choice_loader' => new CallbackChoiceLoader(static fn () => ['a' => 'A', 'b' => 'B', 'c' => 'C']),
'choice_lazy' => true,
'multiple' => true,
]);
@@ -2360,7 +2360,7 @@ class ChoiceTypeTest extends BaseTypeTestCase
public function testChoiceLazyMultipleWithSubmittedData()
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
'choice_loader' => new CallbackChoiceLoader(fn () => ['a' => 'A', 'b' => 'B', 'c' => 'C']),
'choice_loader' => new CallbackChoiceLoader(static fn () => ['a' => 'A', 'b' => 'B', 'c' => 'C']),
'choice_lazy' => true,
'multiple' => true,
]);

View File

@@ -40,7 +40,7 @@ class ChoiceTypeTranslationTest extends TypeTestCase
{
$translator = $this->createStub(TranslatorInterface::class);
$translator->method('trans')
->willReturnCallback(fn ($key, $params) => strtr(\sprintf('Translation of: %s', $key), $params)
->willReturnCallback(static fn ($key, $params) => strtr(\sprintf('Translation of: %s', $key), $params)
);
return array_merge(parent::getExtensions(), [new CoreExtension(null, null, $translator)]);

View File

@@ -121,7 +121,7 @@ class CollectionTypeTest extends BaseTypeTestCase
$form = $this->factory->create(static::TESTED_TYPE, null, [
'entry_type' => AuthorType::class,
'allow_delete' => true,
'delete_empty' => fn (?Author $obj = null) => null === $obj || !$obj->firstName,
'delete_empty' => static fn (?Author $obj = null) => null === $obj || !$obj->firstName,
]);
$form->setData([new Author('Bob'), new Author('Alice')]);
@@ -142,7 +142,7 @@ class CollectionTypeTest extends BaseTypeTestCase
'entry_options' => ['data_class' => null],
'allow_add' => true,
'allow_delete' => true,
'delete_empty' => fn ($author) => empty($author['firstName']),
'delete_empty' => static fn ($author) => empty($author['firstName']),
]);
$form->setData([['firstName' => 'first', 'lastName' => 'last']]);
$form->submit([

View File

@@ -438,8 +438,8 @@ class FormTypeTest extends BaseTypeTestCase
$builder = $this->factory->createBuilder(static::TESTED_TYPE, $author);
$builder->add('referenceCopy', static::TESTED_TYPE);
$builder->get('referenceCopy')->addViewTransformer(new CallbackTransformer(
function () {},
fn ($value) => // reverseTransform
static function () {},
static fn ($value) => // reverseTransform
'foobar'
));
$form = $builder->getForm();
@@ -462,8 +462,8 @@ class FormTypeTest extends BaseTypeTestCase
$builder->setData($author);
$builder->add('referenceCopy', static::TESTED_TYPE);
$builder->get('referenceCopy')->addViewTransformer(new CallbackTransformer(
function () {},
fn ($value) => // reverseTransform
static function () {},
static fn ($value) => // reverseTransform
$ref2
));
$form = $builder->getForm();

View File

@@ -311,7 +311,7 @@ class FormDataCollectorTest extends TestCase
$form1View = new FormView();
$form2View = new FormView();
$child1View = new FormView();
$child1View->vars['is_selected'] = fn ($choice, array $values) => \in_array($choice, $values, true);
$child1View->vars['is_selected'] = static fn ($choice, array $values) => \in_array($choice, $values, true);
$form1->add($child1);
$form2->add($child1);

View File

@@ -371,8 +371,8 @@ class FormDataExtractorTest extends TestCase
{
$form = $this->createBuilder('name')
->addModelTransformer(new CallbackTransformer(
function () {},
function () {
static function () {},
static function () {
throw new TransformationFailedException('Fail!');
}
))

View File

@@ -44,8 +44,8 @@ class TextTypeHtmlSanitizerExtensionTest extends TypeTestCase
return array_merge(parent::getExtensions(), [
new HtmlSanitizerExtension(new ServiceLocator([
'foo' => fn () => $fooSanitizer,
'bar' => fn () => $barSanitizer,
'foo' => static fn () => $fooSanitizer,
'bar' => static fn () => $barSanitizer,
]), 'foo'),
]);
}

View File

@@ -114,7 +114,7 @@ class PasswordTypePasswordHasherExtensionTest extends TypeTestCase
$form = $this->factory
->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, [
'data_class' => User::class,
'empty_data' => function () use ($user) {
'empty_data' => static function () use ($user) {
return $user;
},
])

View File

@@ -439,16 +439,16 @@ class FormValidatorFunctionalTest extends TestCase
->add('field1')
->add('field2')
->addModelTransformer(new CallbackTransformer(
function () {
static function () {
},
function () {
static function () {
throw new TransformationFailedException('This value is invalid.');
}
));
$formBuilder->get('field2')->addModelTransformer(new CallbackTransformer(
function () {
static function () {
},
function () {
static function () {
throw new TransformationFailedException('This value is invalid.');
}
));

View File

@@ -443,7 +443,7 @@ class FormValidatorTest extends ConstraintValidatorTestCase
public function testHandleClosureValidationGroups()
{
$object = new \stdClass();
$options = ['validation_groups' => fn (FormInterface $form) => ['group1', 'group2']];
$options = ['validation_groups' => static fn (FormInterface $form) => ['group1', 'group2']];
$form = $this->getCompoundForm($object, $options);
$form->submit([]);
@@ -555,7 +555,7 @@ class FormValidatorTest extends ConstraintValidatorTestCase
$object = new \stdClass();
$parentOptions = [
'validation_groups' => fn () => ['group1', 'group2'],
'validation_groups' => static fn () => ['group1', 'group2'],
];
$parent = $this->getBuilder('parent', null, $parentOptions)
->setCompound(true)

View File

@@ -76,7 +76,7 @@ abstract class BaseValidatorExtensionTestCase extends TypeTestCase
public function testValidationGroupsCanBeSetToClosure()
{
$form = $this->createForm([
'validation_groups' => function (FormInterface $form) { },
'validation_groups' => static function (FormInterface $form) { },
]);
$this->assertIsCallable($form->getConfig()->getOption('validation_groups'));

View File

@@ -34,7 +34,7 @@ class UploadValidatorExtensionTest extends TypeTestCase
$resolver = new OptionsResolver();
$resolver->setDefault('post_max_size_message', 'old max {{ max }}!');
$resolver->setDefault('upload_max_size_message', fn (Options $options) => fn () => $options['post_max_size_message']);
$resolver->setDefault('upload_max_size_message', static fn (Options $options) => static fn () => $options['post_max_size_message']);
$extension->configureOptions($resolver);
$options = $resolver->resolve();

View File

@@ -336,7 +336,7 @@ class FormFlowTest extends TestCase
'validate' => false,
'validation_groups' => false,
'clear_submission' => false,
'include_if' => fn (FormFlowCursor $cursor) => $cursor->canMoveBack(),
'include_if' => static fn (FormFlowCursor $cursor) => $cursor->canMoveBack(),
]);
self::assertSame('professional', $flow->getCursor()->getCurrentStep());
@@ -885,7 +885,7 @@ class FormFlowTest extends TestCase
{
$flow = $this->factory->create(UserSignUpType::class, new UserSignUp());
$flow->get('navigator')->add('next', NextFlowType::class, [
'handler' => function (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) {
'handler' => static function (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) {
$flow->addError(new FormError('Action error'));
},
]);

View File

@@ -42,7 +42,7 @@ class TranslationFilesTest extends TestCase
public static function provideTranslationFiles()
{
return array_map(
fn ($filePath) => (array) $filePath,
static fn ($filePath) => (array) $filePath,
glob(\dirname(__DIR__, 2).'/Resources/translations/*.xlf')
);
}

View File

@@ -545,7 +545,7 @@ class SimpleFormTest extends TestCase
$config
->setData('default')
->setDataLocked(true)
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
->addEventListener(FormEvents::PRE_SET_DATA, static function (FormEvent $event) {
$event->setData('foobar');
});
$form = new Form($config);
@@ -909,7 +909,7 @@ class SimpleFormTest extends TestCase
$this->expectExceptionMessage('A cycle was detected. Listeners to the PRE_SET_DATA event must not call setData(). You should call setData() on the FormEvent object instead.');
// Cycle detection to prevent endless loops
$config = new FormConfigBuilder('name', 'stdClass', new EventDispatcher());
$config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$config->addEventListener(FormEvents::PRE_SET_DATA, static function (FormEvent $event) {
$event->getForm()->setData('bar');
});
$form = new Form($config);
@@ -922,7 +922,7 @@ class SimpleFormTest extends TestCase
$called = 0;
$child = $this->getBuilder('child');
$child->addEventListener(FormEvents::PRE_SUBMIT, function () use (&$called) {
$child->addEventListener(FormEvents::PRE_SUBMIT, static function () use (&$called) {
++$called;
});
@@ -1033,7 +1033,7 @@ class SimpleFormTest extends TestCase
{
$called = 0;
$form = $this->getBuilder()
->addEventListener(FormEvents::SUBMIT, function () use (&$called) {
->addEventListener(FormEvents::SUBMIT, static function () use (&$called) {
++$called;
})
->setInheritData(true)
@@ -1071,7 +1071,7 @@ class SimpleFormTest extends TestCase
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getData() if the form data has not already been set. You should call getData() on the FormEvent object instead.');
$config = new FormConfigBuilder('name', 'stdClass', new EventDispatcher());
$config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$config->addEventListener(FormEvents::PRE_SET_DATA, static function (FormEvent $event) {
$event->getForm()->getData();
});
$form = new Form($config);
@@ -1084,7 +1084,7 @@ class SimpleFormTest extends TestCase
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getNormData() if the form data has not already been set.');
$config = new FormConfigBuilder('name', 'stdClass', new EventDispatcher());
$config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$config->addEventListener(FormEvents::PRE_SET_DATA, static function (FormEvent $event) {
$event->getForm()->getNormData();
});
$form = new Form($config);
@@ -1097,7 +1097,7 @@ class SimpleFormTest extends TestCase
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getViewData() if the form data has not already been set.');
$config = new FormConfigBuilder('name', 'stdClass', new EventDispatcher());
$config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$config->addEventListener(FormEvents::PRE_SET_DATA, static function (FormEvent $event) {
$event->getForm()->getViewData();
});
$form = new Form($config);
@@ -1109,12 +1109,12 @@ class SimpleFormTest extends TestCase
{
$config = new FormConfigBuilder('foo', null, new EventDispatcher());
$config->setIsEmptyCallback(fn ($modelData): bool => 'ccc' === $modelData);
$config->setIsEmptyCallback(static fn ($modelData): bool => 'ccc' === $modelData);
$form = new Form($config);
$form->setData('ccc');
$this->assertTrue($form->isEmpty());
$config->setIsEmptyCallback(fn (): bool => false);
$config->setIsEmptyCallback(static fn (): bool => false);
$form = new Form($config);
$form->setData(null);
$this->assertFalse($form->isEmpty());