Bug report
I'm trying to write an extension to ignore alwaysTrue in assert()s.
I have
final class IgnoreBooleanAlways implements IgnoreErrorExtension
{
public function shouldIgnore(Error $error, Node $node, Scope $scope): bool
{
$shouldIgnore = false;
switch ($error->getIdentifier()) {
case 'function.alreadyNarrowedType':
case 'instanceof.alwaysTrue':
$functionName = $scope->getFunctionName();
error_log(var_export($functionName, true));
error_log(get_class($node));
$shouldIgnore = true;
break;
}
return $shouldIgnore;
}
}
The function name from $scope is the class method name, not the assert() function. So that's no use.
And Node does not seem to be documented properly. The classes logged are PhpParser\Node\Expr\FuncCall and PhpParser\Node\Expr\Instanceof_, neither of which appear in the documentation.
How can I programmatically determine if an alwaysTrue warning arises from within an assert() in order to discard it? Or is that not possible?
Code snippet that reproduces the problem
No response
Expected output
n/a
Did PHPStan help you today? Did it make you happy in any way?
No. The documentation was hard to find, and appears to be missing substantial parts. Better documentation on creating extensions is needed.
Bug report
I'm trying to write an extension to ignore
alwaysTrueinassert()s.I have
The function name from
$scopeis the class method name, not theassert()function. So that's no use.And
Nodedoes not seem to be documented properly. The classes logged arePhpParser\Node\Expr\FuncCallandPhpParser\Node\Expr\Instanceof_, neither of which appear in the documentation.How can I programmatically determine if an
alwaysTruewarning arises from within anassert()in order to discard it? Or is that not possible?Code snippet that reproduces the problem
No response
Expected output
n/a
Did PHPStan help you today? Did it make you happy in any way?
No. The documentation was hard to find, and appears to be missing substantial parts. Better documentation on creating extensions is needed.