Skip to content

Commit 2e38b26

Browse files
committed
minor #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 ------- 506e0dd327 Code style change in ``@PER`-CS2.0` affecting ``@Symfony`` (parentheses for anonymous classes)
2 parents c90cd2f + c621af0 commit 2e38b26

11 files changed

+30
-30
lines changed

Compiler/AutowirePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class AutowirePass extends AbstractRecursivePass
5050
public function __construct(
5151
private bool $throwOnAutowiringException = true,
5252
) {
53-
$this->defaultArgument = new class() {
53+
$this->defaultArgument = new class {
5454
public $value;
5555
public $names;
5656
public $bag;

Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private function throwServiceNotFoundException(Reference $ref, string $sourceId,
9898
}
9999
}
100100

101-
$pass = new class() extends AbstractRecursivePass {
101+
$pass = new class extends AbstractRecursivePass {
102102
public Reference $ref;
103103
public string $sourceId;
104104
public array $alternatives;

Tests/Compiler/AbstractRecursivePassTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testGetConstructorResolvesFactoryChildDefinitionsClass()
3535
->register('foo', \stdClass::class)
3636
->setFactory([new Reference('child'), 'createFactory']);
3737

38-
$pass = new class() extends AbstractRecursivePass {
38+
$pass = new class extends AbstractRecursivePass {
3939
public \ReflectionMethod $actual;
4040

4141
protected function processValue($value, $isRoot = false): mixed
@@ -61,7 +61,7 @@ public function testGetConstructorResolvesChildDefinitionsClass()
6161
->setAbstract(true);
6262
$container->setDefinition('foo', new ChildDefinition('parent'));
6363

64-
$pass = new class() extends AbstractRecursivePass {
64+
$pass = new class extends AbstractRecursivePass {
6565
public \ReflectionMethod $actual;
6666

6767
protected function processValue($value, $isRoot = false): mixed
@@ -87,7 +87,7 @@ public function testGetReflectionMethodResolvesChildDefinitionsClass()
8787
->setAbstract(true);
8888
$container->setDefinition('foo', new ChildDefinition('parent'));
8989

90-
$pass = new class() extends AbstractRecursivePass {
90+
$pass = new class extends AbstractRecursivePass {
9191
public \ReflectionMethod $actual;
9292

9393
protected function processValue($value, $isRoot = false): mixed
@@ -113,7 +113,7 @@ public function testGetConstructorDefinitionNoClass()
113113
$this->expectException(RuntimeException::class);
114114
$this->expectExceptionMessage('Invalid service "foo": the class is not set.');
115115

116-
(new class() extends AbstractRecursivePass {
116+
(new class extends AbstractRecursivePass {
117117
protected function processValue($value, $isRoot = false): mixed
118118
{
119119
if ($value instanceof Definition && 'foo' === $this->currentId) {

Tests/Compiler/CheckDefinitionValidityPassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,17 @@ public static function provideInvalidTags(): iterable
108108
$message = 'A "tags" attribute must be of a scalar-type for service "a", tag "%s", attribute "%s".';
109109
yield 'object attribute value' => [
110110
'foo',
111-
['bar' => new class() {}],
111+
['bar' => new class {}],
112112
\sprintf($message, 'foo', 'bar'),
113113
];
114114
yield 'nested object attribute value' => [
115115
'foo',
116-
['bar' => ['baz' => new class() {}]],
116+
['bar' => ['baz' => new class {}]],
117117
\sprintf($message, 'foo', 'bar.baz'),
118118
];
119119
yield 'deeply nested object attribute value' => [
120120
'foo',
121-
['bar' => ['baz' => ['qux' => new class() {}]]],
121+
['bar' => ['baz' => ['qux' => new class {}]]],
122122
\sprintf($message, 'foo', 'bar.baz.qux'),
123123
];
124124
}

Tests/Compiler/CustomExpressionLanguageFunctionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testDump()
2727
->setPublic(true)
2828
->setArguments([new Expression('custom_func("foobar")')]);
2929

30-
$container->addExpressionLanguageProvider(new class() implements ExpressionFunctionProviderInterface {
30+
$container->addExpressionLanguageProvider(new class implements ExpressionFunctionProviderInterface {
3131
public function getFunctions(): array
3232
{
3333
return [

Tests/Compiler/RegisterServiceSubscribersPassTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public function testServiceMethodsSubscriberTraitWithSubscribedServiceAttributeO
257257
$this->markTestSkipped('SubscribedService attribute not available.');
258258
}
259259

260-
$subscriber = new class() implements ServiceSubscriberInterface {
260+
$subscriber = new class implements ServiceSubscriberInterface {
261261
use ServiceMethodsSubscriberTrait;
262262

263263
#[SubscribedService]
@@ -277,7 +277,7 @@ public function testServiceMethodsSubscriberTraitWithSubscribedServiceAttributeO
277277
$this->markTestSkipped('SubscribedService attribute not available.');
278278
}
279279

280-
$subscriber = new class() implements ServiceSubscriberInterface {
280+
$subscriber = new class implements ServiceSubscriberInterface {
281281
use ServiceMethodsSubscriberTrait;
282282

283283
#[SubscribedService]
@@ -297,7 +297,7 @@ public function testServiceMethodsSubscriberTraitWithSubscribedServiceAttributeO
297297
$this->markTestSkipped('SubscribedService attribute not available.');
298298
}
299299

300-
$subscriber = new class() implements ServiceSubscriberInterface {
300+
$subscriber = new class implements ServiceSubscriberInterface {
301301
use ServiceMethodsSubscriberTrait;
302302

303303
#[SubscribedService]
@@ -368,7 +368,7 @@ public function testServiceSubscriberWithSemanticId()
368368
{
369369
$container = new ContainerBuilder();
370370

371-
$subscriber = new class() implements ServiceSubscriberInterface {
371+
$subscriber = new class implements ServiceSubscriberInterface {
372372
public static function getSubscribedServices(): array
373373
{
374374
return [
@@ -413,7 +413,7 @@ public function testSubscribedServiceWithAttributes()
413413
{
414414
$container = new ContainerBuilder();
415415

416-
$subscriber = new class() implements ServiceSubscriberInterface {
416+
$subscriber = new class implements ServiceSubscriberInterface {
417417
public static function getSubscribedServices(): array
418418
{
419419
return [
@@ -465,7 +465,7 @@ public function testSubscribedServiceWithLegacyAttributes()
465465
{
466466
$container = new ContainerBuilder();
467467

468-
$subscriber = new class() implements ServiceSubscriberInterface {
468+
$subscriber = new class implements ServiceSubscriberInterface {
469469
public static function getSubscribedServices(): array
470470
{
471471
return [

Tests/ContainerBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function testDeprecateParameterThrowsWhenParameterIsUndefined()
151151

152152
public function testDeprecateParameterThrowsWhenParameterBagIsNotInternal()
153153
{
154-
$builder = new ContainerBuilder(new class() implements ParameterBagInterface {
154+
$builder = new ContainerBuilder(new class implements ParameterBagInterface {
155155
public function clear(): void
156156
{
157157
}

Tests/ContainerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public function testInitializedWithPrivateService()
320320
public function testReset()
321321
{
322322
$c = new Container();
323-
$c->set('bar', $bar = new class() implements ResetInterface {
323+
$c->set('bar', $bar = new class implements ResetInterface {
324324
public int $resetCounter = 0;
325325

326326
public function reset(): void

Tests/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ public function testServiceSubscriber()
10611061

10621062
$container->register(TestDefinition1::class, TestDefinition1::class)->setPublic(true);
10631063

1064-
$container->addCompilerPass(new class() implements CompilerPassInterface {
1064+
$container->addCompilerPass(new class implements CompilerPassInterface {
10651065
public function process(ContainerBuilder $container): void
10661066
{
10671067
$container->setDefinition('late_alias', new Definition(TestDefinition1::class))->setPublic(true);

Tests/EnvVarProcessorTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function testGetEnvCachesEnv()
143143
$GLOBALS['ENV_FOO'] = 'value';
144144

145145
$loaders = function () {
146-
yield new class() implements EnvVarLoaderInterface {
146+
yield new class implements EnvVarLoaderInterface {
147147
public function loadEnvVars(): array
148148
{
149149
return ['FOO' => $GLOBALS['ENV_FOO']];
@@ -173,7 +173,7 @@ public function testReset()
173173
$GLOBALS['ENV_FOO'] = 'value';
174174

175175
$loaders = function () {
176-
yield new class() implements EnvVarLoaderInterface {
176+
yield new class implements EnvVarLoaderInterface {
177177
public function loadEnvVars(): array
178178
{
179179
return ['FOO' => $GLOBALS['ENV_FOO']];
@@ -864,13 +864,13 @@ public function testEnvLoader()
864864
$_ENV['BUZ_ENV_LOADER'] = '';
865865

866866
$loaders = function () {
867-
yield new class() implements EnvVarLoaderInterface {
867+
yield new class implements EnvVarLoaderInterface {
868868
public function loadEnvVars(): array
869869
{
870870
return [
871871
'FOO_ENV_LOADER' => '123',
872872
'BAZ_ENV_LOADER' => '',
873-
'LAZY_ENV_LOADER' => new class() {
873+
'LAZY_ENV_LOADER' => new class {
874874
public function __toString(): string
875875
{
876876
return '';
@@ -880,14 +880,14 @@ public function __toString(): string
880880
}
881881
};
882882

883-
yield new class() implements EnvVarLoaderInterface {
883+
yield new class implements EnvVarLoaderInterface {
884884
public function loadEnvVars(): array
885885
{
886886
return [
887887
'FOO_ENV_LOADER' => '234',
888888
'BAR_ENV_LOADER' => '456',
889889
'BAZ_ENV_LOADER' => '567',
890-
'LAZY_ENV_LOADER' => new class() {
890+
'LAZY_ENV_LOADER' => new class {
891891
public function __toString(): string
892892
{
893893
return '678';
@@ -934,7 +934,7 @@ public function testCircularEnvLoader()
934934
throw new ParameterCircularReferenceException(['FOO_CONTAINER']);
935935
}
936936

937-
yield new class() implements EnvVarLoaderInterface {
937+
yield new class implements EnvVarLoaderInterface {
938938
public function loadEnvVars(): array
939939
{
940940
return [

0 commit comments

Comments
 (0)