Skip to content

Commit

Permalink
Use exception
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed May 20, 2023
1 parent 044a868 commit 281076f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use PHPStan\Reflection\Php\PhpClassReflectionExtension;
use PHPStan\Reflection\Php\PhpPropertyReflection;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\CircularClassReflectionResolutionException;
use PHPStan\Type\CircularTypeAliasDefinitionException;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\ErrorType;
Expand Down Expand Up @@ -193,7 +194,11 @@ public function getParentClass(): ?ClassReflection
return $this->cachedParentClass = null;
}

$extendsTag = $this->getFirstExtendsTag();
try {
$extendsTag = $this->getFirstExtendsTag();
} catch (CircularClassReflectionResolutionException) {
return $this->reflectionProvider->getClass($parentClass->getName());
}

if ($extendsTag !== null && $this->isValidAncestorType($extendsTag->getType(), [$parentClass->getName()])) {
$extendedType = $extendsTag->getType();
Expand Down Expand Up @@ -1349,16 +1354,17 @@ private function getFirstExtendsTag(): ?ExtendsTag
/** @return array<string, ExtendsTag> */
public function getExtendsTags(): array

Check failure on line 1355 in src/Reflection/ClassReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Method PHPStan\Reflection\ClassReflection::getExtendsTags() throws checked exception PHPStan\Type\CircularClassReflectionResolutionException but it's missing from the PHPDoc @throws tag.
{
if (isset(self::$resolvingExtendsTag[$this->getName()])) {
return [];
}
self::$resolvingExtendsTag[$this->getName()] = true;

$resolvedPhpDoc = $this->getResolvedPhpDoc();
if ($resolvedPhpDoc === null) {
return [];
}

// prevent circular reference
if (isset(self::$resolvingExtendsTag[$this->getName()])) {
throw new CircularClassReflectionResolutionException();

Check failure on line 1364 in src/Reflection/ClassReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Method PHPStan\Reflection\ClassReflection::getExtendsTags() throws checked exception PHPStan\Type\CircularClassReflectionResolutionException but it's missing from the PHPDoc @throws tag.

Check failure on line 1364 in src/Reflection/ClassReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Method PHPStan\Reflection\ClassReflection::getExtendsTags() throws checked exception PHPStan\Type\CircularClassReflectionResolutionException but it's missing from the PHPDoc @throws tag.

Check failure on line 1364 in src/Reflection/ClassReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Method PHPStan\Reflection\ClassReflection::getExtendsTags() throws checked exception PHPStan\Type\CircularClassReflectionResolutionException but it's missing from the PHPDoc @throws tag.

Check failure on line 1364 in src/Reflection/ClassReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Method PHPStan\Reflection\ClassReflection::getExtendsTags() throws checked exception PHPStan\Type\CircularClassReflectionResolutionException but it's missing from the PHPDoc @throws tag.

Check failure on line 1364 in src/Reflection/ClassReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Method PHPStan\Reflection\ClassReflection::getExtendsTags() throws checked exception PHPStan\Type\CircularClassReflectionResolutionException but it's missing from the PHPDoc @throws tag.

Check failure on line 1364 in src/Reflection/ClassReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Method PHPStan\Reflection\ClassReflection::getExtendsTags() throws checked exception PHPStan\Type\CircularClassReflectionResolutionException but it's missing from the PHPDoc @throws tag.

Check failure on line 1364 in src/Reflection/ClassReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Method PHPStan\Reflection\ClassReflection::getExtendsTags() throws checked exception PHPStan\Type\CircularClassReflectionResolutionException but it's missing from the PHPDoc @throws tag.

Check failure on line 1364 in src/Reflection/ClassReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Method PHPStan\Reflection\ClassReflection::getExtendsTags() throws checked exception PHPStan\Type\CircularClassReflectionResolutionException but it's missing from the PHPDoc @throws tag.
}
self::$resolvingExtendsTag[$this->getName()] = true;

$extendTags = $resolvedPhpDoc->getExtendsTags();

unset(self::$resolvingExtendsTag[$this->getName()]);
Expand Down
10 changes: 10 additions & 0 deletions src/Type/CircularClassReflectionResolutionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types = 1);

namespace PHPStan\Type;

use Exception;

class CircularClassReflectionResolutionException extends Exception
{

}

0 comments on commit 281076f

Please sign in to comment.