Skip to content

Commit 0be39ad

Browse files
committed
minor #47401 Replace get_class() calls by ::class (deguif)
This PR was squashed before being merged into the 6.2 branch. Discussion ---------- Replace get_class() calls by ::class | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | Replace `get_class()` by `::class` Commits ------- 675601b Replace get_class() calls by ::class
2 parents 683eeb3 + 675601b commit 0be39ad

File tree

141 files changed

+216
-215
lines changed

Some content is hidden

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

141 files changed

+216
-215
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'no_superfluous_phpdoc_tags' => ['remove_inheritdoc' => true],
3535
'header_comment' => ['header' => $fileHeaderComment],
3636
'modernize_strpos' => true,
37+
'get_class_to_class_keyword' => true,
3738
])
3839
->setRiskyAllowed(true)
3940
->setFinder(

src/Symfony/Bridge/Doctrine/DataCollector/ObjectParameter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(object $object, ?\Throwable $error)
2323
$this->object = $object;
2424
$this->error = $error;
2525
$this->stringable = \is_callable([$object, '__toString']);
26-
$this->class = \get_class($object);
26+
$this->class = $object::class;
2727
}
2828

2929
public function getObject(): object

src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function testSupportProxy()
146146
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
147147

148148
$user2 = $em->getReference('Symfony\Bridge\Doctrine\Tests\Fixtures\User', ['id1' => 1, 'id2' => 1]);
149-
$this->assertTrue($provider->supportsClass(\get_class($user2)));
149+
$this->assertTrue($provider->supportsClass($user2::class));
150150
}
151151

152152
public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided()

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ public function validate(mixed $entity, Constraint $constraint)
7575
throw new ConstraintDefinitionException(sprintf('Object manager "%s" does not exist.', $constraint->em));
7676
}
7777
} else {
78-
$em = $this->registry->getManagerForClass(\get_class($entity));
78+
$em = $this->registry->getManagerForClass($entity::class);
7979

8080
if (!$em) {
8181
throw new ConstraintDefinitionException(sprintf('Unable to find the object manager associated with an entity of class "%s".', get_debug_type($entity)));
8282
}
8383
}
8484

85-
$class = $em->getClassMetadata(\get_class($entity));
85+
$class = $em->getClassMetadata($entity::class);
8686

8787
$criteria = [];
8888
$hasNullValue = false;
@@ -136,7 +136,7 @@ public function validate(mixed $entity, Constraint $constraint)
136136
throw new ConstraintDefinitionException(sprintf('The "%s" entity repository does not support the "%s" entity. The entity should be an instance of or extend "%s".', $constraint->entityClass, $class->getName(), $supportedClass));
137137
}
138138
} else {
139-
$repository = $em->getRepository(\get_class($entity));
139+
$repository = $em->getRepository($entity::class);
140140
}
141141

142142
$arguments = [$criteria];
@@ -203,7 +203,7 @@ private function formatWithIdentifiers(ObjectManager $em, ClassMetadata $class,
203203
return (string) $value;
204204
}
205205

