Skip to content

Commit ac4ba72

Browse files
deguiffabpot
authored andcommitted
Replace get_class() calls by ::class
1 parent 8d2ebdb commit ac4ba72

10 files changed

+16
-16
lines changed

Command/DebugCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private function getClassConstraintsData(ClassMetadataInterface $classMetadata):
135135
{
136136
foreach ($classMetadata->getConstraints() as $constraint) {
137137
yield [
138-
'class' => \get_class($constraint),
138+
'class' => $constraint::class,
139139
'groups' => $constraint->groups,
140140
'options' => $this->getConstraintOptions($constraint),
141141
];
@@ -161,7 +161,7 @@ private function getPropertyData(ClassMetadataInterface $classMetadata, string $
161161
foreach ($propertyMetadata as $metadata) {
162162
foreach ($metadata->getConstraints() as $constraint) {
163163
$data[] = [
164-
'class' => \get_class($constraint),
164+
'class' => $constraint::class,
165165
'groups' => $constraint->groups,
166166
'options' => $this->getConstraintOptions($constraint),
167167
];

Constraints/Composite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function __construct(mixed $options = null, array $groups = null, mixed $
6666
foreach ($nestedConstraints as $constraint) {
6767
if (!$constraint instanceof Constraint) {
6868
if (\is_object($constraint)) {
69-
$constraint = \get_class($constraint);
69+
$constraint = $constraint::class;
7070
}
7171

7272
throw new ConstraintDefinitionException(sprintf('The value "%s" is not an instance of Constraint in constraint "%s".', $constraint, static::class));

Mapping/Factory/LazyLoadingMetadataFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getMetadataFor(mixed $value): MetadataInterface
7474
throw new NoSuchMetadataException(sprintf('Cannot create metadata for non-objects. Got: "%s".', get_debug_type($value)));
7575
}
7676

77-
$class = ltrim(\is_object($value) ? \get_class($value) : $value, '\\');
77+
$class = ltrim(\is_object($value) ? $value::class : $value, '\\');
7878

7979
if (isset($this->loadedClasses[$class])) {
8080
return $this->loadedClasses[$class];
@@ -139,7 +139,7 @@ public function hasMetadataFor(mixed $value): bool
139139
return false;
140140
}
141141

142-
$class = ltrim(\is_object($value) ? \get_class($value) : $value, '\\');
142+
$class = ltrim(\is_object($value) ? $value::class : $value, '\\');
143143

144144
return class_exists($class) || interface_exists($class, false);
145145
}

Mapping/MemberMetadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function isPrivate(object|string $objectOrClassName): bool
132132
*/
133133
public function getReflectionMember(object|string $objectOrClassName): \ReflectionMethod|\ReflectionProperty
134134
{
135-
$className = \is_string($objectOrClassName) ? $objectOrClassName : \get_class($objectOrClassName);
135+
$className = \is_string($objectOrClassName) ? $objectOrClassName : $objectOrClassName::class;
136136
if (!isset($this->reflMember[$className])) {
137137
$this->reflMember[$className] = $this->newReflectionMember($objectOrClassName);
138138
}

Mapping/PropertyMetadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getPropertyValue(mixed $object): mixed
6969

7070
protected function newReflectionMember(object|string $objectOrClassName): \ReflectionMethod|\ReflectionProperty
7171
{
72-
$originalClass = \is_string($objectOrClassName) ? $objectOrClassName : \get_class($objectOrClassName);
72+
$originalClass = \is_string($objectOrClassName) ? $objectOrClassName : $objectOrClassName::class;
7373

7474
while (!property_exists($objectOrClassName, $this->getName())) {
7575
$objectOrClassName = get_parent_class($objectOrClassName);

Test/ConstraintValidatorTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected function setObject(mixed $object)
186186
{
187187
$this->object = $object;
188188
$this->metadata = \is_object($object)
189-
? new ClassMetadata(\get_class($object))
189+
? new ClassMetadata($object::class)
190190
: null;
191191

192192
$this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
@@ -196,7 +196,7 @@ protected function setProperty(mixed $object, string $property)
196196
{
197197
$this->object = $object;
198198
$this->metadata = \is_object($object)
199-
? new PropertyMetadata(\get_class($object), $property)
199+
? new PropertyMetadata($object::class, $property)
200200
: null;
201201

202202
$this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);

Tests/Constraints/AbstractComparisonValidatorTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function testInvalidValuePath()
157157
$constraint = $this->createConstraint(['propertyPath' => 'foo']);
158158

159159
$this->expectException(ConstraintDefinitionException::class);
160-
$this->expectExceptionMessage(sprintf('Invalid property path "foo" provided to "%s" constraint', \get_class($constraint)));
160+
$this->expectExceptionMessage(sprintf('Invalid property path "foo" provided to "%s" constraint', $constraint::class));
161161

162162
$object = new ComparisonTest_Class(5);
163163

@@ -239,7 +239,7 @@ public function throwsOnInvalidStringDatesProvider(): array
239239
'value' => 'foo',
240240
]);
241241

242-
$constraintClass = \get_class($constraint);
242+
$constraintClass = $constraint::class;
243243

244244
return [
245245
[$constraint, sprintf('The compared value "foo" could not be converted to a "DateTimeImmutable" instance in the "%s" constraint.', $constraintClass), new \DateTimeImmutable()],

Tests/Constraints/BicValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function testInvalidValuePath()
163163
$constraint = new Bic(['ibanPropertyPath' => 'foo']);
164164

165165
$this->expectException(ConstraintDefinitionException::class);
166-
$this->expectExceptionMessage(sprintf('Invalid property path "foo" provided to "%s" constraint', \get_class($constraint)));
166+
$this->expectExceptionMessage(sprintf('Invalid property path "foo" provided to "%s" constraint', $constraint::class));
167167

168168
$object = new BicComparisonTestClass(5);
169169

Tests/Validator/RecursiveValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ public function testReplaceDefaultGroup($sequence, array $assertViolations)
12581258
$context->addViolation('Violation in Group 3');
12591259
};
12601260

1261-
$metadata = new ClassMetadata(\get_class($entity));
1261+
$metadata = new ClassMetadata($entity::class);
12621262
$metadata->addConstraint(new Callback([
12631263
'callback' => function () {},
12641264
'groups' => 'Group 1',

Validator/RecursiveContextualValidator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function validateProperty(object $object, string $propertyName, string|Gr
183183
$this->validateGenericNode(
184184
$propertyValue,
185185
$object,
186-
$cacheKey.':'.\get_class($object).':'.$propertyName,
186+
$cacheKey.':'.$object::class.':'.$propertyName,
187187
$propertyMetadata,
188188
$propertyPath,
189189
$groups,
@@ -212,7 +212,7 @@ public function validatePropertyValue(object|string $objectOrClass, string $prop
212212

213213
if (\is_object($objectOrClass)) {
214214
$object = $objectOrClass;
215-
$class = \get_class($object);
215+
$class = $object::class;
216216
$cacheKey = $this->generateCacheKey($objectOrClass);
217217
$propertyPath = PropertyPath::append($this->defaultPropertyPath, $propertyName);
218218
} else {
@@ -501,7 +501,7 @@ private function validateClassNode(object $object, ?string $cacheKey, ClassMetad
501501
$this->validateGenericNode(
502502
$propertyValue,
503503
$object,
504-
$cacheKey.':'.\get_class($object).':'.$propertyName,
504+
$cacheKey.':'.$object::class.':'.$propertyName,
505505
$propertyMetadata,
506506
PropertyPath::append($propertyPath, $propertyName),
507507
$groups,

0 commit comments

Comments
 (0)