Skip to content

Commit ff198c9

Browse files
committed
ExtendedPropertyReflection::getName()
1 parent a3c6cad commit ff198c9

22 files changed

+84
-14
lines changed

src/Reflection/Annotations/AnnotationPropertyReflection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ final class AnnotationPropertyReflection implements ExtendedPropertyReflection
1414
{
1515

1616
public function __construct(
17+
private string $name,
1718
private ClassReflection $declaringClass,
1819
private Type $readableType,
1920
private Type $writableType,
@@ -23,6 +24,11 @@ public function __construct(
2324
{
2425
}
2526

27+
public function getName(): string
28+
{
29+
return $this->name;
30+
}
31+
2632
public function getDeclaringClass(): ClassReflection
2733
{
2834
return $this->declaringClass;

src/Reflection/Annotations/AnnotationsPropertiesClassReflectionExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ private function findClassReflectionWithProperty(
5252
}
5353

5454
return new AnnotationPropertyReflection(
55+
$propertyName,
5556
$declaringClass,
5657
TemplateTypeHelper::resolveTemplateTypes(
5758
$propertyTag->getReadableType() ?? new NeverType(),

src/Reflection/ClassReflection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,13 @@ private function wrapExtendedMethod(MethodReflection $method): ExtendedMethodRef
551551
return new WrappedExtendedMethodReflection($method);
552552
}
553553

554-
private function wrapExtendedProperty(PropertyReflection $method): ExtendedPropertyReflection
554+
private function wrapExtendedProperty(string $propertyName, PropertyReflection $method): ExtendedPropertyReflection
555555
{
556556
if ($method instanceof ExtendedPropertyReflection) {
557557
return $method;
558558
}
559559

560-
return new WrappedExtendedPropertyReflection($method);
560+
return new WrappedExtendedPropertyReflection($propertyName, $method);
561561
}
562562

563563
public function hasNativeMethod(string $methodName): bool
@@ -663,7 +663,7 @@ public function getProperty(string $propertyName, ClassMemberAccessAnswerer $sco
663663
continue;
664664
}
665665

666-
$property = $this->wrapExtendedProperty($extension->getProperty($this, $propertyName));
666+
$property = $this->wrapExtendedProperty($propertyName, $extension->getProperty($this, $propertyName));
667667
if ($scope->canReadProperty($property)) {
668668
return $this->properties[$key] = $property;
669669
}

src/Reflection/Dummy/ChangedTypePropertyReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public function __construct(private ClassReflection $declaringClass, private Ext
1616
{
1717
}
1818

19+
public function getName(): string
20+
{
21+
return $this->reflection->getName();
22+
}
23+
1924
public function getDeclaringClass(): ClassReflection
2025
{
2126
return $this->declaringClass;

src/Reflection/Dummy/DummyPropertyReflection.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
final class DummyPropertyReflection implements ExtendedPropertyReflection
1616
{
1717

18+
public function __construct(private string $name)
19+
{
20+
}
21+
22+
public function getName(): string
23+
{
24+
return $this->name;
25+
}
26+
1827
public function getDeclaringClass(): ClassReflection
1928
{
2029
$reflectionProvider = ReflectionProviderStaticAccessor::getInstance();

src/Reflection/ExtendedPropertyReflection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ interface ExtendedPropertyReflection extends PropertyReflection
2626

2727
public const HOOK_SET = 'set';
2828

29+
public function getName(): string;
30+
2931
public function hasPhpDocType(): bool;
3032

3133
public function getPhpDocType(): Type;

src/Reflection/Php/EnumPropertyReflection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313
final class EnumPropertyReflection implements ExtendedPropertyReflection
1414
{
1515

16-
public function __construct(private ClassReflection $declaringClass, private Type $type)
16+
public function __construct(private string $name, private ClassReflection $declaringClass, private Type $type)
1717
{
1818
}
1919

20+
public function getName(): string
21+
{
22+
return $this->name;
23+
}
24+
2025
public function getDeclaringClass(): ClassReflection
2126
{
2227
return $this->declaringClass;

src/Reflection/Php/PhpPropertyReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public function __construct(
4848
{
4949
}
5050

51+
public function getName(): string
52+
{
53+
return $this->reflection->getName();
54+
}
55+
5156
public function getDeclaringClass(): ClassReflection
5257
{
5358
return $this->declaringClass;

src/Reflection/Php/SimpleXMLElementProperty.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ final class SimpleXMLElementProperty implements ExtendedPropertyReflection
1919
{
2020

2121
public function __construct(
22+
private string $name,
2223
private ClassReflection $declaringClass,
2324
private Type $type,
2425
)
2526
{
2627
}
2728

29+
public function getName(): string
30+
{
31+
return $this->name;
32+
}
33+
2834
public function getDeclaringClass(): ClassReflection
2935
{
3036
return $this->declaringClass;

src/Reflection/Php/UniversalObjectCrateProperty.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ final class UniversalObjectCrateProperty implements ExtendedPropertyReflection
1414
{
1515

1616
public function __construct(
17+
private string $name,
1718
private ClassReflection $declaringClass,
1819
private Type $readableType,
1920
private Type $writableType,
2021
)
2122
{
2223
}
2324

25+
public function getName(): string
26+
{
27+
return $this->name;
28+
}
29+
2430
public function getDeclaringClass(): ClassReflection
2531
{
2632
return $this->declaringClass;

src/Reflection/Php/UniversalObjectCratesClassReflectionExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function getProperty(ClassReflection $classReflection, string $propertyNa
8585
$writableType = new MixedType();
8686
}
8787

88-
return new UniversalObjectCrateProperty($classReflection, $readableType, $writableType);
88+
return new UniversalObjectCrateProperty($propertyName, $classReflection, $readableType, $writableType);
8989
}
9090

9191
}

src/Reflection/ResolvedPropertyReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public function __construct(
2525
{
2626
}
2727

28+
public function getName(): string
29+
{
30+
return $this->reflection->getName();
31+
}
32+
2833
public function getOriginalReflection(): ExtendedPropertyReflection
2934
{
3035
return $this->reflection;

src/Reflection/Type/IntersectionTypePropertyReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public function __construct(private array $properties)
2323
{
2424
}
2525

26+
public function getName(): string
27+
{
28+
return $this->properties[0]->getName();
29+
}
30+
2631
public function getDeclaringClass(): ClassReflection
2732
{
2833
return $this->properties[0]->getDeclaringClass();

src/Reflection/Type/UnionTypePropertyReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public function __construct(private array $properties)
2323
{
2424
}
2525

26+
public function getName(): string
27+
{
28+
return $this->properties[0]->getName();
29+
}
30+
2631
public function getDeclaringClass(): ClassReflection
2732
{
2833
return $this->properties[0]->getDeclaringClass();

src/Reflection/WrappedExtendedPropertyReflection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010
final class WrappedExtendedPropertyReflection implements ExtendedPropertyReflection
1111
{
1212

13-
public function __construct(private PropertyReflection $property)
13+
public function __construct(private string $name, private PropertyReflection $property)
1414
{
1515
}
1616

17+
public function getName(): string
18+
{
19+
return $this->name;
20+
}
21+
1722
public function getDeclaringClass(): ClassReflection
1823
{
1924
return $this->property->getDeclaringClass();

src/Type/Enum/EnumCaseObjectType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function getUnresolvedPropertyPrototype(string $propertyName, ClassMember
135135
}
136136
if ($propertyName === 'name') {
137137
return new EnumUnresolvedPropertyPrototypeReflection(
138-
new EnumPropertyReflection($classReflection, new ConstantStringType($this->enumCaseName)),
138+
new EnumPropertyReflection($propertyName, $classReflection, new ConstantStringType($this->enumCaseName)),
139139
);
140140
}
141141

@@ -148,7 +148,7 @@ public function getUnresolvedPropertyPrototype(string $propertyName, ClassMember
148148
}
149149

150150
return new EnumUnresolvedPropertyPrototypeReflection(
151-
new EnumPropertyReflection($classReflection, $valueType),
151+
new EnumPropertyReflection($propertyName, $classReflection, $valueType),
152152
);
153153
}
154154
}

src/Type/MixedType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public function getProperty(string $propertyName, ClassMemberAccessAnswerer $sco
396396

397397
public function getUnresolvedPropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection
398398
{
399-
$property = new DummyPropertyReflection();
399+
$property = new DummyPropertyReflection($propertyName);
400400
return new CallbackUnresolvedPropertyPrototypeReflection(
401401
$property,
402402
$property->getDeclaringClass(),

src/Type/ObjectShapePropertyReflection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313
final class ObjectShapePropertyReflection implements ExtendedPropertyReflection
1414
{
1515

16-
public function __construct(private Type $type)
16+
public function __construct(private string $name, private Type $type)
1717
{
1818
}
1919

20+
public function getName(): string
21+
{
22+
return $this->name;
23+
}
24+
2025
public function getDeclaringClass(): ClassReflection
2126
{
2227
$reflectionProvider = ReflectionProviderStaticAccessor::getInstance();

src/Type/ObjectShapeType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function getUnresolvedPropertyPrototype(string $propertyName, ClassMember
113113
throw new ShouldNotHappenException();
114114
}
115115

116-
$property = new ObjectShapePropertyReflection($this->properties[$propertyName]);
116+
$property = new ObjectShapePropertyReflection($propertyName, $this->properties[$propertyName]);
117117
return new CallbackUnresolvedPropertyPrototypeReflection(
118118
$property,
119119
$property->getDeclaringClass(),

src/Type/Php/SimpleXMLElementClassPropertyReflectionExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
2020

2121
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
2222
{
23-
return new SimpleXMLElementProperty($classReflection, new BenevolentUnionType([new ObjectType($classReflection->getName()), new NullType()]));
23+
return new SimpleXMLElementProperty($propertyName, $classReflection, new BenevolentUnionType([new ObjectType($classReflection->getName()), new NullType()]));
2424
}
2525

2626
}

src/Type/Traits/MaybeObjectTypeTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getProperty(string $propertyName, ClassMemberAccessAnswerer $sco
5252

5353
public function getUnresolvedPropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection
5454
{
55-
$property = new DummyPropertyReflection();
55+
$property = new DummyPropertyReflection($propertyName);
5656
return new CallbackUnresolvedPropertyPrototypeReflection(
5757
$property,
5858
$property->getDeclaringClass(),

src/Type/Traits/ObjectTypeTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function getProperty(string $propertyName, ClassMemberAccessAnswerer $sco
6363

6464
public function getUnresolvedPropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection
6565
{
66-
$property = new DummyPropertyReflection();
66+
$property = new DummyPropertyReflection($propertyName);
6767
return new CallbackUnresolvedPropertyPrototypeReflection(
6868
$property,
6969
$property->getDeclaringClass(),

0 commit comments

Comments
 (0)