Skip to content

Commit 376e594

Browse files
committed
minor symfony#57901 Code style change in `@PER-CS2.0 affecting @Symfony` (parentheses for anonymous classes) (bonroyage)
This PR was squashed before being merged into the 7.2 branch. Discussion ---------- Code style change in ``@PER`-CS2.0` affecting ``@Symfony`` (parentheses for anonymous classes) | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT I have created a PR (PHP-CS-Fixer/PHP-CS-Fixer#8140) in the PHP-CS-Fixer repo to bring the ``@PER`-CS2.0` ruleset in line with the specifications on the `new_with_parentheses` rule for anonymous classes. Since the ``@Symfony`` ruleset builds upon the ``@PER`-CS2.0` ruleset, they would like confirmation that the Symfony community is OK with this change affecting the Symfony ruleset as well. Should it not be, I'll push another commit there ensuring that the change does not affect ``@Symfony``. Therefore, this PR is not meant to be merged, but function as an RFC to get your opinion and show the effect it would have when applied to the Symfony source. Commits ------- 506e0dd Code style change in ``@PER`-CS2.0` affecting ``@Symfony`` (parentheses for anonymous classes)
2 parents b7e0258 + 506e0dd commit 376e594

File tree

108 files changed

+202
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+202
-201
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
'nullable_type_declaration' => true,
3838
'nullable_type_declaration_for_default_null_value' => true,
3939
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match', 'parameters']],
40+
'new_with_parentheses' => ['anonymous_class' => false],
4041
])
4142
->setRiskyAllowed(true)
4243
->setFinder(

src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineOpenTransactionLoggerMiddlewareTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DoctrineOpenTransactionLoggerMiddlewareTest extends MiddlewareTestCase
2929

3030
protected function setUp(): void
3131
{
32-
$this->logger = new class() extends AbstractLogger {
32+
$this->logger = new class extends AbstractLogger {
3333
public array $logs = [];
3434

3535
public function log($level, $message, $context = []): void

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ public static function resultWithEmptyIterator(): array
926926
$entity = new SingleIntIdEntity(1, 'foo');
927927

928928
return [
929-
[$entity, new class() implements \Iterator {
929+
[$entity, new class implements \Iterator {
930930
public function current(): mixed
931931
{
932932
return null;
@@ -950,7 +950,7 @@ public function rewind(): void
950950
{
951951
}
952952
}],
953-
[$entity, new class() implements \Iterator {
953+
[$entity, new class implements \Iterator {
954954
public function current(): mixed
955955
{
956956
return false;

src/Symfony/Bridge/Twig/Extension/TranslationExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getTranslator(): TranslatorInterface
4747
throw new \LogicException(\sprintf('You cannot use the "%s" if the Translation Contracts are not available. Try running "composer require symfony/translation".', __CLASS__));
4848
}
4949

50-
$this->translator = new class() implements TranslatorInterface {
50+
$this->translator = new class implements TranslatorInterface {
5151
use TranslatorTrait;
5252
};
5353
}

src/Symfony/Bridge/Twig/Tests/Extension/AbstractLayoutTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,7 @@ public function testHelpWithTranslatableMessage()
26522652

26532653
public function testHelpWithTranslatableInterface()
26542654
{
2655-
$message = new class() implements TranslatableInterface {
2655+
$message = new class implements TranslatableInterface {
26562656
public function trans(TranslatorInterface $translator, ?string $locale = null): string
26572657
{
26582658
return $translator->trans('foo');

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ConfigBuilderCacheWarmerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function testExtensionAddedInKernel()
189189
$kernel = new class($this->varDir) extends TestKernel {
190190
protected function build(ContainerBuilder $container): void
191191
{
192-
$container->registerExtension(new class() extends Extension implements ConfigurationInterface {
192+
$container->registerExtension(new class extends Extension implements ConfigurationInterface {
193193
public function load(array $configs, ContainerBuilder $container): void
194194
{
195195
}
@@ -276,7 +276,7 @@ protected function build(ContainerBuilder $container): void
276276
{
277277
/** @var TestSecurityExtension $extension */
278278
$extension = $container->getExtension('test_security');
279-
$extension->addAuthenticatorFactory(new class() implements TestAuthenticatorFactoryInterface {
279+
$extension->addAuthenticatorFactory(new class implements TestAuthenticatorFactoryInterface {
280280
public function getKey(): string
281281
{
282282
return 'token';
@@ -292,19 +292,19 @@ public function registerBundles(): iterable
292292
{
293293
yield from parent::registerBundles();
294294

295-
yield new class() extends Bundle {
295+
yield new class extends Bundle {
296296
public function getContainerExtension(): ExtensionInterface
297297
{
298298
return new TestSecurityExtension();
299299
}
300300
};
301301

302-
yield new class() extends Bundle {
302+
yield new class extends Bundle {
303303
public function build(ContainerBuilder $container): void
304304
{
305305
/** @var TestSecurityExtension $extension */
306306
$extension = $container->getExtension('test_security');
307-
$extension->addAuthenticatorFactory(new class() implements TestAuthenticatorFactoryInterface {
307+
$extension->addAuthenticatorFactory(new class implements TestAuthenticatorFactoryInterface {
308308
public function getKey(): string
309309
{
310310
return 'form-login';

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ProfilerPassTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testValidCollector()
6666

6767
public static function provideValidCollectorWithTemplateUsingAutoconfigure(): \Generator
6868
{
69-
yield [new class() implements TemplateAwareDataCollectorInterface {
69+
yield [new class implements TemplateAwareDataCollectorInterface {
7070
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
7171
{
7272
}
@@ -86,7 +86,7 @@ public static function getTemplate(): string
8686
}
8787
}];
8888

89-
yield [new class() extends AbstractDataCollector {
89+
yield [new class extends AbstractDataCollector {
9090
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
9191
{
9292
}

src/Symfony/Bundle/FrameworkBundle/Tests/Test/WebTestCaseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ private function getRequestTester(): WebTestCase
388388

389389
private function getTester(KernelBrowser $client): WebTestCase
390390
{
391-
$tester = new class() extends WebTestCase {
391+
$tester = new class extends WebTestCase {
392392
use WebTestAssertionsTrait {
393393
getClient as public;
394394
}

src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function testCollectCollectsDecisionLogWhenStrategyIsAffirmative()
226226
$voter1 = new DummyVoter();
227227
$voter2 = new DummyVoter();
228228

229-
$decoratedVoter1 = new TraceableVoter($voter1, new class() implements EventDispatcherInterface {
229+
$decoratedVoter1 = new TraceableVoter($voter1, new class implements EventDispatcherInterface {
230230
public function dispatch(object $event, ?string $eventName = null): object
231231
{
232232
return new \stdClass();
@@ -301,7 +301,7 @@ public function testCollectCollectsDecisionLogWhenStrategyIsUnanimous()
301301
$voter1 = new DummyVoter();
302302
$voter2 = new DummyVoter();
303303

304-
$decoratedVoter1 = new TraceableVoter($voter1, new class() implements EventDispatcherInterface {
304+
$decoratedVoter1 = new TraceableVoter($voter1, new class implements EventDispatcherInterface {
305305
public function dispatch(object $event, ?string $eventName = null): object
306306
{
307307
return new \stdClass();

src/Symfony/Component/AssetMapper/Tests/AssetMapperCompilerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AssetMapperCompilerTest extends TestCase
2121
{
2222
public function testCompile()
2323
{
24-
$compiler1 = new class() implements AssetCompilerInterface {
24+
$compiler1 = new class implements AssetCompilerInterface {
2525
public function supports(MappedAsset $asset): bool
2626
{
2727
return 'css' === $asset->publicExtension;
@@ -33,7 +33,7 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
3333
}
3434
};
3535

36-
$compiler2 = new class() implements AssetCompilerInterface {
36+
$compiler2 = new class implements AssetCompilerInterface {
3737
public function supports(MappedAsset $asset): bool
3838
{
3939
return 'js' === $asset->publicExtension;
@@ -45,7 +45,7 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
4545
}
4646
};
4747

48-
$compiler3 = new class() implements AssetCompilerInterface {
48+
$compiler3 = new class implements AssetCompilerInterface {
4949
public function supports(MappedAsset $asset): bool
5050
{
5151
return 'js' === $asset->publicExtension;

0 commit comments

Comments
 (0)