Skip to content

Commit 1e69e2f

Browse files
deguiffabpot
authored andcommitted
Replace get_class() calls by ::class
1 parent e48911d commit 1e69e2f

17 files changed

+30
-30
lines changed

Extractor/ObjectPropertyListExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(PropertyListExtractorInterface $propertyListExtracto
2929

3030
public function getProperties(object $object, array $context = []): ?array
3131
{
32-
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
32+
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : $object::class;
3333

3434
return $this->propertyListExtractor->getProperties($class, $context);
3535
}

Mapping/ClassDiscriminatorFromClassMetadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getMappingForMappedObject(object|string $object): ?ClassDiscrimi
4848
}
4949
}
5050

51-
$cacheKey = \is_object($object) ? \get_class($object) : $object;
51+
$cacheKey = \is_object($object) ? $object::class : $object;
5252
if (!\array_key_exists($cacheKey, $this->mappingForMappedObjectCache)) {
5353
$this->mappingForMappedObjectCache[$cacheKey] = $this->resolveMappingForMappedObject($object);
5454
}

Mapping/Factory/ClassResolverTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ private function getClass(object|string $value): string
3737
return ltrim($value, '\\');
3838
}
3939

40-
return \get_class($value);
40+
return $value::class;
4141
}
4242
}

