Skip to content

Commit ebb9ef0

Browse files
minor #62798 Don't use ->getDeclaringClass() when ->class is enough (nicolas-grekas)
This PR was merged into the 8.1 branch. Discussion ---------- Don't use `->getDeclaringClass()` when `->class` is enough | Q | A | ------------- | --- | Branch? | 8.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Commits ------- 93fd60b Dont use ->getDeclaringClass() when ->class is enough
2 parents 7862a33 + 93fd60b commit ebb9ef0

File tree

14 files changed

+19
-19
lines changed

14 files changed

+19
-19
lines changed

src/Symfony/Component/Console/Attribute/Interact.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public static function tryFrom(\ReflectionMethod $method): ?self
2929
}
3030

3131
if (!$method->isPublic() || $method->isStatic()) {
32-
throw new LogicException(\sprintf('The interactive method "%s::%s()" must be public and non-static.', $method->getDeclaringClass()->getName(), $method->getName()));
32+
throw new LogicException(\sprintf('The interactive method "%s::%s()" must be public and non-static.', $method->class, $method->getName()));
3333
}
3434

3535
if ('__invoke' === $method->getName()) {
36-
throw new LogicException(\sprintf('The "%s::__invoke()" method cannot be used as an interactive method.', $method->getDeclaringClass()->getName()));
36+
throw new LogicException(\sprintf('The "%s::__invoke()" method cannot be used as an interactive method.', $method->class));
3737
}
3838

3939
$self->method = $method;

src/Symfony/Component/Console/Attribute/Reflection/ReflectionMember.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getAttribute(string $class): ?object
3636
public function getSourceName(): string
3737
{
3838
if ($this->member instanceof \ReflectionProperty) {
39-
return $this->member->getDeclaringClass()->name;
39+
return $this->member->class;
4040
}
4141

4242
$function = $this->member->getDeclaringFunction();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function __construct(?string $name = null, ?callable $code = null)
109109
$this->addUsage($usage);
110110
}
111111

112-
if (!$code && \is_callable($this) && self::class === (new \ReflectionMethod($this, 'execute'))->getDeclaringClass()->name) {
112+
if (!$code && \is_callable($this) && self::class === (new \ReflectionMethod($this, 'execute'))->class) {
113113
$this->code = new InvokableCommand($this, $this(...));
114114
}
115115

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
322322

323323
protected function interact(InputInterface $input, OutputInterface $output): void
324324
{
325-
if (!$this->isInteractive = Command::class !== (new \ReflectionMethod($this->command, 'interact'))->getDeclaringClass()->getName()) {
325+
if (!$this->isInteractive = Command::class !== (new \ReflectionMethod($this->command, 'interact'))->class) {
326326
return;
327327
}
328328

src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private function checkType(Definition $checkedDefinition, mixed $value, \Reflect
203203
}
204204

205205
if ('self' === $type) {
206-
$type = $parameter->getDeclaringClass()->getName();
206+
$type = $parameter->getDeclaringClass()->name;
207207
}
208208

209209
if ('static' === $type) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ public function __construct()
12851285
if (null !== $r
12861286
&& (null !== $constructor = $r->getConstructor())
12871287
&& 0 === $constructor->getNumberOfRequiredParameters()
1288-
&& Container::class !== $constructor->getDeclaringClass()->name
1288+
&& Container::class !== $constructor->class
12891289
) {
12901290
$code .= " parent::__construct();\n";
12911291
$code .= " \$this->parameterBag = null;\n\n";

src/Symfony/Component/DependencyInjection/Exception/InvalidParameterTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(string $serviceId, string $type, \ReflectionParamete
2727

2828
$function = $parameter->getDeclaringFunction();
2929
$functionName = $function instanceof \ReflectionMethod
30-
? \sprintf('%s::%s', $function->getDeclaringClass()->getName(), $function->getName())
30+
? \sprintf('%s::%s', $function->class, $function->getName())
3131
: $function->getName();
3232

3333
parent::__construct(\sprintf('Invalid definition for service "%s": argument %d of "%s()" accepts "%s", "%s" passed.', $serviceId, 1 + $parameter->getPosition(), $functionName, $acceptedType, $type));

src/Symfony/Component/Runtime/SymfonyRuntime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function getRunner(?object $application): RunnerInterface
187187
if (!$application->getName() || !$console->has($application->getName())) {
188188
$application->setName($_SERVER['argv'][0]);
189189

190-
if (!method_exists($console, 'addCommand') || method_exists($console, 'add') && (new \ReflectionMethod($console, 'add'))->getDeclaringClass()->getName() !== (new \ReflectionMethod($console, 'addCommand'))->getDeclaringClass()->getName()) {
190+
if (!method_exists($console, 'addCommand') || method_exists($console, 'add') && (new \ReflectionMethod($console, 'add'))->class !== (new \ReflectionMethod($console, 'addCommand'))->class) {
191191
$console->add($application);
192192
} else {
193193
$console->addCommand($application);

src/Symfony/Component/Serializer/Mapping/Loader/AttributeLoader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private function doLoadClassMetadata(\ReflectionClass $reflectionClass, ClassMet
100100
}
101101

102102
$attributeMetadata = $attributesMetadata[$property->name];
103-
if ($property->getDeclaringClass()->name === $className) {
103+
if ($property->class === $className) {
104104
if ($classContextAttribute) {
105105
$this->setAttributeContextsForGroups($classContextAttribute, $attributeMetadata);
106106
}
@@ -133,7 +133,7 @@ private function doLoadClassMetadata(\ReflectionClass $reflectionClass, ClassMet
133133
}
134134

135135
foreach ($reflectionClass->getMethods() as $method) {
136-
if ($method->getDeclaringClass()->name !== $className) {
136+
if ($method->class !== $className) {
137137
continue;
138138
}
139139

@@ -211,8 +211,8 @@ private function loadAttributes(\ReflectionMethod|\ReflectionClass|\ReflectionPr
211211
}
212212
$on = match (true) {
213213
$reflector instanceof \ReflectionClass => ' on class '.$reflector->name,
214-
$reflector instanceof \ReflectionMethod => \sprintf(' on "%s::%s()"', $reflector->getDeclaringClass()->name, $reflector->name),
215-
$reflector instanceof \ReflectionProperty => \sprintf(' on "%s::$%s"', $reflector->getDeclaringClass()->name, $reflector->name),
214+
$reflector instanceof \ReflectionMethod => \sprintf(' on "%s::%s()"', $reflector->class, $reflector->name),
215+
$reflector instanceof \ReflectionProperty => \sprintf(' on "%s::$%s"', $reflector->class, $reflector->name),
216216
default => '',
217217
};
218218

src/Symfony/Component/TypeInfo/TypeResolver/ReflectionPropertyTypeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function resolve(mixed $subject, ?TypeContext $typeContext = null): Type
4141
try {
4242
return $this->reflectionTypeResolver->resolve($subject->getType(), $typeContext);
4343
} catch (UnsupportedException $e) {
44-
$path = \sprintf('%s::$%s', $subject->getDeclaringClass()->getName(), $subject->getName());
44+
$path = \sprintf('%s::$%s', $subject->class, $subject->getName());
4545

4646
throw new UnsupportedException(\sprintf('Cannot resolve type for "%s".', $path), $subject, previous: $e);
4747
}

0 commit comments

Comments
 (0)