Skip to content

Commit

Permalink
remove recursion guards
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jan 6, 2024
1 parent 4965434 commit 0f88b00
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\MethodsClassReflectionExtension;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\VerbosityLevel;

class RequireExtendsMethodsClassReflectionExtension implements MethodsClassReflectionExtension
{

/** @var array<string, array<string, true>> */
private array $inProcess = [];

public function hasMethod(ClassReflection $classReflection, string $methodName): bool
{
return $this->findMethod($classReflection, $methodName) !== null;
Expand Down Expand Up @@ -47,23 +43,11 @@ private function findMethod(ClassReflection $classReflection, string $methodName
foreach ($extendsTags as $extendsTag) {
$type = $extendsTag->getType();

$typeDescription = $type->describe(VerbosityLevel::typeOnly());
if (isset($this->inProcess[$typeDescription][$methodName])) {
continue;
}

$this->inProcess[$typeDescription][$methodName] = true;

if (!$type->hasMethod($methodName)->yes()) {
unset($this->inProcess[$typeDescription][$methodName]);
continue;
}

$method = $type->getMethod($methodName, new OutOfClassScope());

unset($this->inProcess[$typeDescription][$methodName]);

return $method;
return $type->getMethod($methodName, new OutOfClassScope());
}

$interfaces = $classReflection->getInterfaces();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\VerbosityLevel;

class RequireExtendsPropertiesClassReflectionExtension implements PropertiesClassReflectionExtension
{

/** @var array<string, array<string, true>> */
private array $inProcess = [];

public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
{
return $this->findProperty($classReflection, $propertyName) !== null;
Expand All @@ -40,22 +36,11 @@ private function findProperty(ClassReflection $classReflection, string $property
foreach ($requireExtendsTags as $requireExtendsTag) {
$type = $requireExtendsTag->getType();

$typeDescription = $type->describe(VerbosityLevel::typeOnly());
if (isset($this->inProcess[$typeDescription][$propertyName])) {
continue;
}

$this->inProcess[$typeDescription][$propertyName] = true;

if (!$type->hasProperty($propertyName)->yes()) {
unset($this->inProcess[$typeDescription][$propertyName]);
continue;
}

$property = $type->getProperty($propertyName, new OutOfClassScope());
unset($this->inProcess[$typeDescription][$propertyName]);

return $property;
return $type->getProperty($propertyName, new OutOfClassScope());
}

$interfaces = $classReflection->getInterfaces();
Expand Down

0 comments on commit 0f88b00

Please sign in to comment.