Skip to content
Closed
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
24 changes: 21 additions & 3 deletions src/Rules/Comparison/ImpossibleCheckTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,19 +418,37 @@
);
}

private static array $contextCache = [];

Check failure on line 421 in src/Rules/Comparison/ImpossibleCheckTypeHelper.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Property PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper::$contextCache type has no value type specified in iterable type array.

Check failure on line 421 in src/Rules/Comparison/ImpossibleCheckTypeHelper.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.5)

Property PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper::$contextCache type has no value type specified in iterable type array.

Check failure on line 421 in src/Rules/Comparison/ImpossibleCheckTypeHelper.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Property PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper::$contextCache type has no value type specified in iterable type array.

Check failure on line 421 in src/Rules/Comparison/ImpossibleCheckTypeHelper.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Property PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper::$contextCache type has no value type specified in iterable type array.

Check failure on line 421 in src/Rules/Comparison/ImpossibleCheckTypeHelper.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Property PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper::$contextCache type has no value type specified in iterable type array.

Check failure on line 421 in src/Rules/Comparison/ImpossibleCheckTypeHelper.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, ubuntu-latest)

Property PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper::$contextCache type has no value type specified in iterable type array.

Check failure on line 421 in src/Rules/Comparison/ImpossibleCheckTypeHelper.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Property PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper::$contextCache type has no value type specified in iterable type array.

Check failure on line 421 in src/Rules/Comparison/ImpossibleCheckTypeHelper.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, windows-latest)

Property PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper::$contextCache type has no value type specified in iterable type array.

Check failure on line 421 in src/Rules/Comparison/ImpossibleCheckTypeHelper.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Property PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper::$contextCache type has no value type specified in iterable type array.

Check failure on line 421 in src/Rules/Comparison/ImpossibleCheckTypeHelper.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Property PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper::$contextCache type has no value type specified in iterable type array.

Check failure on line 421 in src/Rules/Comparison/ImpossibleCheckTypeHelper.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, windows-latest)

Property PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper::$contextCache type has no value type specified in iterable type array.

private function determineContext(Scope $scope, Expr $node): TypeSpecifierContext
{
if ($node instanceof Expr\CallLike && $node->isFirstClassCallable()) {
return TypeSpecifierContext::createTruthy();
}

if ($node instanceof FuncCall && $node->name instanceof Node\Name) {
$cached = self::$contextCache['function'][$node->name->toString()] ?? null;
if ($cached !== null) {
return $cached;
}

if ($this->reflectionProvider->hasFunction($node->name, $scope)) {
$functionReflection = $this->reflectionProvider->getFunction($node->name, $scope);
$parametersAcceptor = ParametersAcceptorSelector::selectFromArgs($scope, $node->getArgs(), $functionReflection->getVariants(), $functionReflection->getNamedArgumentsVariants());
$returnType = TypeUtils::resolveLateResolvableTypes($parametersAcceptor->getReturnType());

return $returnType->isVoid()->yes() ? TypeSpecifierContext::createNull() : TypeSpecifierContext::createTruthy();
$functionVariants = $functionReflection->getVariants();
$namedArgumentsVariants = $functionReflection->getNamedArgumentsVariants();
$parametersAcceptor = ParametersAcceptorSelector::selectFromArgs($scope, $node->getArgs(), $functionVariants, $namedArgumentsVariants);
$returnType = TypeUtils::resolveLateResolvableTypes($parametersAcceptor->getReturnType());
$context = $returnType->isVoid()->yes() ? TypeSpecifierContext::createNull() : TypeSpecifierContext::createTruthy();

if (
count($functionVariants) === 1
&& !$functionVariants[0]->getReturnType()->hasTemplateOrLateResolvableType()
&& $namedArgumentsVariants === null
) {
return self::$contextCache['function'][$node->name->toString()] = $context;
}
return $context;
}
} elseif ($node instanceof MethodCall && $node->name instanceof Node\Identifier) {
$methodCalledOnType = $scope->getType($node->var);
Expand Down
Loading