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

0 commit comments

Comments
 (0)