Skip to content

Commit

Permalink
check require-extends after other extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jan 6, 2024
1 parent 0a1c34c commit 0b4bf73
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
42 changes: 18 additions & 24 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,6 @@ public function hasProperty(string $propertyName): bool
return $this->hasNativeProperty($propertyName);
}

if ($this->requireExtendsPropertiesClassReflectionExtension->hasProperty($this, $propertyName)) {
return true;
}

foreach ($this->propertiesClassReflectionExtensions as $i => $extension) {
if ($i > 0 && !$this->allowsDynamicPropertiesExtensions()) {
break;
Expand All @@ -443,21 +439,25 @@ public function hasProperty(string $propertyName): bool
}
}

if ($this->requireExtendsPropertiesClassReflectionExtension->hasProperty($this, $propertyName)) {
return true;
}

return false;
}

public function hasMethod(string $methodName): bool
{
if ($this->requireExtendsMethodsClassReflectionExtension->hasMethod($this, $methodName)) {
return true;
}

foreach ($this->methodsClassReflectionExtensions as $extension) {
if ($extension->hasMethod($this, $methodName)) {
return true;
}
}

if ($this->requireExtendsMethodsClassReflectionExtension->hasMethod($this, $methodName)) {
return true;
}

return false;
}

Expand All @@ -468,14 +468,6 @@ public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope):
$key = sprintf('%s-%s', $key, $scope->getClassReflection()->getCacheKey());
}

if ($this->requireExtendsMethodsClassReflectionExtension->hasMethod($this, $methodName)) {
$method = $this->wrapExtendedMethod($this->requireExtendsMethodsClassReflectionExtension->getMethod($this, $methodName));
if ($scope->canCallMethod($method)) {
return $this->methods[$key] = $method;
}
$this->methods[$key] = $method;
}

if (!isset($this->methods[$key])) {
foreach ($this->methodsClassReflectionExtensions as $extension) {
if (!$extension->hasMethod($this, $methodName)) {
Expand All @@ -488,6 +480,11 @@ public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope):
}
$this->methods[$key] = $method;
}

if ($this->requireExtendsMethodsClassReflectionExtension->hasMethod($this, $methodName)) {
$method = $this->requireExtendsMethodsClassReflectionExtension->getMethod($this, $methodName);
$this->methods[$key] = $method;
}
}

if (!isset($this->methods[$key])) {
Expand Down Expand Up @@ -599,14 +596,6 @@ public function getProperty(string $propertyName, ClassMemberAccessAnswerer $sco
$key = sprintf('%s-%s', $key, $scope->getClassReflection()->getCacheKey());
}
if (!isset($this->properties[$key])) {
if ($this->requireExtendsPropertiesClassReflectionExtension->hasProperty($this, $propertyName)) {
$property = $this->requireExtendsPropertiesClassReflectionExtension->getProperty($this, $propertyName);
if ($scope->canAccessProperty($property)) {
return $this->properties[$key] = $property;
}
$this->properties[$key] = $property;
}

foreach ($this->propertiesClassReflectionExtensions as $i => $extension) {
if (
$i > 0 && !$this->allowsDynamicPropertiesExtensions()
Expand All @@ -624,6 +613,11 @@ public function getProperty(string $propertyName, ClassMemberAccessAnswerer $sco
}
$this->properties[$key] = $property;
}

if ($this->requireExtendsPropertiesClassReflectionExtension->hasProperty($this, $propertyName)) {
$property = $this->requireExtendsPropertiesClassReflectionExtension->getProperty($this, $propertyName);
$this->properties[$key] = $property;
}
}

if (!isset($this->properties[$key])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use PHPStan\Analyser\OutOfClassScope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ExtendedMethodReflection;
use PHPStan\Reflection\MethodsClassReflectionExtension;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\VerbosityLevel;
Expand All @@ -20,7 +20,7 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
return $this->findMethod($classReflection, $methodName) !== null;
}

public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
public function getMethod(ClassReflection $classReflection, string $methodName): ExtendedMethodReflection
{
$method = $this->findMethod($classReflection, $methodName);
if ($method === null) {
Expand All @@ -30,7 +30,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
return $method;
}

private function findMethod(ClassReflection $classReflection, string $methodName): ?MethodReflection
private function findMethod(ClassReflection $classReflection, string $methodName): ?ExtendedMethodReflection
{
if (!$classReflection->isInterface()) {
return null;
Expand Down

0 comments on commit 0b4bf73

Please sign in to comment.