Mapping/Factory/CompiledClassMetadataFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(string $compiledClassMetadataFile, ClassMetadataFact
4444

4545
public function getMetadataFor(string|object $value): ClassMetadataInterface
4646
{
47-
$className = \is_object($value) ? \get_class($value) : $value;
47+
$className = \is_object($value) ? $value::class : $value;
4848

4949
if (!isset($this->compiledClassMetadata[$className])) {
5050
return $this->classMetadataFactory->getMetadataFor($value);
@@ -69,7 +69,7 @@ public function getMetadataFor(string|object $value): ClassMetadataInterface
6969

7070
public function hasMetadataFor(mixed $value): bool
7171
{
72-
$className = \is_object($value) ? \get_class($value) : $value;
72+
$className = \is_object($value) ? $value::class : $value;
7373

7474
return isset($this->compiledClassMetadata[$className]) || $this->classMetadataFactory->hasMetadataFor($value);
7575
}

Normalizer/AbstractObjectNormalizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function normalize(mixed $object, string $format = null, array $context =
156156
$data = [];
157157
$stack = [];
158158
$attributes = $this->getAttributes($object, $format, $context);
159-
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
159+
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : $object::class;
160160
$attributesMetadata = $this->classMetadataFactory?->getMetadataFor($class)->getAttributesMetadata();
161161
if (isset($context[self::MAX_DEPTH_HANDLER])) {
162162
$maxDepthHandler = $context[self::MAX_DEPTH_HANDLER];
@@ -248,7 +248,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex
248248
*/
249249
protected function getAttributes(object $object, ?string $format, array $context): array
250250
{
251-
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
251+
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : $object::class;
252252
$key = $class.'-'.$context['cache_key'];
253253

254254
if (isset($this->attributesCache[$key])) {
@@ -318,7 +318,7 @@ public function denormalize(mixed $data, string $type, string $format = null, ar
318318

319319
$reflectionClass = new \ReflectionClass($type);
320320
$object = $this->instantiateObject($normalizedData, $type, $context, $reflectionClass, $allowedAttributes, $format);
321-
$resolvedClass = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
321+
$resolvedClass = $this->objectClassResolver ? ($this->objectClassResolver)($object) : $object::class;
322322

323323
foreach ($normalizedData as $attribute => $value) {
324324
if ($this->nameConverter) {

Normalizer/GetSetMethodNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function getAttributeValue(object $object, string $attribute, string $
137137
protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = [])
138138
{
139139
$setter = 'set'.ucfirst($attribute);
140-
$key = \get_class($object).':'.$setter;
140+
$key = $object::class.':'.$setter;
141141

142142
if (!isset(self::$setterAccessibleCache[$key])) {
143143
self::$setterAccessibleCache[$key] = \is_callable([$object, $setter]) && !(new \ReflectionMethod($object, $setter))->isStatic();

Normalizer/MimeMessageNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function normalize(mixed $object, string $format = null, array $context =
6161

6262
if ($object instanceof AbstractPart) {
6363
$ret = $this->normalizer->normalize($object, $format, $context);
64-
$ret['class'] = \get_class($object);
64+
$ret['class'] = $object::class;
6565

6666
return $ret;
6767
}

Normalizer/ObjectNormalizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
4545
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
4646

4747
$this->objectClassResolver = $objectClassResolver ?? function ($class) {
48-
return \is_object($class) ? \get_class($class) : $class;
48+
return \is_object($class) ? $class::class : $class;
4949
};
5050
}
5151

@@ -56,7 +56,7 @@ public function hasCacheableSupportsMethod(): bool
5656

5757
protected function extractAttributes(object $object, string $format = null, array $context = []): array
5858
{
59-
if (\stdClass::class === \get_class($object)) {
59+
if (\stdClass::class === $object::class) {
6060
return array_keys((array) $object);
6161
}
6262

@@ -119,7 +119,7 @@ protected function extractAttributes(object $object, string $format = null, arra
119119

120120
protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = []): mixed
121121
{
122-
$cacheKey = \get_class($object);
122+
$cacheKey = $object::class;
123123
if (!\array_key_exists($cacheKey, $this->discriminatorCache)) {
124124
$this->discriminatorCache[$cacheKey] = null;
125125
if (null !== $this->classDiscriminatorResolver) {
@@ -147,7 +147,7 @@ protected function getAllowedAttributes(string|object $classOrObject, array $con
147147
}
148148

149149
if (null !== $this->classDiscriminatorResolver) {
150-
$class = \is_object($classOrObject) ? \get_class($classOrObject) : $classOrObject;
150+
$class = \is_object($classOrObject) ? $classOrObject::class : $classOrObject;
151151
if (null !== $discriminatorMapping = $this->classDiscriminatorResolver->getMappingForMappedObject($classOrObject)) {
152152
$allowedAttributes[] = $attributesAsString ? $discriminatorMapping->getTypeProperty() : new AttributeMetadata($discriminatorMapping->getTypeProperty());
153153
}

Normalizer/PropertyNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
5959
*/
6060
public function supportsNormalization(mixed $data, string $format = null /* , array $context = [] */): bool
6161
{
62-
return parent::supportsNormalization($data, $format) && $this->supports(\get_class($data));
62+
return parent::supportsNormalization($data, $format) && $this->supports($data::class);
6363
}
6464

6565
/**
@@ -164,7 +164,7 @@ protected function getAttributeValue(object $object, string $attribute, string $
164164
|| ($reflectionProperty->isProtected() && !\array_key_exists("\0*\0{$reflectionProperty->name}", $propertyValues))
165165
|| ($reflectionProperty->isPrivate() && !\array_key_exists("\0{$reflectionProperty->class}\0{$reflectionProperty->name}", $propertyValues))
166166
) {
167-
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not initialized.', \get_class($object), $reflectionProperty->name));
167+
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not initialized.', $object::class, $reflectionProperty->name));
168168
}
169169
}
170170

Serializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public function supportsDenormalization(mixed $data, string $type, string $forma
246246
*/
247247
private function getNormalizer(mixed $data, ?string $format, array $context): ?NormalizerInterface
248248
{
249-
$type = \is_object($data) ? \get_class($data) : 'native-'.\gettype($data);
249+
$type = \is_object($data) ? $data::class : 'native-'.\gettype($data);
250250

251251
if (!isset($this->normalizerCache[$format][$type])) {
252252
$this->normalizerCache[$format][$type] = [];

Tests/Debug/TraceableEncoderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public function testCollectEncodingData()
5050
$dataCollector
5151
->expects($this->once())
5252
->method('collectEncoding')
53-
->with($this->isType('string'), \get_class($encoder), $this->isType('float'));
53+
->with($this->isType('string'), $encoder::class, $this->isType('float'));
5454
$dataCollector
5555
->expects($this->once())
5656
->method('collectDecoding')
57-
->with($this->isType('string'), \get_class($decoder), $this->isType('float'));
57+
->with($this->isType('string'), $decoder::class, $this->isType('float'));
5858

5959
(new TraceableEncoder($encoder, $dataCollector))->encode('data', 'format', [TraceableSerializer::DEBUG_TRACE_ID => 'debug']);
6060
(new TraceableEncoder($decoder, $dataCollector))->decode('data', 'format', [TraceableSerializer::DEBUG_TRACE_ID => 'debug']);

Tests/Debug/TraceableNormalizerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public function testCollectNormalizationData()
5050
$dataCollector
5151
->expects($this->once())
5252
->method('collectNormalization')
53-
->with($this->isType('string'), \get_class($normalizer), $this->isType('float'));
53+
->with($this->isType('string'), $normalizer::class, $this->isType('float'));
5454
$dataCollector
5555
->expects($this->once())
5656
->method('collectDenormalization')
57-
->with($this->isType('string'), \get_class($denormalizer), $this->isType('float'));
57+
->with($this->isType('string'), $denormalizer::class, $this->isType('float'));
5858

5959
(new TraceableNormalizer($normalizer, $dataCollector))->normalize('data', 'format', [TraceableSerializer::DEBUG_TRACE_ID => 'debug']);
6060
(new TraceableNormalizer($denormalizer, $dataCollector))->denormalize('data', 'type', 'format', [TraceableSerializer::DEBUG_TRACE_ID => 'debug']);

Tests/Extractor/ObjectPropertyListExtractorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testGetPropertiesWithoutObjectClassResolver()
2626
$propertyListExtractor = $this->createMock(PropertyListExtractorInterface::class);
2727
$propertyListExtractor->expects($this->once())
2828
->method('getProperties')
29-
->with(\get_class($object), $context)
29+
->with($object::class, $context)
3030
->willReturn($properties);
3131

3232
$this->assertSame(

Tests/Mapping/Factory/CacheMetadataFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testAnonymousClass()
7070
$anonymousObject = new class() {
7171
};
7272

73-
$metadata = new ClassMetadata(\get_class($anonymousObject));
73+
$metadata = new ClassMetadata($anonymousObject::class);
7474
$decorated = $this->createMock(ClassMetadataFactoryInterface::class);
7575
$decorated
7676
->expects($this->once())

Tests/Normalizer/Features/CallbacksTestTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public function __construct()
107107
}
108108
};
109109

110-
$obj = $normalizer->denormalize(['foo' => $valueBar], \get_class($objWithNoConstructorArgument), 'any', ['callbacks' => $callbacks]);
111-
$this->assertInstanceof(\get_class($objWithNoConstructorArgument), $obj);
110+
$obj = $normalizer->denormalize(['foo' => $valueBar], $objWithNoConstructorArgument::class, 'any', ['callbacks' => $callbacks]);
111+
$this->assertInstanceof($objWithNoConstructorArgument::class, $obj);
112112
$this->assertEquals($result->getBar(), $obj->getBar());
113113
}
114114

Tests/Normalizer/Features/CircularReferenceTestTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testUnableToNormalizeCircularReference(array $defaultContext, ar
4242
$obj = $this->getSelfReferencingModel();
4343

4444
$this->expectException(CircularReferenceException::class);
45-
$this->expectExceptionMessage(sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d).', \get_class($obj), $expectedLimit));
45+
$this->expectExceptionMessage(sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d).', $obj::class, $expectedLimit));
4646
$normalizer->normalize($obj, null, $context);
4747
}
4848

@@ -51,15 +51,15 @@ public function testCircularReferenceHandler()
5151
$normalizer = $this->getNormalizerForCircularReference([]);
5252

5353
$obj = $this->getSelfReferencingModel();
54-
$expected = ['me' => \get_class($obj)];
54+
$expected = ['me' => $obj::class];
5555

5656
$context = [
5757
'circular_reference_handler' => function ($actualObj, string $format, array $context) use ($obj) {
58-
$this->assertInstanceOf(\get_class($obj), $actualObj);
58+
$this->assertInstanceOf($obj::class, $actualObj);
5959
$this->assertSame('test', $format);
6060
$this->assertArrayHasKey('foo', $context);
6161

62-
return \get_class($actualObj);
62+
return $actualObj::class;
6363
},
6464
'foo' => 'bar',
6565
];

Tests/Normalizer/PropertyNormalizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ public function testMultiDimensionObject()
453453
RootDummy::class,
454454
'any'
455455
);
456-
$this->assertEquals(\get_class($root), RootDummy::class);
456+
$this->assertEquals($root::class, RootDummy::class);
457457

458458
// children (two dimension array)
459459
$this->assertCount(1, $root->children);

0 commit comments

Comments
 (0)