PSR2 with class declarations extending classes with namespaces in PHP Code Sniffer

I ran into a problem with PHPCS using the PSR2 standard. Searched high and low, but to my surprise, I can not find anyone reporting the same problem.

Say I have a class declaration as follows:

<?php

class MyChildClass extends \SomeNameSpace\MyParentClass
{
}

Then I run it through PHPCS with:

bash-3.2$ phpcs -s  --standard=PSR2 test.php 

FILE: test.php
--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
 3 | ERROR | Expected 0 spaces between "SomeNameSpace" and comma; $1 found
   |       | (PSR2.Classes.ClassDeclaration.SpaceBeforeComma)
 3 | ERROR | Expected 1 space before "MyParentClass"; 13 found
   |       | (PSR2.Classes.ClassDeclaration.SpaceBeforeName)
--------------------------------------------------------------------------------

Time: 0 seconds, Memory: 4.00Mb

also:

Bash-3.2$ phpcs --version
PHP_CodeSniffer version 1.3.6 (stable) by Squiz Pty Ltd. (http://www.squiz.net)

Has anyone come across this? Am I doing something wrong? Otherwise, I will go first to the sniffer code, which does not feel good.

+5
source share
1 answer

The PSR-1 and PSR-2 standards within the current version of PHP_CodeSniffer are not complete. I never mentioned them in the release notes, so people obviously either just found them or they are talking about the current version of dev, where they are full.

PSR-2 PHP_CodeSniffer, git :

git clone git://github.com/squizlabs/PHP_CodeSniffer.git
cd PHP_CodeSniffer
PHP s/phpcs --standard=PSR2 /path/to/code

, , .

dev , , :

2:PHP_CodeSniffer gsherwood$ PHP s/phpcs --standard=psr2 temp.php

FILE: /Users/gsherwood/Sites/Projects/PHP_CodeSniffer/temp.php
--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
 3 | ERROR | Each class must be in a namespace of at least one level (a
   |       | top-level vendor name)
 5 | ERROR | Expected 1 blank line at end of file; 0 found
--------------------------------------------------------------------------------

Time: 0 seconds, Memory: 4.25Mb

, .

+8

All Articles