Skip to content

Commit 90b42f9

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 ------- 675601b8f7 Replace get_class() calls by ::class
2 parents e53292d + ba9af66 commit 90b42f9

File tree

12 files changed

+25
-25
lines changed

12 files changed

+25
-25
lines changed

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

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()],

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([]);

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 = [];

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

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
}

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
}

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.');

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
}

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);

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

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
/**

0 commit comments

Comments
 (0)