Bug #19695 [Fbk->Bgs]: PSR-1 Namespace sniff - false positive for PHP5.2 style namespacing

From: Date: Thu, 08 Nov 2012 23:18:44 +0000
Subject: Bug #19695 [Fbk->Bgs]: PSR-1 Namespace sniff - false positive for PHP5.2 style namespacing
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-9311@lists.php.net to get a copy of this message
Edit report at https://pear.php.net/bugs/bug.php?id=19695&edit=1 ID: 19695 Updated by: gsherwood@squiz.net Reported By: rjt at zygous dot co dot uk Summary: PSR-1 Namespace sniff - false positive for PHP5.2 style namespacing -Status: Feedback +Status: Bogus Type: Bug Package: PHP_CodeSniffer Operating System: Linux Package Version: SVN PHP Version: 5_4 SVN-2012-11-07 Assigned To: squiz Roadmap Versions: New Comment: -Status: Feedback +Status: Bogus Yeah, it would be good if the PSR standards said something about documenting the min PHP version. PEAR has a requirement for this inside the file comment on each PHP file, but documentation is not covered at all by the PSRs. Hopefully this will change one day, but maybe PHP5.2 support will be dropped before then anyway. THe PSRs seems to move a little slowly. Wish I had a Not a Bug status, but I only have Bogus. Please don't be offended. Previous Comments: ------------------------------------------------------------------------ [2012-11-08 12:19:41] zygous Yep, that all makes sense. It's a shame there's no PHPDoc tag to specify a minimum required PHP version that PHPCS could check. Having to maintain a custom set of sniffs would be a bit of a nuisance. I guess this report can be resolved as not-a-bug then. ------------------------------------------------------------------------ [2012-11-07 21:44:50] squiz -Status: Open +Status: Feedback -Assigned To: +Assigned To: squiz The reason you are seeing that error is because you are running PHPCS using a version of PHP that supports namespaces. PSR-1 states that if code is written for 5.3 and after then is MUST use namespaces. But there is nothing that will actually tell me what version of PHP your code is supposed to support. The only thing I can check is the PHP version. So my problem when doing this sniff was that I have to throw an error (the use of MUST means error, not warning) if you are using old-style namespacing for code meant to run under PHP 5.3+. If I see old-style namespacing and I don't throw an error, I could be hiding a really important error message and that would probably be a bigger mistake. If you know that you'll always be running PHP_CodeSniffer using PHP 5.3+, you can write your own standard that mutes this particular error message. Or you can run PHP_CodeSniffer using the lowest PHP version that your code supports (seems like PHP 5.2 in this case). If you want to create your own standard, create a file somewhere called (for example) mystandard.xml and make the contents: <?xml version="1.0"?> <ruleset name="MyStandard"> <description>My custom coding standard.</description> <rule ref="PSR2"/> <rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace"> <severity>0</severity> </rule> </ruleset> Then you can run PHP_CodeSniffer like this: phpcs --standard=/path/to/mystandard.xml /path/to/code ------------------------------------------------------------------------ [2012-11-07 08:56:47] zygous Description: ------------ Given a class written for PHP 5.2, with a name that incorporates a namespace, PHPCS complains that "each class must be in a namespace of at least one level". E.g. class Vendor_Mvc_Controller_Index is, according to PSR-0, equivalent to \Vendor\Mvc\Controller\Index in PHP5.3+ code, so PHPCS shouldn't complain about namespacing. ------------------------------------------------------------------------ -- Edit this bug report at https://pear.php.net/bugs/bug.php?id=19695&edit=1

« previous php.pear.bugs (#9311) next »