Skip to content

Commit 956da84

Browse files
minor #47672 Leverage First-class callable syntax (tigitz)
This PR was merged into the 6.2 branch. Discussion ---------- Leverage First-class callable syntax | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | - | License | MIT | Doc PR | - ### Rationale https://wiki.php.net/rfc/first_class_callable_syntax Mainly: > The advantage is that the new syntax is accessible to static analysis, and respects the scope at the point where the callable is created. I'd argue that it also improves readability and IDE color syntax also helps: ![image](https://user-images.githubusercontent.com/1524501/191912084-7ee933c5-dda1-4176-86f1-cd6511c58aa4.png) I've manually reviewed each changes and discarded some of them where `[Foo::class, 'method']` was intended to be tested with this specific syntax Commits ------- 26d9ce9520 Leverage First-class callable syntax
2 parents 322f18a + 33bae57 commit 956da84

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

Extension/DataCollector/FormDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ protected function getCasters(): array
235235
Caster::PREFIX_VIRTUAL.'type_class' => new ClassStub(\get_class($f->getConfig()->getType()->getInnerType())),
236236
];
237237
},
238-
FormView::class => [StubCaster::class, 'cutInternals'],
238+
FormView::class => StubCaster::cutInternals(...),
239239
ConstraintViolationInterface::class => function (ConstraintViolationInterface $v, array $a) {
240240
return [
241241
Caster::PREFIX_VIRTUAL.'root' => $v->getRoot(),

Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function testCreateFromChoicesFlatValuesAsCallable()
141141
{
142142
$list = $this->factory->createListFromChoices(
143143
['A' => $this->obj1, 'B' => $this->obj2, 'C' => $this->obj3, 'D' => $this->obj4],
144-
[$this, 'getValue']
144+
$this->getValue(...)
145145
);
146146

147147
$this->assertObjectListWithCustomValues($list);
@@ -186,7 +186,7 @@ public function testCreateFromChoicesGroupedValuesAsCallable()
186186
'Group 1' => ['A' => $this->obj1, 'B' => $this->obj2],
187187
'Group 2' => ['C' => $this->obj3, 'D' => $this->obj4],
188188
],
189-
[$this, 'getValue']
189+
$this->getValue(...)
190190
);
191191

192192
$this->assertObjectListWithCustomValues($list);
@@ -335,7 +335,7 @@ public function testCreateViewFlatPreferredChoiceGroupsSameOrder()
335335
[$this->obj4, $this->obj2, $this->obj1, $this->obj3],
336336
null, // label
337337
null, // index
338-
[$this, 'getGroup']
338+
$this->getGroup(...)
339339
);
340340

341341
$preferredLabels = array_map(static function (ChoiceGroupView $groupView): array {
@@ -380,7 +380,7 @@ public function testCreateViewFlatPreferredChoicesAsCallable()
380380
{
381381
$view = $this->factory->createView(
382382
$this->list,
383-
[$this, 'isPreferred']
383+
$this->isPreferred(...)
384384
);
385385

386386
$this->assertFlatView($view);
@@ -430,7 +430,7 @@ public function testCreateViewFlatLabelAsCallable()
430430
$view = $this->factory->createView(
431431
$this->list,
432432
[$this->obj2, $this->obj3],
433-
[$this, 'getLabel']
433+
$this->getLabel(...)
434434
);
435435

436436
$this->assertFlatView($view);
@@ -486,7 +486,7 @@ public function testCreateViewFlatIndexAsCallable()
486486
$this->list,
487487
[$this->obj2, $this->obj3],
488488
null, // label
489-
[$this, 'getFormIndex']
489+
$this->getFormIndex(...)
490490
);
491491

492492
$this->assertFlatViewWithCustomIndices($view);
@@ -580,7 +580,7 @@ public function testCreateViewFlatGroupByAsCallable()
580580
[$this->obj2, $this->obj3],
581581
null, // label
582582
null, // index
583-
[$this, 'getGroup']
583+
$this->getGroup(...)
584584
);
585585

586586
$this->assertGroupedView($view);
@@ -593,7 +593,7 @@ public function testCreateViewFlatGroupByAsCallableReturnsArray()
593593
[],
594594
null, // label
595595
null, // index
596-
[$this, 'getGroupArray']
596+
$this->getGroupArray(...)
597597
);
598598

599599
$this->assertGroupedViewWithChoiceDuplication($view);
@@ -606,7 +606,7 @@ public function testCreateViewFlatGroupByObjectThatCanBeCastToString()
606606
[$this->obj2, $this->obj3],
607607
null, // label
608608
null, // index
609-
[$this, 'getGroupAsObject']
609+
$this->getGroupAsObject(...)
610610
);
611611

612612
$this->assertGroupedView($view);
@@ -699,7 +699,7 @@ public function testCreateViewFlatAttrAsCallable()
699699
null, // label
700700
null, // index
701701
null, // group
702-
[$this, 'getAttr']
702+
$this->getAttr(...)
703703
);
704704

705705
$this->assertFlatViewWithAttr($view);
@@ -837,7 +837,7 @@ public function testCreateViewFlatlabelTranslationParametersAsCallable()
837837
null, // index
838838
null, // group
839839
null, // attr
840-
[$this, 'getlabelTranslationParameters']
840+
$this->getlabelTranslationParameters(...)
841841
);
842842

843843
$this->assertFlatViewWithlabelTranslationParameters($view);

Tests/Extension/Validator/Constraints/FormValidatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public function testHandleGroupSequenceValidationGroups()
423423
public function testHandleCallbackValidationGroups()
424424
{
425425
$object = new \stdClass();
426-
$options = ['validation_groups' => [$this, 'getValidationGroups']];
426+
$options = ['validation_groups' => $this->getValidationGroups(...)];
427427
$form = $this->getCompoundForm($object, $options);
428428
$form->submit([]);
429429

@@ -543,7 +543,7 @@ public function testUseInheritedCallbackValidationGroup()
543543
{
544544
$object = new \stdClass();
545545

546-
$parentOptions = ['validation_groups' => [$this, 'getValidationGroups']];
546+
$parentOptions = ['validation_groups' => $this->getValidationGroups(...)];
547547
$parent = $this->getBuilder('parent', null, $parentOptions)
548548
->setCompound(true)
549549
->setDataMapper(new DataMapper())

Tests/Extension/Validator/Type/BaseValidatorExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testValidationGroupsCanBeSetToFalse()
5757
public function testValidationGroupsCanBeSetToCallback()
5858
{
5959
$form = $this->createForm([
60-
'validation_groups' => [$this, 'testValidationGroupsCanBeSetToCallback'],
60+
'validation_groups' => $this->testValidationGroupsCanBeSetToCallback(...),
6161
]);
6262

6363
$this->assertIsCallable($form->getConfig()->getOption('validation_groups'));

0 commit comments

Comments
 (0)