Skip to content

Commit 27bfdcc

Browse files
committed
Refactor stuff I disagree with
1 parent 5297d77 commit 27bfdcc

File tree

2 files changed

+33
-54
lines changed

2 files changed

+33
-54
lines changed

src/Reflection/ClassReflection.php

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,11 @@ public function hasProperty(string $propertyName): bool
484484
}
485485

486486
// For BC purpose
487-
if ($this->getPhpExtension()->hasStaticProperty($this, $propertyName)) {
488-
return $this->hasPropertyCache[$propertyName] = true;
487+
if ($this->getPhpExtension()->hasProperty($this, $propertyName)) {
488+
$property = $this->getPhpExtension()->getProperty($this, $propertyName);
489+
if ($property->isStatic()) {
490+
return $this->hasPropertyCache[$propertyName] = true;
491+
}
489492
}
490493

491494
if ($this->requireExtendsPropertiesClassReflectionExtension->hasProperty($this, $propertyName)) {
@@ -527,8 +530,11 @@ public function hasStaticProperty(string $propertyName): bool
527530
return $this->hasStaticPropertyCache[$propertyName];
528531
}
529532

530-
if ($this->getPhpExtension()->hasStaticProperty($this, $propertyName)) {
531-
return $this->hasStaticPropertyCache[$propertyName] = true;
533+
if ($this->getPhpExtension()->hasProperty($this, $propertyName)) {
534+
$property = $this->getPhpExtension()->getProperty($this, $propertyName);
535+
if ($property->isStatic()) {
536+
return $this->hasStaticPropertyCache[$propertyName] = true;
537+
}
532538
}
533539

534540
if ($this->requireExtendsPropertiesClassReflectionExtension->hasStaticProperty($this, $propertyName)) {
@@ -737,12 +743,14 @@ public function getProperty(string $propertyName, ClassMemberAccessAnswerer $sco
737743
}
738744

739745
// For BC purpose
740-
if ($this->getPhpExtension()->hasStaticProperty($this, $propertyName)) {
741-
$property = $this->wrapExtendedProperty($propertyName, $this->getPhpExtension()->getStaticProperty($this, $propertyName));
742-
if ($scope->canReadProperty($property)) {
743-
return $this->properties[$key] = $property;
746+
if ($this->getPhpExtension()->hasProperty($this, $propertyName)) {
747+
$property = $this->wrapExtendedProperty($propertyName, $this->getPhpExtension()->getProperty($this, $propertyName));
748+
if ($property->isStatic()) {
749+
if ($scope->canReadProperty($property)) {
750+
return $this->properties[$key] = $property;
751+
}
752+
$this->properties[$key] = $property;
744753
}
745-
$this->properties[$key] = $property;
746754
}
747755

748756
if (!isset($this->properties[$key])) {
@@ -780,7 +788,12 @@ public function getInstanceProperty(string $propertyName, ClassMemberAccessAnswe
780788
continue;
781789
}
782790

783-
$property = $this->wrapExtendedProperty($propertyName, $extension->getProperty($this, $propertyName));
791+
$nakedProperty = $extension->getProperty($this, $propertyName);
792+
if ($nakedProperty->isStatic()) {
793+
continue;
794+
}
795+
796+
$property = $this->wrapExtendedProperty($propertyName, $nakedProperty);
784797
if ($scope->canReadProperty($property)) {
785798
return $this->instanceProperties[$key] = $property;
786799
}
@@ -809,9 +822,14 @@ public function getStaticProperty(string $propertyName): ExtendedPropertyReflect
809822
return $this->staticProperties[$key];
810823
}
811824

812-
if ($this->getPhpExtension()->hasStaticProperty($this, $propertyName)) {
813-
$property = $this->wrapExtendedProperty($propertyName, $this->getPhpExtension()->getStaticProperty($this, $propertyName));
814-
return $this->staticProperties[$key] = $property;
825+
if ($this->getPhpExtension()->hasProperty($this, $propertyName)) {
826+
$nakedProperty = $this->getPhpExtension()->getProperty($this, $propertyName);
827+
if ($nakedProperty->isStatic()) {
828+
$property = $this->wrapExtendedProperty($propertyName, $nakedProperty);
829+
if ($property->isStatic()) {
830+
return $this->staticProperties[$key] = $property;
831+
}
832+
}
815833
}
816834

817835
if ($this->requireExtendsPropertiesClassReflectionExtension->hasStaticProperty($this, $propertyName)) {
@@ -824,7 +842,7 @@ public function getStaticProperty(string $propertyName): ExtendedPropertyReflect
824842

825843
public function hasNativeProperty(string $propertyName): bool
826844
{
827-
return $this->getPhpExtension()->hasNativeProperty($this, $propertyName);
845+
return $this->getPhpExtension()->hasProperty($this, $propertyName);
828846
}
829847

830848
public function getNativeProperty(string $propertyName): PhpPropertyReflection

src/Reflection/Php/PhpClassReflectionExtension.php

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ final class PhpClassReflectionExtension
7171
/** @var PhpPropertyReflection[][] */
7272
private array $propertiesIncludingAnnotations = [];
7373

74-
/** @var ExtendedPropertyReflection[][] */
75-
private array $staticPropertiesIncludingAnnotations = [];
76-
7774
/** @var PhpPropertyReflection[][] */
7875
private array $nativeProperties = [];
7976

@@ -121,17 +118,6 @@ public function evictPrivateSymbols(string $classCacheKey): void
121118
unset($this->propertiesIncludingAnnotations[$key][$name]);
122119
}
123120
}
124-
foreach ($this->staticPropertiesIncludingAnnotations as $key => $properties) {
125-
if ($key !== $classCacheKey) {
126-
continue;
127-
}
128-
foreach ($properties as $name => $property) {
129-
if (!$property->isPrivate()) {
130-
continue;
131-
}
132-
unset($this->staticPropertiesIncludingAnnotations[$key][$name]);
133-
}
134-
}
135121
foreach ($this->nativeProperties as $key => $properties) {
136122
if ($key !== $classCacheKey) {
137123
continue;
@@ -169,10 +155,7 @@ public function evictPrivateSymbols(string $classCacheKey): void
169155

170156
public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
171157
{
172-
$nativeReflection = $classReflection->getNativeReflection();
173-
174-
return $nativeReflection->hasProperty($propertyName)
175-
&& !$nativeReflection->getProperty($propertyName)->isStatic();
158+
return $classReflection->getNativeReflection()->hasProperty($propertyName);
176159
}
177160

178161
public function getProperty(ClassReflection $classReflection, string $propertyName): PhpPropertyReflection
@@ -184,28 +167,6 @@ public function getProperty(ClassReflection $classReflection, string $propertyNa
184167
return $this->propertiesIncludingAnnotations[$classReflection->getCacheKey()][$propertyName];
185168
}
186169

187-
public function hasStaticProperty(ClassReflection $classReflection, string $propertyName): bool
188-
{
189-
$nativeReflection = $classReflection->getNativeReflection();
190-
191-
return $nativeReflection->hasProperty($propertyName)
192-
&& $nativeReflection->getProperty($propertyName)->isStatic();
193-
}
194-
195-
public function getStaticProperty(ClassReflection $classReflection, string $propertyName): ExtendedPropertyReflection
196-
{
197-
if (!isset($this->staticPropertiesIncludingAnnotations[$classReflection->getCacheKey()][$propertyName])) {
198-
$this->staticPropertiesIncludingAnnotations[$classReflection->getCacheKey()][$propertyName] = $this->createProperty($classReflection, $propertyName, false);
199-
}
200-
201-
return $this->staticPropertiesIncludingAnnotations[$classReflection->getCacheKey()][$propertyName];
202-
}
203-
204-
public function hasNativeProperty(ClassReflection $classReflection, string $propertyName): bool
205-
{
206-
return $classReflection->getNativeReflection()->hasProperty($propertyName);
207-
}
208-
209170
public function getNativeProperty(ClassReflection $classReflection, string $propertyName): PhpPropertyReflection
210171
{
211172
if (!isset($this->nativeProperties[$classReflection->getCacheKey()][$propertyName])) {

0 commit comments

Comments
 (0)