Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions src/Internal/Ast/ContractVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use TypePHP\Internal\Ast\Elimination\StaticTypeEvaluator;
use TypePHP\Internal\Diagnostic\DebugLog;
use TypePHP\Internal\Docblock\DocblockExtractor;
use TypePHP\Internal\Docblock\DocblockNormalizer;
use TypePHP\Internal\Docblock\DocblockParser;
Expand Down Expand Up @@ -540,7 +541,8 @@ private function collectUnprovenClassConstantChecks(Node\Stmt\Class_ $node, stri
$checkStmt->setAttribute('typephp_injected', true);
$injectedStmts[] = $checkStmt;
}
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}

Expand Down Expand Up @@ -603,7 +605,8 @@ private function collectUnprovenGlobalConstantChecks(Node\Stmt\Const_ $node): ar
$checkStmt->setAttribute('typephp_injected', true);
$injectedStmts[] = $checkStmt;
}
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}

return $injectedStmts;
Expand Down Expand Up @@ -901,7 +904,8 @@ private function processClassPropertyDefaults(Node\Stmt\Class_ $node): void
if ($classTemplates !== [] && DocblockParser::typeReferencesTemplate($propTypeNode, $classTemplates)) {
continue;
}
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}

Expand Down Expand Up @@ -984,7 +988,8 @@ private function resolveClassTemplatesForDefaults(Node\Stmt\Class_ $node): array
try {
$phpDocNode = DocblockExtractor::parseDocString($nodeDoc->getText());
$classTemplates = DocblockExtractor::extractTemplates($phpDocNode);
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}

Expand All @@ -994,7 +999,8 @@ private function resolveClassTemplatesForDefaults(Node\Stmt\Class_ $node): array
try {
$loadedTemplates = DocblockParser::parseClassTemplates($className);
$classTemplates = [...$classTemplates, ...$loadedTemplates];
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}
}
Expand All @@ -1006,7 +1012,8 @@ private function resolveClassTemplatesForDefaults(Node\Stmt\Class_ $node): array
try {
$parentTemplates = DocblockParser::parseClassTemplates($parentClass);
$classTemplates = [...$classTemplates, ...$parentTemplates];
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
} else {
$parentFile = self::findClassFileWithoutAutoload($parentClass);
Expand All @@ -1022,7 +1029,8 @@ private function resolveClassTemplatesForDefaults(Node\Stmt\Class_ $node): array
$classTemplates = [...$classTemplates, ...DocblockExtractor::extractTemplates($phpDocNode)];
}
}
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}
}
Expand Down Expand Up @@ -1104,7 +1112,8 @@ private function enterClassLike(Node\Stmt\Class_|Node\Stmt\Interface_|Node\Stmt\
try {
$phpDocNode = DocblockExtractor::parseDocString($doc->getText());
$templates = DocblockExtractor::extractTemplates($phpDocNode);
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}
$hasTemplates = $templates !== [];
Expand Down Expand Up @@ -1194,7 +1203,8 @@ private function enterClassLike(Node\Stmt\Class_|Node\Stmt\Interface_|Node\Stmt\
try {
$methodPhpDoc = DocblockExtractor::parseDocString($methodDoc->getText());
$methodParamTags = DocblockExtractor::getParamTags($methodPhpDoc);
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}

Expand Down Expand Up @@ -1261,7 +1271,8 @@ private function extractClassLikeAliases(
try {
$phpDocNode = DocblockExtractor::parseDocString($doc->getText());
$this->collectAliasesFromPhpDocInFile($phpDocNode, $aliases, $this->currentFile, $this->currentNamespace, $visited);
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}

Expand Down Expand Up @@ -1412,7 +1423,9 @@ class_exists($fqcn, false)
self::collectRawAliasesFromAstDoc($phpDocNode, $aliases, '', '', [], $localClassAliases, $visited);

return self::$astClassAliasesCache[$fqcn] = $aliases;
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore

return self::$astClassAliasesCache[$fqcn] = [];
}
}
Expand Down Expand Up @@ -1443,7 +1456,8 @@ class_exists($fqcn, false)
}

$aliases = self::extractTargetClassAliasesFromStmts($stmts, $fqcn, $filePath, $localClassAliases, $visited);
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
$aliases = [];
}