206-
if ($class->getName() !== $idClass = \get_class($value)) {
206+
if ($class->getName() !== $idClass = $value::class) {
207207
// non unique value might be a composite PK that consists of other entity objects
208208
if ($em->getMetadataFactory()->hasMetadataFor($idClass)) {
209209
$identifiers = $em->getClassMetadata($idClass)->getIdentifierValues($value);
@@ -224,7 +224,7 @@ private function formatWithIdentifiers(ObjectManager $em, ClassMetadata $class,
224224
if (!\is_object($id) || $id instanceof \DateTimeInterface) {
225225
$idAsString = $this->formatValue($id, self::PRETTY_DATE);
226226
} else {
227-
$idAsString = sprintf('object("%s")', \get_class($id));
227+
$idAsString = sprintf('object("%s")', $id::class);
228228
}
229229

230230
$id = sprintf('%s => %s', $field, $idAsString);

src/Symfony/Bridge/Doctrine/Validator/DoctrineInitializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public function __construct(ManagerRegistry $registry)
3030

3131
public function initialize(object $object)
3232
{
33-
$this->registry->getManagerForClass(\get_class($object))?->initializeObject($object);
33+
$this->registry->getManagerForClass($object::class)?->initializeObject($object);
3434
}
3535
}

src/Symfony/Bridge/Twig/Mime/NotificationEmail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private function getExceptionAsString(\Throwable|FlattenException $exception): s
208208
return $exception->getAsString();
209209
}
210210

211-
$message = \get_class($exception);
211+
$message = $exception::class;
212212
if ('' !== $exception->getMessage()) {
213213
$message .= ': '.$exception->getMessage();
214214
}

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/ConfigBuilderCacheWarmer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function warmUp(string $cacheDir): array
5353
try {
5454
$this->dumpExtension($extension, $generator);
5555
} catch (\Exception $e) {
56-
$this->logger?->warning('Failed to generate ConfigBuilder for extension {extensionClass}.', ['exception' => $e, 'extensionClass' => \get_class($extension)]);
56+
$this->logger?->warning('Failed to generate ConfigBuilder for extension {extensionClass}.', ['exception' => $e, 'extensionClass' => $extension::class]);
5757
}
5858
}
5959

src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6767
new TableSeparator(),
6868
['<info>Kernel</>'],
6969
new TableSeparator(),
70-
['Type', \get_class($kernel)],
70+
['Type', $kernel::class],
7171
['Environment', $kernel->getEnvironment()],
7272
['Debug', $kernel->isDebug() ? 'true' : 'false'],
7373
['Charset', $kernel->getCharset()],

src/Symfony/Bundle/FrameworkBundle/Command/BuildDebugContainerTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function getContainerBuilder(KernelInterface $kernel): ContainerBuilde
4444
$this->initializeBundles();
4545

4646
return $this->buildContainer();
47-
}, $kernel, \get_class($kernel));
47+
}, $kernel, $kernel::class);
4848
$container = $buildContainer();
4949
$container->getCompilerPassConfig()->setRemovingPasses([]);
5050
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);

src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function getContainerBuilder(): ContainerBuilder
8686
$this->initializeBundles();
8787

8888
return $this->buildContainer();
89-
}, $kernel, \get_class($kernel));
89+
}, $kernel, $kernel::class);
9090
$container = $buildContainer();
9191

9292
$skippedIds = [];

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ protected function formatValue(mixed $value): string
158158
}
159159

160160
if (\is_object($value)) {
161-
return sprintf('object(%s)', \get_class($value));
161+
return sprintf('object(%s)', $value::class);
162162
}
163163

164164
if (\is_string($value)) {
@@ -335,7 +335,7 @@ private function getContainerEnvVars(ContainerBuilder $container): array
335335
$getDefaultParameter = function (string $name) {
336336
return parent::get($name);
337337
};
338-
$getDefaultParameter = $getDefaultParameter->bindTo($bag, \get_class($bag));
338+
$getDefaultParameter = $getDefaultParameter->bindTo($bag, $bag::class);
339339

340340
$getEnvReflection = new \ReflectionMethod($container, 'getEnv');
341341

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function describeContainerService(object $service, array $options = []
7878
} elseif ($service instanceof Definition) {
7979
$this->writeData($this->getContainerDefinitionData($service, isset($options['omit_tags']) && $options['omit_tags'], isset($options['show_arguments']) && $options['show_arguments'], $builder, $options['id']), $options);
8080
} else {
81-
$this->writeData(\get_class($service), $options);
81+
$this->writeData($service::class, $options);
8282
}
8383
}
8484

@@ -108,7 +108,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
108108
} elseif ($service instanceof Definition) {
109109
$data['definitions'][$serviceId] = $this->getContainerDefinitionData($service, $omitTags, $showArguments, $builder, $serviceId);
110110
} else {
111-
$data['services'][$serviceId] = \get_class($service);
111+
$data['services'][$serviceId] = $service::class;
112112
}
113113
}
114114

@@ -204,7 +204,7 @@ protected function getRouteData(Route $route): array
204204
'hostRegex' => '' !== $route->getHost() ? $route->compile()->getHostRegex() : '',
205205
'scheme' => $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY',
206206
'method' => $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY',
207-
'class' => \get_class($route),
207+
'class' => $route::class,
208208
'defaults' => $route->getDefaults(),
209209
'requirements' => $route->getRequirements() ?: 'NO CUSTOM',
210210
'options' => $route->getOptions(),
@@ -382,7 +382,7 @@ private function getCallableData(mixed $callable): array
382382

