Skip to content

Commit dce37b8

Browse files
committed
minor #47752 Leverage class name literal on object (tigitz)
This PR was merged into the 6.3 branch. Discussion ---------- Leverage class name literal on object | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | ### Rational [PHP RFC: Allow ::class on objects](https://wiki.php.net/rfc/class_name_literal_on_object) More specifically > As it is syntactically similar to a class constant access, programmers intuitively expect the syntax $object::class to work as well and provide the same result as get_class($object). This RFC proposes to allow that syntax. Commits ------- 44c7c58 Leverage class name literal on object
2 parents fdd04c7 + 44c7c58 commit dce37b8

File tree

60 files changed

+100
-100
lines changed

Some content is hidden

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

60 files changed

+100
-100
lines changed

src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function testFixManagersAutoMappingsWithTwoAutomappings()
7777
'SecondBundle' => 'My\SecondBundle',
7878
];
7979

80-
$reflection = new \ReflectionClass(\get_class($this->extension));
80+
$reflection = new \ReflectionClass($this->extension);
8181
$method = $reflection->getMethod('fixManagersAutoMappings');
8282

8383
$method->invoke($this->extension, $emConfigs, $bundles);
@@ -165,7 +165,7 @@ public function testFixManagersAutoMappings(array $originalEm1, array $originalE
165165
'SecondBundle' => 'My\SecondBundle',
166166
];
167167

168-
$reflection = new \ReflectionClass(\get_class($this->extension));
168+
$reflection = new \ReflectionClass($this->extension);
169169
$method = $reflection->getMethod('fixManagersAutoMappings');
170170