Expand Down Expand Up @@ -1545,7 +1559,8 @@ private static function scanClassLikesForAliases(
try {
$phpDocNode = DocblockExtractor::parseDocString($doc->getText());
self::collectRawAliasesFromAstDoc($phpDocNode, $aliases, $filePath, $namespace, $imports, $localClassAliases, $visited);
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}

Expand Down Expand Up @@ -1893,6 +1908,7 @@ private function propagateShapeTypesToDestructuring(Node\Expr\List_|Node\Expr\Ar
}
}
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}

Expand Down Expand Up @@ -1940,7 +1956,8 @@ private function handleAssign(Node\Expr\Assign $node): ?Node
[$typeParser, $lexer] = DocblockExtractor::getTypeParserComponents();
$tokens = new TokenIterator($lexer->tokenize(DocblockNormalizer::normalize($typeString)));
$parsedType = $typeParser->parse($tokens);
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}

if ($expr instanceof Node\Expr\New_ && $parsedType !== null) {
Expand Down Expand Up @@ -2758,7 +2775,8 @@ private function registerParamInferredTypes(array $params, ?string $docText = nu
foreach (DocblockExtractor::getParamTags($phpDocNode) as $pName => $pTag) {
$docParamTypes[$pName] = (string) $pTag->type;
}
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}

Expand Down Expand Up @@ -3286,7 +3304,8 @@ private function parseUnsetTypeCached(string $typeString): ?TypeNode
self::$parsedUnsetTypeCache[$typeString] = $parsed;

return $parsed;
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
self::$parsedUnsetTypeCache[$typeString] = false;

return null;
Expand Down
11 changes: 8 additions & 3 deletions src/Internal/Ast/FunctionContractInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use TypePHP\Internal\Ast\Elimination\Evaluator\GeneratorEvaluator;
use TypePHP\Internal\Ast\Elimination\StaticTypeEvaluator;
use TypePHP\Internal\Checker\ConditionalChecker;
use TypePHP\Internal\Diagnostic\DebugLog;
use TypePHP\Internal\Docblock\DocblockExtractor;
use TypePHP\Internal\Docblock\DocblockNormalizer;
use TypePHP\Internal\Docblock\DocblockParser;
Expand Down Expand Up @@ -119,7 +120,8 @@ public static function inject(
$paramTags = DocblockExtractor::getParamTags($phpDocNode);
$paramOutTags = DocblockExtractor::getParamOutTags($phpDocNode);
$selfOutType = DocblockExtractor::getSelfOutTag($phpDocNode);
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}

Expand Down Expand Up @@ -479,7 +481,8 @@ private static function collectTrustedParamTypes(
try {
$phpDocNode = DocblockExtractor::parseDocString($doc->getText());
$paramTags = DocblockExtractor::getParamTags($phpDocNode);
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}
}

Expand Down Expand Up @@ -1767,7 +1770,9 @@ public static function inlineVarSubsumesReturn(
$targetReturnType,
GenericTypeNode::VARIANCE_COVARIANT
);
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore

return false;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Internal/Ast/ScopeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace TypePHP\Internal\Ast;

use PhpParser\Node;
use TypePHP\Internal\Diagnostic\DebugLog;
use TypePHP\Internal\Docblock\DocblockExtractor;

/**
Expand Down Expand Up @@ -211,6 +212,7 @@ public function extractVarDocblock(string $docText, ?Node\Expr $expr = null): vo
}
}
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
// Silently ignore malformed docblocks
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Internal/Ast/TypeDeducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPStan\PhpDocParser\Ast\Type\ObjectShapeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use TypePHP\Internal\Diagnostic\DebugLog;
use TypePHP\Internal\Docblock\DocblockExtractor;
use TypePHP\Internal\Docblock\DocblockNormalizer;
use TypePHP\Internal\Docblock\DocblockParser;
Expand Down Expand Up @@ -313,7 +314,9 @@ private static function parseTypeString(string $typeString): ?TypeNode
$tokens = new TokenIterator($lexer->tokenize($normalized));

return self::$parsedTypeCache[$typeString] = $typeParser->parse($tokens);
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore

return null;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Internal/Checker/ConditionalChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use ReflectionClass;
use Throwable;
use Traversable;
use TypePHP\Internal\Diagnostic\DebugLog;
use TypePHP\Internal\Docblock\DocblockParser;
use TypePHP\Internal\Generics\TemplateManager;
use TypePHP\Internal\Resolver\HierarchyResolver;
Expand Down Expand Up @@ -479,6 +480,7 @@ private static function resolveRenamedParamValue(string $function, string $param
}
}
} catch (Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
// Silently ignore reflection errors
}

Expand Down
9 changes: 9 additions & 0 deletions src/Internal/Checker/InlineChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;
use TypePHP\Internal\Diagnostic\DebugLog;
use TypePHP\Internal\Diagnostic\ErrorFactory;
use TypePHP\Internal\Diagnostic\ErrorMessage;
use TypePHP\Internal\Docblock\DocblockNormalizer;
Expand Down Expand Up @@ -266,6 +267,7 @@ public static function checkVariable(
$value = self::wrapCollectionCallables($typeNode, $value, $context, $registry);
}
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
// Silently ignore unexpected execution exceptions
}

Expand Down Expand Up @@ -373,6 +375,7 @@ public static function validateCollectionElementMutation(
return $registry->validate($value, $typeNode->type, $context);
}
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
// Silently fall back to prospective whole-structure validation
}

Expand Down Expand Up @@ -572,6 +575,7 @@ public static function checkProperty(mixed $value, mixed $objectOrClass, string
TemplateManager::markFallbackReturnBindings($value, $typeNode, $fallbackMeta[1], $fallbackMeta[0], $preExistingBindings);
}
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
// Silently ignore unexpected execution exceptions
}

Expand Down Expand Up @@ -625,6 +629,7 @@ private static function classHasSelfOut(string $className): bool
}
}
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
// Silently ignore reflection errors
}

Expand Down Expand Up @@ -780,6 +785,7 @@ private static function resolveFunctionContextWithFallback(TypeNode $typeNode, s
$typeNode = SpecialTypeResolver::resolve($typeNode, $refFunc);
}
} catch (\ReflectionException $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
// Silently continue if reflection fails
}

Expand Down Expand Up @@ -859,6 +865,7 @@ private static function resolveClassContextWithFallback(
$typeNode = SpecialTypeResolver::resolve($typeNode, $refClass);
}
} catch (\ReflectionException $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
// Silently continue if reflection fails
}

Expand Down Expand Up @@ -916,6 +923,7 @@ private static function substitutePropertyGenericsWithFallback(TypeNode $typeNod
$refClass = new \ReflectionClass($className);
$typeNode = SpecialTypeResolver::resolve($subNode, $refClass);
} catch (\ReflectionException $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
$typeNode = $subNode;
}
} else {
Expand Down Expand Up @@ -973,6 +981,7 @@ private static function substituteStaticPropertyGenerics(TypeNode $typeNode, str
$refClass = new \ReflectionClass($className);
$typeNode = SpecialTypeResolver::resolve($typeNode, $refClass);
} catch (\ReflectionException $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
// Silently continue if reflection fails
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/Internal/Checker/MemberAssignChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use ReflectionNamedType;
use ReflectionProperty;
use TypePHP\Internal\Ast\Elimination\StaticTypeEvaluator;
use TypePHP\Internal\Diagnostic\DebugLog;
use TypePHP\Internal\Diagnostic\ErrorFactory;
use TypePHP\Internal\Diagnostic\ErrorMessage;
use TypePHP\Internal\Docblock\DocblockExtractor;
Expand Down Expand Up @@ -740,7 +741,8 @@ private static function validatePropertyElementMutationWithContract(
return $registry->validate($value, $contract['valueType'], $context);
}
}
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}

return null;
Expand Down Expand Up @@ -1193,7 +1195,8 @@ private static function resolveArrayAccessPlan(string $className): ?array
}
}
}
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}

return self::$arrayAccessPlanCache[$className] = null;
Expand Down Expand Up @@ -1281,7 +1284,8 @@ private static function readPropertyValue(mixed $objectOrClass, string $classNam
// @phpstan-ignore property.dynamicName
return $objectOrClass->$propName ?? [];
}
} catch (\Throwable) {
} catch (\Throwable $e) {
DebugLog::swallowed($e); // @codeCoverageIgnore
}

return [];
Expand Down
Loading
Loading