383383
if (method_exists($callable, '__invoke')) {
384384
$data['type'] = 'object';
385-
$data['name'] = \get_class($callable);
385+
$data['name'] = $callable::class;
386386

387387
return $data;
388388
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function describeRoute(Route $route, array $options = [])
5151
."\n".'- Host Regex: '.('' !== $route->getHost() ? $route->compile()->getHostRegex() : '')
5252
."\n".'- Scheme: '.($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY')
5353
."\n".'- Method: '.($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY')
54-
."\n".'- Class: '.\get_class($route)
54+
."\n".'- Class: '.$route::class
5555
."\n".'- Defaults: '.$this->formatRouterConfig($route->getDefaults())
5656
."\n".'- Requirements: '.($route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM')
5757
."\n".'- Options: '.$this->formatRouterConfig($route->getOptions());
@@ -101,7 +101,7 @@ protected function describeContainerService(object $service, array $options = []
101101
} elseif ($service instanceof Definition) {
102102
$this->describeContainerDefinition($service, $childOptions, $builder);
103103
} else {
104-
$this->write(sprintf('**`%s`:** `%s`', $options['id'], \get_class($service)));
104+
$this->write(sprintf('**`%s`:** `%s`', $options['id'], $service::class));
105105
}
106106
}
107107

@@ -188,7 +188,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
188188
$this->write("\n\nServices\n--------\n");
189189
foreach ($services['services'] as $id => $service) {
190190
$this->write("\n");
191-
$this->write(sprintf('- `%s`: `%s`', $id, \get_class($service)));
191+
$this->write(sprintf('- `%s`: `%s`', $id, $service::class));
192192
}
193193
}
194194
}
@@ -399,7 +399,7 @@ protected function describeCallable(mixed $callable, array $options = [])
399399

400400
if (method_exists($callable, '__invoke')) {
401401
$string .= "\n- Type: `object`";
402-
$string .= "\n".sprintf('- Name: `%s`', \get_class($callable));
402+
$string .= "\n".sprintf('- Name: `%s`', $callable::class);
403403

404404
return $this->write($string."\n");
405405
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected function describeRoute(Route $route, array $options = [])
9898
['Scheme', $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'],
9999
['Method', $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'],
100100
['Requirements', $route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM'],
101-
['Class', \get_class($route)],
101+
['Class', $route::class],
102102
['Defaults', $this->formatRouterConfig($defaults)],
103103
['Options', $this->formatRouterConfig($route->getOptions())],
104104
];
@@ -156,7 +156,7 @@ protected function describeContainerService(object $service, array $options = []
156156
$options['output']->table(
157157
['Service ID', 'Class'],
158158
[
159-
[$options['id'] ?? '-', \get_class($service)],
159+
[$options['id'] ?? '-', $service::class],
160160
]
161161
);
162162
}
@@ -244,7 +244,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
244244
$alias = $definition;
245245
$tableRows[] = array_merge([$styledServiceId, sprintf('alias for "%s"', $alias)], $tagsCount ? array_fill(0, $tagsCount, '') : []);
246246
} else {
247-
$tableRows[] = array_merge([$styledServiceId, \get_class($definition)], $tagsCount ? array_fill(0, $tagsCount, '') : []);
247+
$tableRows[] = array_merge([$styledServiceId, $definition::class], $tagsCount ? array_fill(0, $tagsCount, '') : []);
248248
}
249249
}
250250

@@ -625,7 +625,7 @@ private function formatCallable(mixed $callable): string
625625
}
626626

627627
if (method_exists($callable, '__invoke')) {
628-
return sprintf('%s::__invoke()', \get_class($callable));
628+
return sprintf('%s::__invoke()', $callable::class);
629629
}
630630

631631
throw new \InvalidArgumentException('Callable is not describable.');

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private function getRouteDocument(Route $route, string $name = null): \DOMDocume
164164
$routeXML->setAttribute('name', $name);
165165
}
166166

167-
$routeXML->setAttribute('class', \get_class($route));
167+
$routeXML->setAttribute('class', $route::class);
168168

