Skip to content

Commit

Permalink
Use properties instead of getters to read property/class names via re…
Browse files Browse the repository at this point in the history
…flection
  • Loading branch information
nicolas-grekas committed Jul 20, 2023
1 parent bc61d7d commit dcd8a2b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ public function initializeReflection($reflService)
$this->namespace = $reflService->getClassNamespace($this->name);

if ($this->reflClass) {
$this->name = $this->rootEntityName = $this->reflClass->getName();
$this->name = $this->rootEntityName = $this->reflClass->name;
}

$this->table['name'] = $this->namingStrategy->classToTableName($this->name);
Expand Down Expand Up @@ -3866,7 +3866,7 @@ private function getAccessibleProperty(ReflectionService $reflService, string $c
{
$reflectionProperty = $reflService->getAccessibleProperty($class, $field);
if ($reflectionProperty !== null && PHP_VERSION_ID >= 80100 && $reflectionProperty->isReadOnly()) {
$declaringClass = $reflectionProperty->getDeclaringClass()->name;
$declaringClass = $reflectionProperty->class;
if ($declaringClass !== $class) {
$reflectionProperty = $reflService->getAccessibleProperty($declaringClass, $field);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
}

$mapping = [];
$mapping['fieldName'] = $property->getName();
$mapping['fieldName'] = $property->name;

// Evaluate @Cache annotation
$cacheAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Cache::class);
Expand Down Expand Up @@ -398,7 +398,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
// @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
$columnAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Column::class);
if ($columnAnnot) {
$mapping = $this->columnToArray($property->getName(), $columnAnnot);
$mapping = $this->columnToArray($property->name, $columnAnnot);

$idAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Id::class);
if ($idAnnot) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
}

$mapping = [];
$mapping['fieldName'] = $property->getName();
$mapping['fieldName'] = $property->name;

// Evaluate #[Cache] attribute
$cacheAttribute = $this->reader->getPropertyAttribute($property, Mapping\Cache::class);
Expand Down Expand Up @@ -350,7 +350,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
$embeddedAttribute = $this->reader->getPropertyAttribute($property, Mapping\Embedded::class);

if ($columnAttribute !== null) {
$mapping = $this->columnToArray($property->getName(), $columnAttribute);
$mapping = $this->columnToArray($property->name, $columnAttribute);

if ($this->reader->getPropertyAttribute($property, Mapping\Id::class)) {
$mapping['id'] = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Mapping/Driver/ReflectionBasedDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private function isRepeatedPropertyDeclaration(ReflectionProperty $property, Cla
|| $metadata->isInheritedEmbeddedClass($property->name);
}

$declaringClass = $property->getDeclaringClass()->getName();
$declaringClass = $property->class;

if (
isset($metadata->fieldMappings[$property->name]['declared'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function getHierarchyClasses(string $className): array

$parentClass = $currentClass->getParentClass();
if ($parentClass) {
$parentClassName = $parentClass->getName();
$parentClassName = $parentClass->name;
}
}

Expand Down Expand Up @@ -111,14 +111,14 @@ private function isInstanceProperty(ReflectionProperty $reflectionProperty): boo
private function getAccessibleProperty(ReflectionProperty $property): ?ReflectionProperty
{
return $this->reflectionService->getAccessibleProperty(
$property->getDeclaringClass()->getName(),
$property->getName()
$property->class,
$property->name
);
}

private function getLogicalName(ReflectionProperty $property): string
{
$propertyName = $property->getName();
$propertyName = $property->name;

if ($property->isPublic()) {
return $propertyName;
Expand All @@ -128,6 +128,6 @@ private function getLogicalName(ReflectionProperty $property): string
return "\0*\0" . $propertyName;
}

return "\0" . $property->getDeclaringClass()->getName() . "\0" . $propertyName;
return "\0" . $property->class . "\0" . $propertyName;
}
}
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(ReflectionProperty $parentProperty, ReflectionProper
$this->childProperty = $childProperty;
$this->embeddedClass = (string) $embeddedClass;

parent::__construct($childProperty->getDeclaringClass()->getName(), $childProperty->getName());
parent::__construct($childProperty->class, $childProperty->name);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Mapping/ReflectionEnumProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function __construct(ReflectionProperty $originalReflectionProperty, stri
$this->enumType = $enumType;

parent::__construct(
$originalReflectionProperty->getDeclaringClass()->getName(),
$originalReflectionProperty->getName()
$originalReflectionProperty->class,
$originalReflectionProperty->name
);
}

Expand Down Expand Up @@ -98,7 +98,7 @@ private function initializeEnumValue($object, $value): BackedEnum
} catch (ValueError $e) {
throw MappingException::invalidEnumValue(
get_class($object),
$this->originalReflectionProperty->getName(),
$this->originalReflectionProperty->name,
(string) $value,
$enumType,
$e
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,13 @@ private function generateSkippedProperties(ClassMetadata $class): string

while ($reflector) {
foreach ($reflector->getProperties($filter) as $property) {
$name = $property->getName();
$name = $property->name;

if ($property->isStatic() || (($class->hasField($name) || $class->hasAssociation($name)) && ! isset($identifiers[$name]))) {
continue;
}

$prefix = $property->isPrivate() ? "\0" . $property->getDeclaringClass()->getName() . "\0" : ($property->isProtected() ? "\0*\0" : '');
$prefix = $property->isPrivate() ? "\0" . $property->class . "\0" : ($property->isProtected() ? "\0*\0" : '');

$skippedProperties[$prefix . $name] = true;
}
Expand All @@ -353,7 +353,7 @@ private function generateSkippedProperties(ClassMetadata $class): string
uksort($skippedProperties, 'strnatcmp');

$code = VarExporter::export($skippedProperties);
$code = str_replace(VarExporter::export($class->getName()), 'parent::class', $code);
$code = str_replace(VarExporter::export($class->name), 'parent::class', $code);

Check failure on line 356 in lib/Doctrine/ORM/Proxy/ProxyFactory.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm

NoInterfaceProperties

lib/Doctrine/ORM/Proxy/ProxyFactory.php:356:49: NoInterfaceProperties: Interfaces cannot have properties (see https://psalm.dev/028)
$code = str_replace("\n", "\n ", $code);

return $code;
Expand All @@ -376,7 +376,7 @@ private function generateSerializeImpl(ClassMetadata $class): string
return $code . '$data = [];
foreach (parent::__sleep() as $name) {
$value = $properties[$k = $name] ?? $properties[$k = "\0*\0$name"] ?? $properties[$k = "\0' . $reflector->getName() . '\0$name"] ?? $k = null;
$value = $properties[$k = $name] ?? $properties[$k = "\0*\0$name"] ?? $properties[$k = "\0' . $reflector->name) . '\0$name"] ?? $k = null;

Check failure on line 379 in lib/Doctrine/ORM/Proxy/ProxyFactory.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm

ParseError

lib/Doctrine/ORM/Proxy/ProxyFactory.php:379:123: ParseError: Syntax error, unexpected ')', expecting ';' on line 379 (see https://psalm.dev/173)
if (null === $k) {
trigger_error(sprintf(\'serialize(): "%s" returned as member variable from __sleep() but does not exist\', $name), \E_USER_NOTICE);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ protected function getClassToExtendName()
{
$refl = new ReflectionClass($this->getClassToExtend());

return '\\' . $refl->getName();
return '\\' . $refl->name;
}

/** @return string */
Expand Down

0 comments on commit dcd8a2b

Please sign in to comment.