171171
$newEmConfigs = $method->invoke($this->extension, $emConfigs, $bundles);
@@ -182,7 +182,7 @@ public function testMappingTypeDetection()
182182
{
183183
$container = $this->createContainer();
184184

185-
$reflection = new \ReflectionClass(\get_class($this->extension));
185+
$reflection = new \ReflectionClass($this->extension);
186186
$method = $reflection->getMethod('detectMappingType');
187187

188188
// The ordinary fixtures contain annotation
@@ -326,7 +326,7 @@ public function testBundleAutoMapping(string $bundle, string $expectedType, stri
326326

327327
$container = $this->createContainer([], [$bundle => $bundleClassName]);
328328

329-
$reflection = new \ReflectionClass(\get_class($this->extension));
329+
$reflection = new \ReflectionClass($this->extension);
330330
$method = $reflection->getMethod('getMappingDriverBundleConfigDefaults');
331331

332332
$this->assertSame(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ private function getCallableData(mixed $callable): array
328328

329329
if (\is_object($callable[0])) {
330330
$data['name'] = $callable[1];
331-
$data['class'] = \get_class($callable[0]);
331+
$data['class'] = $callable[0]::class;
332332
} else {
333333
if (!str_starts_with($callable[1], 'parent::')) {
334334
$data['name'] = $callable[1];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ protected function describeCallable(mixed $callable, array $options = [])
345345

346346
if (\is_object($callable[0])) {
347347
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
348-
$string .= "\n".sprintf('- Class: `%s`', \get_class($callable[0]));
348+
$string .= "\n".sprintf('- Class: `%s`', $callable[0]::class);
349349
} else {
350350
if (!str_starts_with($callable[1], 'parent::')) {
351351
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ private function formatCallable(mixed $callable): string
602602
{
603603
if (\is_array($callable)) {
604604
if (\is_object($callable[0])) {
605-
return sprintf('%s::%s()', \get_class($callable[0]), $callable[1]);
605+
return sprintf('%s::%s()', $callable[0]::class, $callable[1]);
606606
}
607607

608608
return sprintf('%s::%s()', $callable[0], $callable[1]);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ private function getCallableDocument(mixed $callable): \DOMDocument
523523

524524
if (\is_object($callable[0])) {
525525
$callableXML->setAttribute('name', $callable[1]);
526-
$callableXML->setAttribute('class', \get_class($callable[0]));
526+
$callableXML->setAttribute('class', $callable[0]::class);
527527
} else {
528528
if (!str_starts_with($callable[1], 'parent::')) {
529529
$callableXML->setAttribute('name', $callable[1]);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private function formatCallable(mixed $callable): string
230230
{
231231
if (\is_array($callable)) {
232232
if (\is_object($callable[0])) {
233-
return sprintf('%s::%s()', \get_class($callable[0]), $callable[1]);
233+
return sprintf('%s::%s()', $callable[0]::class, $callable[1]);
234234
}
235235

236236
return sprintf('%s::%s()', $callable[0], $callable[1]);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function collect(Request $request, Response $response, \Throwable $except
145145
foreach ($decisionLog as $key => $log) {
146146
$decisionLog[$key]['voter_details'] = [];
147147
foreach ($log['voterDetails'] as $voterDetail) {
148-
$voterClass = \get_class($voterDetail['voter']);
148+
$voterClass = $voterDetail['voter']::class;
149149
$classData = $this->hasVarDumper ? new ClassStub($voterClass) : $voterClass;
150150
$decisionLog[$key]['voter_details'][] = [
151151
'class' => $classData,

src/Symfony/Component/Console/Command/CompleteCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
134134
$completionInput->bind($command->getDefinition());
135135

136136
if (CompletionInput::TYPE_OPTION_NAME === $completionInput->getCompletionType()) {
137-
$this->log(' Completing option names for the <comment>'.\get_class($command instanceof LazyCommand ? $command->getCommand() : $command).'</> command.');
137+
$this->log(' Completing option names for the <comment>'.($command instanceof LazyCommand ? $command->getCommand() : $command)::class.'</> command.');
138138

139139
$suggestions->suggestOptions($command->getDefinition()->getOptions());
140140
} else {
141141
$this->log([
142-
' Completing using the <comment>'.\get_class($command instanceof LazyCommand ? $command->getCommand() : $command).'</> class.',
142+
' Completing using the <comment>'.($command instanceof LazyCommand ? $command->getCommand() : $command)::class.'</> class.',
143143
' Completing <comment>'.$completionInput->getCompletionType().'</> for <comment>'.$completionInput->getCompletionName().'</>',
144144
]);
145145
if (null !== $compval = $completionInput->getCompletionValue()) {

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ public function testRenderAnonymousException()
922922
$application = new Application();
923923
$application->setAutoExit(false);
924924
$application->register('foo')->setCode(function () {
925-
throw new \InvalidArgumentException(sprintf('Dummy type "%s" is invalid.', \get_class(new class() { })));
925+
throw new \InvalidArgumentException(sprintf('Dummy type "%s" is invalid.', (new class() { })::class));
926926
});
927927
$tester = new ApplicationTester($application);
928928

@@ -948,7 +948,7 @@ public function testRenderExceptionStackTraceContainsRootException()
948948
$application = new Application();
949949
$application->setAutoExit(false);
950950
$application->register('foo')->setCode(function () {
951-
throw new \InvalidArgumentException(sprintf('Dummy type "%s" is invalid.', \get_class(new class() { })));
951+
throw new \InvalidArgumentException(sprintf('Dummy type "%s" is invalid.', (new class() { })::class));
952952
});
953953
$tester = new ApplicationTester($application);
954954

src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private function findNodes(): array
174174
}
175175

176176
if (!$container->hasDefinition($id)) {
177-
$nodes[$id] = ['class' => str_replace('\\', '\\\\', \get_class($container->get($id))), 'attributes' => $this->options['node.instance']];
177+
$nodes[$id] = ['class' => str_replace('\\', '\\\\', $container->get($id)::class), 'attributes' => $this->options['node.instance']];
178178
}
179179
}
180180

0 commit comments

Comments
 (0)