169169
$routeXML->appendChild($pathXML = $dom->createElement('path'));
170170
$pathXML->setAttribute('regex', $route->compile()->getRegex());
@@ -269,7 +269,7 @@ private function getContainerServiceDocument(object $service, string $id, Contai
269269
} else {
270270
$dom->appendChild($serviceXML = $dom->createElement('service'));
271271
$serviceXML->setAttribute('id', $id);
272-
$serviceXML->setAttribute('class', \get_class($service));
272+
$serviceXML->setAttribute('class', $service::class);
273273
}
274274

275275
return $dom;
@@ -577,7 +577,7 @@ private function getCallableDocument(mixed $callable): \DOMDocument
577577

578578
if (method_exists($callable, '__invoke')) {
579579
$callableXML->setAttribute('type', 'object');
580-
$callableXML->setAttribute('name', \get_class($callable));
580+
$callableXML->setAttribute('name', $callable::class);
581581

582582
return $dom;
583583
}

src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testCacheIsWarmedWithOldContainer()
126126
\Closure::bind(function (Container $class) {
127127
unset($class->loadedDynamicParameters['kernel.build_dir']);
128128
unset($class->parameters['kernel.build_dir']);
129-
}, null, \get_class($container))($container);
129+
}, null, $container::class)($container);
130130

131131
$input = new ArrayInput(['cache:clear']);
132132
$application = new Application($kernel);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ public function testValidCollectorWithTemplateUsingAutoconfigure(TemplateAwareDa
105105
$profilerDefinition = $container->register('profiler', 'ProfilerClass');
106106

107107
$container->registerForAutoconfiguration(DataCollectorInterface::class)->addTag('data_collector');
108-
$container->register('mydatacollector', \get_class($dataCollector))->setAutoconfigured(true);
108+
$container->register('mydatacollector', $dataCollector::class)->setAutoconfigured(true);
109109

110110
(new ResolveInstanceofConditionalsPass())->process($container);
111111
(new ProfilerPass())->process($container);
112112

113-
$idForTemplate = \get_class($dataCollector);
113+
$idForTemplate = $dataCollector::class;
114114
$this->assertSame(['mydatacollector' => [$idForTemplate, 'foo']], $container->getParameter('data_collector.templates'));
115115

116116
// grab the method calls off of the "profiler" definition

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/AnnotatedController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AnnotatedController
2222
*/
2323
public function requestDefaultNullAction(Request $request = null)
2424
{
25-
return new Response($request ? \get_class($request) : null);
25+
return new Response($request ? $request::class : null);
2626
}
2727

2828
/**

src/Symfony/Bundle/SecurityBundle/Command/DebugFirewallCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private function displayAuthenticators(string $name, SymfonyStyle $io): void
218218
array_map(
219219
static function ($authenticator) {
220220
return [
221-
\get_class($authenticator),
221+
$authenticator::class,
222222
];
223223
},
224224
$authenticators
@@ -253,7 +253,7 @@ private function formatCallable(mixed $callable): string
253253
}
254254

255255
if (method_exists($callable, '__invoke')) {
256-
return sprintf('%s::__invoke()', \get_class($callable));
256+
return sprintf('%s::__invoke()', $callable::class);
257257
}
258258

259259
throw new \InvalidArgumentException('Callable is not describable.');

src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function collect(Request $request, Response $response, \Throwable $except
119119
'impersonator_user' => $impersonatorUser,
120120
'impersonation_exit_path' => null,
121121
'token' => $token,
122-
'token_class' => $this->hasVarDumper ? new ClassStub(\get_class($token)) : \get_class($token),
122+
'token_class' => $this->hasVarDumper ? new ClassStub($token::class) : $token::class,
123123
'logout_url' => $logoutUrl,
124124
'user' => $token->getUserIdentifier(),
125125
'roles' => $assignedRoles,
@@ -137,7 +137,7 @@ public function collect(Request $request, Response $response, \Throwable $except
137137
$voter = $voter->getDecoratedVoter();
138138
}
139139

140-
$this->data['voters'][] = $this->hasVarDumper ? new ClassStub(\get_class($voter)) : \get_class($voter);
140+
$this->data['voters'][] = $this->hasVarDumper ? new ClassStub($voter::class) : $voter::class;
141141
}
142142

143143
// collect voter details

0 commit comments

Comments
 (0)