8000 Leverage First-class callable syntax · symfony/symfony@34532a1 · GitHub
[go: up one dir, main page]

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
10000
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())

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

src/Symfony/Component/HttpClient/Response/AmpResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private static function select(ClientState $multi, float $timeout): int
207207
$timeout += microtime(true);
208208
self::$delay = Loop::defer(static function () use ($timeout) {
209209
if (0 < $timeout -= microtime(true)) {
210-
self::$delay = Loop::delay(ceil(1000 * $timeout), [Loop::class, 'stop']);
210+
self::$delay = Loop::delay(ceil(1000 * $timeout), Loop::stop(...));
211211
} else {
212212
Loop::stop();
213213
}
@@ -447,6 +447,6 @@ private static function stopLoop(): void
447447
self::$delay = null;
448448
}
449449

450-
Loop::defer([Loop::class, 'stop']);
450+
Loop::defer(Loop::stop(...));
451451
}
452452
}

src/Symfony/Component/HttpKernel/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function setUp(): void
3535

3636
public function testSignature1()
3737
{
38-
$arguments = $this->factory->createArgumentMetadata([$this, 'signature1']);
38+
$arguments = $this->factory->createArgumentMetadata($this->signature1(...));
3939

4040
$this->assertEquals([
4141
new ArgumentMetadata('foo', self::class, false, false, null),
@@ -46,7 +46,7 @@ public function testSignature1()
4646

4747
public function testSignature2()
4848
{
49-
$arguments = $this->factory->createArgumentMetadata([$this, 'signature2']);
49+
$arguments = $this->factory->createArgumentMetadata($this->signature2(...));
5050

5151
$this->assertEquals([
5252
new ArgumentMetadata('foo', self::class, false, true, null, true),
@@ -57,7 +57,7 @@ public function testSignature2()
5757

5858
public function testSignature3()
5959
{
60-
$arguments = $this->factory->createArgumentMetadata([$this, 'signature3']);
60+
$arguments = $this->factory->createArgumentMetadata($this->signature3(...));
6161

6262
$this->assertEquals([
6363
new ArgumentMetadata('bar', FakeClassThatDoesNotExist::class, false, false, null),
@@ -67,7 +67,7 @@ public function testSignature3()
6767

6868
public function testSignature4()
6969
{
70-
$arguments = $this->factory->createArgumentMetadata([$this, 'signature4']);
70+
$arguments = $this->factory->createArgumentMetadata($this->signature4(...));
7171

7272
$this->assertEquals([
7373
new ArgumentMetadata('foo', null, false, true, 'default'),
@@ -78,7 +78,7 @@ public function testSignature4()
7878

7979
public function testSignature5()
8080
{
81-
$arguments = $this->factory->createArgumentMetadata([$this, 'signature5']);
81+
$arguments = $this->factory->createArgumentMetadata($this->signature5(...));
8282

8383
$this->assertEquals([
8484
new ArgumentMetadata('foo', 'array', false, true, null, true),

src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function provideControllerCallables()
102102
return [
103103
[
104104
'"Regular" callable',
105-
[$this, 'testControllerInspection'],
105+
$this->testControllerInspection(...),
106106
[
107107
'class' => self::class,
108108
'method' => 'testControllerInspection',
@@ -135,7 +135,7 @@ function () { return 'foo'; },
135135

136136
[
137137
'Static callable with instance',
138-
[$this, 'staticControllerMethod'],
138+
$this->staticControllerMethod(...),
139139
[
140140
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
141141
'method' => 'staticControllerMethod',

src/Symfony/Component/HttpKernel/Tests/EventListener/ResponseListenerTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function setUp(): void
3030
{
3131
$this->dispatcher = new EventDispatcher();
3232
$listener = new ResponseListener('UTF-8');
33-
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
33+
$this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...));
3434

3535
$this->kernel = $this->createMock(HttpKernelInterface::class);
3636
}
@@ -54,7 +54,7 @@ public function testFilterDoesNothingForSubRequests()
5454
public function testFilterSetsNonDefaultCharsetIfNotOverridden()
5555
{
5656
$listener = new ResponseListener('ISO-8859-15');
57-
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1);
57+
$this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1);
5858

5959
$response = new Response('foo');
6060

@@ -67,7 +67,7 @@ public function testFilterSetsNonDefaultCharsetIfNotOverridden()
6767
public function testFilterDoesNothingIfCharsetIsOverridden()
6868
{
6969
$listener = new ResponseListener('ISO-8859-15');
70-
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1);
70+
$this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1);
7171

7272
$response = new Response('foo');
7373
$response->setCharset('ISO-8859-1');
@@ -81,7 +81,7 @@ public function testFilterDoesNothingIfCharsetIsOverridden()
8181
public function testFiltersSetsNonDefaultCharsetIfNotOverriddenOnNonTextContentType()
8282
{
8383
$listener = new ResponseListener('ISO-8859-15');
84-
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1);
84+
$this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1);
8585

8686
$response = new Response('foo');
8787
$request = Request::create('/');
@@ -96,7 +96,7 @@ public function testFiltersSetsNonDefaultCharsetIfNotOverriddenOnNonTextContentT
9696
public function testSetContentLanguageHeaderWhenEmptyAndAtLeast2EnabledLocalesAreConfigured()
9797
{
9898
$listener = new ResponseListener('ISO-8859-15', true, ['fr', 'en']);
99-
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1);
99+
$this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1);
100100

101101
$response = new Response('content');
102102
$request = Request::create('/');
@@ -111,7 +111,7 @@ public function testSetContentLanguageHeaderWhenEmptyAndAtLeast2EnabledLocalesAr
111111
public function testNotOverrideContentLanguageHeaderWhenNotEmpty()
112112
{
113113
$listener = new ResponseListener('ISO-8859-15', true, ['de']);
114-
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1);
114+
$this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1);
115115

116116
$response = new Response('content');
117117
$response->headers->set('Content-Language', 'mi, en');
@@ -127,7 +127,7 @@ public function testNotOverrideContentLanguageHeaderWhenNotEmpty()
127127
public function testNotSetContentLanguageHeaderWhenDisabled()
128128
{
129129
$listener = new ResponseListener('ISO-8859-15', false);
130-
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1);
130+
$this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1);
131131

132132
$response = new Response('content');
133133
$request = Request::create('/');

0 commit comments

Comments
 (0)
0