From 26d9ce95208b73c128f928cce0f4016b647dea19 Mon Sep 17 00:00:00 2001 From: tigitz Date: Fri, 30 Sep 2022 22:34:56 +0200 Subject: [PATCH] Leverage First-class callable syntax --- .../Middleware/Debug/DebugDataHolder.php | 2 +- .../Tests/Kernel/MicroKernelTraitTest.php | 2 +- .../Definition/Dumper/YamlReferenceDumper.php | 2 +- .../Component/Console/Helper/Table.php | 2 +- .../Console/Tests/Command/CommandTest.php | 2 +- .../Loader/IniFileLoader.php | 2 +- .../Tests/EventDispatcherTest.php | 20 ++++++++++------- .../DataCollector/FormDataCollector.php | 2 +- .../Factory/DefaultChoiceListFactoryTest.php | 22 +++++++++---------- .../Constraints/FormValidatorTest.php | 4 ++-- .../Type/BaseValidatorExtensionTest.php | 2 +- .../HttpClient/Response/AmpResponse.php | 4 ++-- .../ArgumentMetadataFactoryTest.php | 10 ++++----- .../RequestDataCollectorTest.php | 11 ++++++++++ .../EventListener/ResponseListenerTest.php | 14 ++++++------ .../EventListener/SurrogateListenerTest.php | 6 ++--- .../Tests/TraceableMessageBusTest.php | 2 +- src/Symfony/Component/String/LazyString.php | 2 +- .../Tests/Constraints/UniqueValidatorTest.php | 1 + 19 files changed, 64 insertions(+), 48 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Middleware/Debug/DebugDataHolder.php b/src/Symfony/Bridge/Doctrine/Middleware/Debug/DebugDataHolder.php index 14c338e63d691..4e1052a139651 100644 --- a/src/Symfony/Bridge/Doctrine/Middleware/Debug/DebugDataHolder.php +++ b/src/Symfony/Bridge/Doctrine/Middleware/Debug/DebugDataHolder.php @@ -24,7 +24,7 @@ public function addQuery(string $connectionName, Query $query): void 'sql' => $query->getSql(), 'params' => $query->getParams(), 'types' => $query->getTypes(), - 'executionMS' => [$query, 'getDuration'], // stop() may not be called at this point + 'executionMS' => $query->getDuration(...), // stop() may not be called at this point ]; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php index afe35548df5cb..8c2059723939c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php @@ -129,7 +129,7 @@ protected function configureContainer(ContainerConfigurator $c): void protected function configureRoutes(RoutingConfigurator $routes): void { - $routes->add('hello', '/')->controller([$this, 'helloAction']); + $routes->add('hello', '/')->controller($this->helloAction(...)); } }; diff --git a/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php b/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php index bb629d332e507..606c3edaad58f 100644 --- a/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php +++ b/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php @@ -170,7 +170,7 @@ private function writeNode(NodeInterface $node, NodeInterface $parentNode = null $this->writeLine('# '.$message.':', $depth * 4 + 4); - $this->writeArray(array_map([Inline::class, 'dump'], $example), $depth + 1); + $this->writeArray(array_map(Inline::dump(...), $example), $depth + 1); } if ($children) { diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 81598dfb49929..ac48bf4bac865 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -617,7 +617,7 @@ private function buildTableRows(array $rows): TableRows if (!str_contains($cell ?? '', "\n")) { continue; } - $escaped = implode("\n", array_map([OutputFormatter::class, 'escapeTrailingBackslash'], explode("\n", $cell))); + $escaped = implode("\n", array_map(OutputFormatter::escapeTrailingBackslash(...), explode("\n", $cell))); $cell = $cell instanceof TableCell ? new TableCell($escaped, ['colspan' => $cell->getColspan()]) : $escaped; $lines = explode("\n", str_replace("\n", "\n", $cell)); foreach ($lines as $lineKey => $line) { diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index 6aca4e4383b0b..e2172f56aae2a 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -405,7 +405,7 @@ private static function createClosure() public function testSetCodeWithNonClosureCallable() { $command = new \TestCommand(); - $ret = $command->setCode([$this, 'callableMethodCommand']); + $ret = $command->setCode($this->callableMethodCommand(...)); $this->assertEquals($command, $ret, '->setCode() implements a fluent interface'); $tester = new CommandTester($command); $tester->execute([]); diff --git a/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php index 2115217909e8d..4ba1a2dda9087 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php @@ -39,7 +39,7 @@ public function load(mixed $resource, string $type = null): mixed if (isset($result['parameters']) && \is_array($result['parameters'])) { foreach ($result['parameters'] as $key => $value) { if (\is_array($value)) { - $this->container->setParameter($key, array_map([$this, 'phpize'], $value)); + $this->container->setParameter($key, array_map($this->phpize(...), $value)); } else { $this->container->setParameter($key, $this->phpize($value)); } diff --git a/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php index 291d5b85a0dcd..a13e6f43f06f6 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php @@ -57,7 +57,7 @@ public function testInitialState() public function testAddListener() { $this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']); - $this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']); + $this->dispatcher->addListener('post.foo', $this->listener->postFoo(...)); $this->assertTrue($this->dispatcher->hasListeners()); $this->assertTrue($this->dispatcher->hasListeners(self::preFoo)); $this->assertTrue($this->dispatcher->hasListeners(self::postFoo)); @@ -71,21 +71,25 @@ public function testGetListenersSortsByPriority() $listener1 = new TestEventListener(); $listener2 = new TestEventListener(); $listener3 = new TestEventListener(); + $listener4 = new TestEventListener(); $listener1->name = '1'; $listener2->name = '2'; $listener3->name = '3'; + $listener4->name = '4'; $this->dispatcher->addListener('pre.foo', [$listener1, 'preFoo'], -10); $this->dispatcher->addListener('pre.foo', [$listener2, 'preFoo'], 10); $this->dispatcher->addListener('pre.foo', [$listener3, 'preFoo']); + $this->dispatcher->addListener('pre.foo', $listener4->preFoo(...), 20); $expected = [ + $listener4->preFoo(...), [$listener2, 'preFoo'], [$listener3, 'preFoo'], [$listener1, 'preFoo'], ]; - $this->assertSame($expected, $this->dispatcher->getListeners('pre.foo')); + $this->assertEquals($expected, $this->dispatcher->getListeners('pre.foo')); } public function testGetAllListenersSortsByPriority() @@ -129,7 +133,7 @@ public function testGetListenerPriority() public function testDispatch() { $this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']); - $this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']); + $this->dispatcher->addListener('post.foo', $this->listener->postFoo(...)); $this->dispatcher->dispatch(new Event(), self::preFoo); $this->assertTrue($this->listener->preFooInvoked); $this->assertFalse($this->listener->postFooInvoked); @@ -160,7 +164,7 @@ public function testStopEventPropagation() // be executed // Manually set priority to enforce $this->listener to be called first $this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo'], 10); - $this->dispatcher->addListener('post.foo', [$otherListener, 'postFoo']); + $this->dispatcher->addListener('post.foo', $otherListener->postFoo(...)); $this->dispatcher->dispatch(new Event(), self::postFoo); $this->assertTrue($this->listener->postFooInvoked); $this->assertFalse($otherListener->postFooInvoked); @@ -386,7 +390,7 @@ public function testMutatingWhilePropagationIsStopped() { $testLoaded = false; $test = new TestEventListener(); - $this->dispatcher->addListener('foo', [$test, 'postFoo']); + $this->dispatcher->addListener('foo', $test->postFoo(...)); $this->dispatcher->addListener('foo', [function () use ($test, &$testLoaded) { $testLoaded = true; @@ -398,7 +402,7 @@ public function testMutatingWhilePropagationIsStopped() $this->assertTrue($test->postFooInvoked); $this->assertFalse($test->preFooInvoked); - $this->assertsame(0, $this->dispatcher->getListenerPriority('foo', [$test, 'preFoo'])); + $this->assertEquals(0, $this->dispatcher->getListenerPriority('foo', $test->postFoo(...))); $test->preFoo(new Event()); $this->dispatcher->dispatch(new Event(), 'foo'); @@ -417,8 +421,8 @@ public function testNamedClosures() $this->assertNotSame($callback1, $callback2); $this->assertNotSame($callback1, $callback3); $this->assertNotSame($callback2, $callback3); - $this->assertTrue($callback1 == $callback2); - $this->assertFalse($callback1 == $callback3); + $this->assertEquals($callback1, $callback2); + $this->assertEquals($callback1, $callback3); $this->dispatcher->addListener('foo', $callback1, 3); $this->dispatcher->addListener('foo', $callback2, 2); diff --git a/src/Symfony/Component/Form/Extension/DataCollector/FormDataCollector.php b/src/Symfony/Component/Form/Extension/DataCollector/FormDataCollector.php index 525d8ffeccd4b..0a9145c624e68 100644 --- a/src/Symfony/Component/Form/Extension/DataCollector/FormDataCollector.php +++ b/src/Symfony/Component/Form/Extension/DataCollector/FormDataCollector.php @@ -235,7 +235,7 @@ protected function getCasters(): array Caster::PREFIX_VIRTUAL.'type_class' => new ClassStub(\get_class($f->getConfig()->getType()->getInnerType())), ]; }, - FormView::class => [StubCaster::class, 'cutInternals'], + FormView::class => StubCaster::cutInternals(...), ConstraintViolationInterface::class => function (ConstraintViolationInterface $v, array $a) { return [ Caster::PREFIX_VIRTUAL.'root' => $v->getRoot(), diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php index ab26d4cbe3ded..054739c8ccd80 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php @@ -141,7 +141,7 @@ public function testCreateFromChoicesFlatValuesAsCallable() { $list = $this->factory->createListFromChoices( ['A' => $this->obj1, 'B' => $this->obj2, 'C' => $this->obj3, 'D' => $this->obj4], - [$this, 'getValue'] + $this->getValue(...) ); $this->assertObjectListWithCustomValues($list); @@ -186,7 +186,7 @@ public function testCreateFromChoicesGroupedValuesAsCallable() 'Group 1' => ['A' => $this->obj1, 'B' => $this->obj2], 'Group 2' => ['C' => $this->obj3, 'D' => $this->obj4], ], - [$this, 'getValue'] + $this->getValue(...) ); $this->assertObjectListWithCustomValues($list); @@ -335,7 +335,7 @@ public function testCreateViewFlatPreferredChoiceGroupsSameOrder() [$this->obj4, $this->obj2, $this->obj1, $this->obj3], null, // label null, // index - [$this, 'getGroup'] + $this->getGroup(...) ); $preferredLabels = array_map(static function (ChoiceGroupView $groupView): array { @@ -380,7 +380,7 @@ public function testCreateViewFlatPreferredChoicesAsCallable() { $view = $this->factory->createView( $this->list, - [$this, 'isPreferred'] + $this->isPreferred(...) ); $this->assertFlatView($view); @@ -430,7 +430,7 @@ public function testCreateViewFlatLabelAsCallable() $view = $this->factory->createView( $this->list, [$this->obj2, $this->obj3], - [$this, 'getLabel'] + $this->getLabel(...) ); $this->assertFlatView($view); @@ -486,7 +486,7 @@ public function testCreateViewFlatIndexAsCallable() $this->list, [$this->obj2, $this->obj3], null, // label - [$this, 'getFormIndex'] + $this->getFormIndex(...) ); $this->assertFlatViewWithCustomIndices($view); @@ -580,7 +580,7 @@ public function testCreateViewFlatGroupByAsCallable() [$this->obj2, $this->obj3], null, // label null, // index - [$this, 'getGroup'] + $this->getGroup(...) ); $this->assertGroupedView($view); @@ -593,7 +593,7 @@ public function testCreateViewFlatGroupByAsCallableReturnsArray() [], null, // label null, // index - [$this, 'getGroupArray'] + $this->getGroupArray(...) ); $this->assertGroupedViewWithChoiceDuplication($view); @@ -606,7 +606,7 @@ public function testCreateViewFlatGroupByObjectThatCanBeCastToString() [$this->obj2, $this->obj3], null, // label null, // index - [$this, 'getGroupAsObject'] + $this->getGroupAsObject(...) ); $this->assertGroupedView($view); @@ -699,7 +699,7 @@ public function testCreateViewFlatAttrAsCallable() null, // label null, // index null, // group - [$this, 'getAttr'] + $this->getAttr(...) ); $this->assertFlatViewWithAttr($view); @@ -837,7 +837,7 @@ public function testCreateViewFlatlabelTranslationParametersAsCallable() null, // index null, // group null, // attr - [$this, 'getlabelTranslationParameters'] + $this->getlabelTranslationParameters(...) ); $this->assertFlatViewWithlabelTranslationParameters($view); diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index e5b0d736b0672..b5ab6588cb1de 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -423,7 +423,7 @@ public function testHandleGroupSequenceValidationGroups() public function testHandleCallbackValidationGroups() { $object = new \stdClass(); - $options = ['validation_groups' => [$this, 'getValidationGroups']]; + $options = ['validation_groups' => $this->getValidationGroups(...)]; $form = $this->getCompoundForm($object, $options); $form->submit([]); @@ -543,7 +543,7 @@ public function testUseInheritedCallbackValidationGroup() { $object = new \stdClass(); - $parentOptions = ['validation_groups' => [$this, 'getValidationGroups']]; + $parentOptions = ['validation_groups' => $this->getValidationGroups(...)]; $parent = $this->getBuilder('parent', null, $parentOptions) ->setCompound(true) ->setDataMapper(new DataMapper()) diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Type/BaseValidatorExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Type/BaseValidatorExtensionTest.php index 7062ed53d3686..4b69dfe886c8f 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Type/BaseValidatorExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Type/BaseValidatorExtensionTest.php @@ -57,7 +57,7 @@ public function testValidationGroupsCanBeSetToFalse() public function testValidationGroupsCanBeSetToCallback() { $form = $this->createForm([ - 'validation_groups' => [$this, 'testValidationGroupsCanBeSetToCallback'], + 'validation_groups' => $this->testValidationGroupsCanBeSetToCallback(...), ]); $this->assertIsCallable($form->getConfig()->getOption('validation_groups')); diff --git a/src/Symfony/Component/HttpClient/Response/AmpResponse.php b/src/Symfony/Component/HttpClient/Response/AmpResponse.php index c0453436e8b8c..d46e4036d801c 100644 --- a/src/Symfony/Component/HttpClient/Response/AmpResponse.php +++ b/src/Symfony/Component/HttpClient/Response/AmpResponse.php @@ -207,7 +207,7 @@ private static function select(ClientState $multi, float $timeout): int $timeout += microtime(true); self::$delay = Loop::defer(static function () use ($timeout) { if (0 < $timeout -= microtime(true)) { - self::$delay = Loop::delay(ceil(1000 * $timeout), [Loop::class, 'stop']); + self::$delay = Loop::delay(ceil(1000 * $timeout), Loop::stop(...)); } else { Loop::stop(); } @@ -447,6 +447,6 @@ private static function stopLoop(): void self::$delay = null; } - Loop::defer([Loop::class, 'stop']); + Loop::defer(Loop::stop(...)); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php b/src/Symfony/Component/HttpKernel/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php index ffbb6549b89fe..2984950e120ea 100644 --- a/src/Symfony/Component/HttpKernel/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php @@ -35,7 +35,7 @@ protected function setUp(): void public function testSignature1() { - $arguments = $this->factory->createArgumentMetadata([$this, 'signature1']); + $arguments = $this->factory->createArgumentMetadata($this->signature1(...)); $this->assertEquals([ new ArgumentMetadata('foo', self::class, false, false, null), @@ -46,7 +46,7 @@ public function testSignature1() public function testSignature2() { - $arguments = $this->factory->createArgumentMetadata([$this, 'signature2']); + $arguments = $this->factory->createArgumentMetadata($this->signature2(...)); $this->assertEquals([ new ArgumentMetadata('foo', self::class, false, true, null, true), @@ -57,7 +57,7 @@ public function testSignature2() public function testSignature3() { - $arguments = $this->factory->createArgumentMetadata([$this, 'signature3']); + $arguments = $this->factory->createArgumentMetadata($this->signature3(...)); $this->assertEquals([ new ArgumentMetadata('bar', FakeClassThatDoesNotExist::class, false, false, null), @@ -67,7 +67,7 @@ public function testSignature3() public function testSignature4() { - $arguments = $this->factory->createArgumentMetadata([$this, 'signature4']); + $arguments = $this->factory->createArgumentMetadata($this->signature4(...)); $this->assertEquals([ new ArgumentMetadata('foo', null, false, true, 'default'), @@ -78,7 +78,7 @@ public function testSignature4() public function testSignature5() { - $arguments = $this->factory->createArgumentMetadata([$this, 'signature5']); + $arguments = $this->factory->createArgumentMetadata($this->signature5(...)); $this->assertEquals([ new ArgumentMetadata('foo', 'array', false, true, null, true), diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php index 184d22d07288d..378bfd3ee7051 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php @@ -122,6 +122,17 @@ function () { return 'foo'; }, ], ], + [ + 'First-class callable closure', + $this->testControllerInspection(...), + [ + 'class' => self::class, + 'method' => 'testControllerInspection', + 'file' => __FILE__, + 'line' => $r1->getStartLine(), + ], + ], + [ 'Static callback as string', __NAMESPACE__.'\RequestDataCollectorTest::staticControllerMethod', diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/ResponseListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/ResponseListenerTest.php index f6ca1963c812c..4bb8a607cf911 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/ResponseListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/ResponseListenerTest.php @@ -30,7 +30,7 @@ protected function setUp(): void { $this->dispatcher = new EventDispatcher(); $listener = new ResponseListener('UTF-8'); - $this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); + $this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...)); $this->kernel = $this->createMock(HttpKernelInterface::class); } @@ -54,7 +54,7 @@ public function testFilterDoesNothingForSubRequests() public function testFilterSetsNonDefaultCharsetIfNotOverridden() { $listener = new ResponseListener('ISO-8859-15'); - $this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1); + $this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1); $response = new Response('foo'); @@ -67,7 +67,7 @@ public function testFilterSetsNonDefaultCharsetIfNotOverridden() public function testFilterDoesNothingIfCharsetIsOverridden() { $listener = new ResponseListener('ISO-8859-15'); - $this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1); + $this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1); $response = new Response('foo'); $response->setCharset('ISO-8859-1'); @@ -81,7 +81,7 @@ public function testFilterDoesNothingIfCharsetIsOverridden() public function testFiltersSetsNonDefaultCharsetIfNotOverriddenOnNonTextContentType() { $listener = new ResponseListener('ISO-8859-15'); - $this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1); + $this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1); $response = new Response('foo'); $request = Request::create('/'); @@ -96,7 +96,7 @@ public function testFiltersSetsNonDefaultCharsetIfNotOverriddenOnNonTextContentT public function testSetContentLanguageHeaderWhenEmptyAndAtLeast2EnabledLocalesAreConfigured() { $listener = new ResponseListener('ISO-8859-15', true, ['fr', 'en']); - $this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1); + $this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1); $response = new Response('content'); $request = Request::create('/'); @@ -111,7 +111,7 @@ public function testSetContentLanguageHeaderWhenEmptyAndAtLeast2EnabledLocalesAr public function testNotOverrideContentLanguageHeaderWhenNotEmpty() { $listener = new ResponseListener('ISO-8859-15', true, ['de']); - $this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1); + $this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1); $response = new Response('content'); $response->headers->set('Content-Language', 'mi, en'); @@ -127,7 +127,7 @@ public function testNotOverrideContentLanguageHeaderWhenNotEmpty() public function testNotSetContentLanguageHeaderWhenDisabled() { $listener = new ResponseListener('ISO-8859-15', false); - $this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1); + $this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1); $response = new Response('content'); $request = Request::create('/'); diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/SurrogateListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/SurrogateListenerTest.php index 88a442a928bac..ae24c882a73a6 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/SurrogateListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/SurrogateListenerTest.php @@ -30,7 +30,7 @@ public function testFilterDoesNothingForSubRequests() $response = new Response('foo '); $listener = new SurrogateListener(new Esi()); - $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); + $dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...)); $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response); $dispatcher->dispatch($event, KernelEvents::RESPONSE); @@ -44,7 +44,7 @@ public function testFilterWhenThereIsSomeEsiIncludes() $response = new Response('foo '); $listener = new SurrogateListener(new Esi()); - $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); + $dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...)); $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, $response); $dispatcher->dispatch($event, KernelEvents::RESPONSE); @@ -58,7 +58,7 @@ public function testFilterWhenThereIsNoEsiIncludes() $response = new Response('foo'); $listener = new SurrogateListener(new Esi()); - $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); + $dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...)); $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, $response); $dispatcher->dispatch($event, KernelEvents::RESPONSE); diff --git a/src/Symfony/Component/Messenger/Tests/TraceableMessageBusTest.php b/src/Symfony/Component/Messenger/Tests/TraceableMessageBusTest.php index 0b57cf37bad6c..12ccf943079bd 100644 --- a/src/Symfony/Component/Messenger/Tests/TraceableMessageBusTest.php +++ b/src/Symfony/Component/Messenger/Tests/TraceableMessageBusTest.php @@ -172,6 +172,6 @@ public function testItTracesExceptionsWhenMessageBusIsFiredFromArrayCallback() $this->expectExceptionObject($exception); - array_map([$traceableBus, 'dispatch'], [$message]); + array_map($traceableBus->dispatch(...), [$message]); } } diff --git a/src/Symfony/Component/String/LazyString.php b/src/Symfony/Component/String/LazyString.php index 7bc3a033c4127..77d50fbbb3ba1 100644 --- a/src/Symfony/Component/String/LazyString.php +++ b/src/Symfony/Component/String/LazyString.php @@ -50,7 +50,7 @@ public static function fromCallable(callable|array $callback, mixed ...$argument public static function fromStringable(string|int|float|bool|\Stringable $value): static { if (\is_object($value)) { - return static::fromCallable([$value, '__toString']); + return static::fromCallable($value->__toString(...)); } $lazyString = new static(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php index 2f045ccf64ff7..eeaa6f8cdfa26 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php @@ -162,6 +162,7 @@ public function getCallback(): array }], 'callable with string notation' => ['Symfony\Component\Validator\Tests\Constraints\CallableClass::execute'], 'callable with static notation' => [[CallableClass::class, 'execute']], + 'callable with first-class callable notation' => [CallableClass::execute(...)], 'callable with object' => [[new CallableClass(), 'execute']], ]; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy