Skip to content

Missing documentation for Node #14616

@JakeQZ

Description

@JakeQZ

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions