webimpress / coding-standard

Webimpress Coding Standard for PHP_CodeSniffer
BSD 2-Clause "Simplified" License
13 stars 7 forks source link

PHP.ImportInternalConstant wrongly detects class constants as "PHP internal" #120

Closed rieschl closed 4 years ago

rieschl commented 4 years ago

When using a class constant which has the same name as a PHP constant, the check WebimpressCodingStandard.PHP.ImportInternalConstant throws an error, even if it shouldn't. For example:

<?php

declare(strict_types=1);

namespace Foo;

class Test {
    private const TRUE = 'true';
}

results in this error:

vendor/bin/phpcs --sniffs="WebimpressCodingStandard.PHP.ImportInternalConstant" Test.php

FILE: /mnt/e/PhpStormProjects/Test.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 8 | ERROR | [x] PHP internal constant "TRUE" must be imported
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

That happens with more such constants. In one of our projects I get 4 errors, with class constants TRUE, FALSE, SORT_ASC and SORT_DESC. It doesn't matter if the constant is public or private.