FAQ
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: Open
+Status: Feedback
Type: Bug
Package: PHP_CodeSniffer
Operating System: Linux
Package Version: SVN
PHP Version: 5_4 SVN-2012-11-07
-Assigned To:
+Assigned To: squiz
Roadmap Versions:
New Comment:

-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


Previous Comments:
------------------------------------------------------------------------

[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.

------------------------------------------------------------------------

Search Discussions

  • Rjt at Nov 8, 2012 at 12:19 pm
    Edit report at https://pear.php.net/bugs/bug.php?id=19695&edit=1

    ID: 19695
    Updated by: rjt@zygous.co.uk
    Reported By: rjt at zygous dot co dot uk
    Summary: PSR-1 Namespace sniff - false positive for PHP5.2
    style namespacing
    Status: Feedback
    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:

    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.


    Previous Comments:
    ------------------------------------------------------------------------

    [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.

    ------------------------------------------------------------------------
  • Gsherwood at Nov 8, 2012 at 11:18 pm
    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.

    ------------------------------------------------------------------------
  • Rjt at Nov 9, 2012 at 8:31 am
    Edit report at https://pear.php.net/bugs/bug.php?id=19695&edit=1

    ID: 19695
    Updated by: rjt@zygous.co.uk
    Reported By: rjt at zygous dot co dot uk
    Summary: PSR-1 Namespace sniff - false positive for PHP5.2
    style namespacing
    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:

    Would it be worth honouring the PEAR comment if that's present? From
    what I've read of the PSRs I don't think that would be in contravention,
    would it? Any means necessary to identify the target PHP version...

    We have a lot of code written before PHP 5.3 that we're now running on
    5.3 servers. It all works, so there's no reason to change namespacing,
    and I believe it's PSR compliant in all other regards. It wasn't written
    for 5.3, so needn't use 'real' namespaces.

    I know the mailing list is fed-up of discussing. PSRs 1 and 2, but
    perhaps iI should raise this on the list...

    I'm not offended by the bogus status :-) Oh, and good job on the
    sniffs!


    Previous Comments:
    ------------------------------------------------------------------------

    [2012-11-08 23:18:43] squiz

    -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.

    ------------------------------------------------------------------------

    [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.

    ------------------------------------------------------------------------
  • Gsherwood at Nov 11, 2012 at 10:21 pm
    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: 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:

    Yes, the mailing list for the PHP FIG seems like it doesn't like
    receiving mail, which is
    a little odd given they have released a common PHP coding standard to
    the
    community. A great thing, but you're obviously going to get feedback.

    Still, I'd ask there because it isn't the sort of call I could make as
    I'm not a voting
    member. If the authors of the standard decide to relax things and just
    say that both
    methods of namespacing are fine, then it's just a little bit of code to
    remove.


    Previous Comments:
    ------------------------------------------------------------------------

    [2012-11-09 08:31:06] zygous

    Would it be worth honouring the PEAR comment if that's present? From
    what I've read of the PSRs I don't think that would be in contravention,
    would it? Any means necessary to identify the target PHP version...

    We have a lot of code written before PHP 5.3 that we're now running on
    5.3 servers. It all works, so there's no reason to change namespacing,
    and I believe it's PSR compliant in all other regards. It wasn't written
    for 5.3, so needn't use 'real' namespaces.

    I know the mailing list is fed-up of discussing. PSRs 1 and 2, but
    perhaps iI should raise this on the list...

    I'm not offended by the bogus status :-) Oh, and good job on the
    sniffs!

    ------------------------------------------------------------------------

    [2012-11-08 23:18:43] squiz

    -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.

    ------------------------------------------------------------------------

    [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.

    ------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedNov 7, '12 at 9:44p
activeNov 11, '12 at 10:21p
posts5
users2
websitepear.php.net

2 users in discussion

Gsherwood: 3 posts Rjt: 2 posts

People

Translate

site design / logo © 2022 Grokbase