Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34532a1

Browse files
committed
Leverage First-class callable syntax
1 parent 4a97318 commit 34532a1

File tree

19 files changed

+54
-53
lines changed

19 files changed

+54
-53
lines changed

src/Symfony/Bridge/Doctrine/Middleware/Debug/DebugDataHolder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function addQuery(string $connectionName, Query $query): void
2424
'sql' => $query->getSql(),
2525
'params' => $query->getParams(),
2626
'types' => $query->getTypes(),
27-
'executionMS' => [$query, 'getDuration'], // stop() may not be called at this point
27+
'executionMS' => $query->getDuration(...), // stop() may not be called at this point
2828
];
2929
}
3030

src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected function configureContainer(ContainerConfigurator $c): void
129129

130130
protected function configureRoutes(RoutingConfigurator $routes): void
131131
{
132-
$routes->add('hello', '/')->controller([$this, 'helloAction']);
132+
$routes->add('hello', '/')->controller($this->helloAction(...));
133133
}
134134
};
135135

src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private function writeNode(NodeInterface $node, NodeInterface $parentNode = null
170170

171171
$this->writeLine('# '.$message.':', $depth * 4 + 4);
172172

173-
$this->writeArray(array_map([Inline::class, 'dump'], $example), $depth + 1);
173+
$this->writeArray(array_map(Inline::dump(...), $example), $depth + 1);
174174
}
175175

176176
if ($children) {

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ private function buildTableRows(array $rows): TableRows
617617
if (!str_contains($cell ?? '', "\n")) {
618618
continue;
619619
}
620-
$escaped = implode("\n", array_map([OutputFormatter::class, 'escapeTrailingBackslash'], explode("\n", $cell)));
620+
$escaped = implode("\n", array_map(OutputFormatter::escapeTrailingBackslash(...), explode("\n", $cell)));
621621
$cell = $cell instanceof TableCell ? new TableCell($escaped, ['colspan' => $cell->getColspan()]) : $escaped;
622622
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default></>\n", $cell));
623623
foreach ($lines as $lineKey => $line) {

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ private static function createClosure()
405405
public function testSetCodeWithNonClosureCallable()
406406
{
407407
$command = new \TestCommand();
408-
$ret = $command->setCode([$this, 'callableMethodCommand']);
408+
$ret = $command->setCode($this->callableMethodCommand(...));
409409
$this->assertEquals($command, $ret, '->setCode() implements a fluent interface');
410410
$tester = new CommandTester($command);
411411
$tester->execute([]);

src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function load(mixed $resource, string $type = null): mixed
3939
if (isset($result['parameters']) && \is_array($result['parameters'])) {
4040
foreach ($result['parameters'] as $key => $value) {
4141
if (\is_array($value)) {
42-
$this->container->setParameter($key, array_map([$this, 'phpize'], $value));
42+
$this->container->setParameter($key, array_map($this->phpize(...), $value));
4343
} else {
4444
$this->container->setParameter($key, $this->phpize($value));
4545
}

src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ public function testGetListenersSortsByPriority()
7575
$listener2->name = '2';
7676
$listener3->name = '3';
7777

78-
$this->dispatcher->addListener('pre.foo', [$listener1, 'preFoo'], -10);
79-
$this->dispatcher->addListener('pre.foo', [$listener2, 'preFoo'], 10);
80-
$this->dispatcher->addListener('pre.foo', [$listener3, 'preFoo']);
78+
$this->dispatcher->addListener('pre.foo', $listener1Call = $listener1->preFoo(...), -10);
79+
$this->dispatcher->addListener('pre.foo', $listener2Call = $listener2->preFoo(...), 10);
80+
$this->dispatcher->addListener('pre.foo', $listener3Call = $listener3->preFoo(...));
8181

8282
$expected = [
83-
[$listener2, 'preFoo'],
84-
[$listener3, 'preFoo'],
85-
[$listener1, 'preFoo'],
83+
$listener2Call,
84+
$listener3Call,
85+
$listener1Call,
8686
];
8787

8888
$this->assertSame($expected, $this->dispatcher->getListeners('pre.foo'));
@@ -159,8 +159,8 @@ public function testStopEventPropagation()
159159
// postFoo() stops the propagation, so only one listener should
160160
// be executed
161161
// Manually set priority to enforce $this->listener to be called first
162-
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo'], 10);
163-
$this->dispatcher->addListener('post.foo', [$otherListener, 'postFoo']);
162+
$this->dispatcher->addListener('post.foo', $this->listener->postFoo(...), 10);
163+
$this->dispatcher->addListener('post.foo', $otherListener->postFoo(...));
164164
$this->dispatcher->dispatch(new Event(), self::postFoo);
165165
$this->assertTrue($this->listener->postFooInvoked);
166166
$this->assertFalse($otherListener->postFooInvoked);
@@ -260,7 +260,7 @@ public function testRemoveSubscriberWithMultipleListeners()
260260
public function testEventReceivesTheDispatcherInstanceAsArgument()
261261
{
262262
$listener = new TestWithDispatcher();
263-
$this->dispatcher->addListener('test', [$listener, 'foo']);
263+
$this->dispatcher->addListener('test', $listener->foo(...));
264264
$this->assertNull($listener->name);
265265
$this->assertNull($listener->dispatcher);
266266
$this->dispatcher->dispatch(new Event(), 'test');
@@ -386,7 +386,7 @@ public function testMutatingWhilePropagationIsStopped()
386386
{
387387
$testLoaded = false;
388388
$test = new TestEventListener();
389-
$this->dispatcher->addListener('foo', [$test, 'postFoo']);
389+
$this->dispatcher->addListener('foo', $listenerCall = $test->postFoo(...));
390390
$this->dispatcher->addListener('foo', [function () use ($test, &$testLoaded) {
391391
$testLoaded = true;
392392

@@ -398,7 +398,7 @@ public function testMutatingWhilePropagationIsStopped()
398398
$this->assertTrue($test->postFooInvoked);
399399
$this->assertFalse($test->preFooInvoked);
400400

401-
$this->assertsame(0, $this->dispatcher->getListenerPriority('foo', [$test, 'preFoo']));
401+
$this->assertsame(0, $this->dispatcher->getListenerPriority('foo', $listenerCall));
402402

403403
$test->preFoo(new Event());
404404
$this->dispatcher->dispatch(new Event(), 'foo');

src/Symfony/Component/Form/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(),

src/Symfony/Component/Form/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);

src/Symfony/Component/Form/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())

0 commit comments

Comments
 (0)