VKCOM / noverify

Pretty fast linter (code static analysis utility) for PHP
MIT License
673 stars 57 forks source link

False alarm undefinedConstant Class constant ::XX does not exist #1171

Open EdmondDantes opened 2 years ago

EdmondDantes commented 2 years ago

PHP Version: 8.1

OS: Windows 11

Run command:

noverify.exe check --ignore-vendor --allow-disable="./*" --exclude-checks="discardExpr" --index-only-files="./tests/KC,./vendor,./api3.php" --output="reports.txt" ./KC

The minimal code in which the bug appears:


class Students                      extends LMSEntityAbstract
{

    const TIME_ZONE                 = 'time_zone';

    protected function _propertyTimeZone(): VirtualProperty
    {
        // @todo propertyTimeZone
        return new VirtualProperty(static::TIME_ZONE);
    }

    protected function propertyFullName(): VirtualProperty
    {
        // CONCAT_WS(' ', first_name, last_name)
        return new VirtualPropertyAsExpression(self::FULL_NAME, new ConcatenateWithSeparator(
            ' ',
            new FieldRef(self::FIRST_NAME),
            new FieldRef(self::LAST_NAME)
        ));
    }

Actual Behavior:

ERROR undefinedConstant: Class constant ::TIME_ZONE does not exist at Entities/Students.php:180 return new VirtualProperty(static::TIME_ZONE); ^^^^^^^^^ ERROR undefinedConstant: Class constant ::FULL_NAME does not exist at Entities/Students.php:187 return new VirtualPropertyAsExpression(self::FULL_NAME, new ConcatenateWithSeparator( ^^^^^^^^^ ERROR undefinedConstant: Class constant ::FIRST_NAME does not exist at Entities/Students.php:189 new FieldRef(self::FIRST_NAME), ^^^^^^^^^^ ERROR undefinedConstant: Class constant ::LAST_NAME does not exist at Entities/Students.php:190 new FieldRef(self::LAST_NAME) ^^^^^^^^^ **Expected Behavior:** No alert [Students.zip](https://github.com/VKCOM/noverify/files/8101778/Students.zip) s