Skip to content

Commit

Permalink
Catch more BetterReflection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 27, 2020
1 parent cefbb1d commit 3e8ec5f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/Analyser/FileAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use PHPStan\Rules\Registry;
use PHPStan\Rules\TipRuleError;
use Roave\BetterReflection\NodeCompiler\Exception\UnableToCompileNode;
use Roave\BetterReflection\Reflection\Exception\NotAClassReflection;
use Roave\BetterReflection\Reflection\Exception\NotAnInterfaceReflection;
use Roave\BetterReflection\Reflector\Exception\IdentifierNotFound;
use function array_fill_keys;
use function array_key_exists;
Expand Down Expand Up @@ -90,8 +92,8 @@ public function analyseFile(
} catch (IdentifierNotFound $e) {
$fileErrors[] = new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getLine(), $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols');
continue;
} catch (UnableToCompileNode $e) {
$fileErrors[] = new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, $node->getLine(), $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols');
} catch (UnableToCompileNode | NotAClassReflection | NotAnInterfaceReflection $e) {
$fileErrors[] = new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, $node->getLine(), $e);
continue;
}

Expand Down Expand Up @@ -178,7 +180,7 @@ public function analyseFile(
// pass
} catch (IdentifierNotFound $e) {
// pass
} catch (UnableToCompileNode $e) {
} catch (UnableToCompileNode | NotAClassReflection | NotAnInterfaceReflection $e) {
// pass
}
};
Expand Down Expand Up @@ -239,8 +241,8 @@ public function analyseFile(
$fileErrors[] = new Error($e->getMessage(), $file, null, $e, null, null, $e->getTip());
} catch (IdentifierNotFound $e) {
$fileErrors[] = new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, null, $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols');
} catch (UnableToCompileNode $e) {
$fileErrors[] = new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, null, $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols');
} catch (UnableToCompileNode | NotAClassReflection | NotAnInterfaceReflection $e) {
$fileErrors[] = new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, null, $e);
}
} elseif (is_dir($file)) {
$fileErrors[] = new Error(sprintf('File %s is a directory.', $file), $file, null, false);
Expand Down
6 changes: 4 additions & 2 deletions src/Reflection/BetterReflection/BetterReflectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use Roave\BetterReflection\NodeCompiler\Exception\UnableToCompileNode;
use Roave\BetterReflection\Reflection\Adapter\ReflectionClass;
use Roave\BetterReflection\Reflection\Adapter\ReflectionFunction;
use Roave\BetterReflection\Reflection\Exception\NotAClassReflection;
use Roave\BetterReflection\Reflection\Exception\NotAnInterfaceReflection;
use Roave\BetterReflection\Reflector\ClassReflector;
use Roave\BetterReflection\Reflector\ConstantReflector;
use Roave\BetterReflection\Reflector\Exception\IdentifierNotFound;
Expand Down Expand Up @@ -335,7 +337,7 @@ public function getConstant(\PhpParser\Node\Name $nameNode, ?Scope $scope): Glob
$constantValue = $constantReflection->getValue();
$constantValueType = ConstantTypeHelper::getTypeFromValue($constantValue);
$fileName = $constantReflection->getFileName();
} catch (UnableToCompileNode $e) {
} catch (UnableToCompileNode | NotAClassReflection | NotAnInterfaceReflection $e) {
$constantValueType = new MixedType();
$fileName = null;
}
Expand All @@ -355,7 +357,7 @@ public function resolveConstantName(\PhpParser\Node\Name $nameNode, ?Scope $scop
return true;
} catch (\Roave\BetterReflection\Reflector\Exception\IdentifierNotFound $e) {
// pass
} catch (UnableToCompileNode $e) {
} catch (UnableToCompileNode | NotAClassReflection | NotAnInterfaceReflection $e) {
// pass
}
return false;
Expand Down

0 comments on commit 3e8ec5f

Please sign in to comment.