FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=18670&edit=1

ID: 18670
Comment by: gennadiy@gmail.com
Reported By: johnston dot joshua at gmail dot com
Summary: UpperCaseConstantNameSniff fails on dynamic retrieval
of class constant
Status: Open
Type: Bug
Package: PHP_CodeSniffer
Operating System: Lunux
Package Version: 1.3.0
PHP Version: 5.3.6
Roadmap Versions:
New Comment:

I have the same issue.


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

[2011-07-15 22:30:53] treegi

Description:
------------
The constant sniff assumes that arguments to constant() should be all
uppercase when it is valid to have constant('self::SOME_CONST'); if you
are doing dynamic constant retrieval

Test script:
---------------
<?php
// bug.php
class ConstTest {
const TESTER = '1';
public function __construct() {
echo constant('self::TESTER');
}
}
?>


Expected result:
----------------
$ phpcs --standard=PEAR bug.php

--------------------------------------------------------------------------------
FOUND 6 ERROR(S) AFFECTING 3 LINE(S)
--------------------------------------------------------------------------------
2 | ERROR | Missing file doc comment
2 | ERROR | Missing class doc comment
2 | ERROR | Opening brace of a class must be on the line after the
definition
4 | ERROR | Missing function doc comment
4 | ERROR | Opening brace should be on a new line
5 | ERROR | Constants must be uppercase; expected 'SELF::TESTER' but
found
'self::TESTER'
--------------------------------------------------------------------------------

Time: 0 seconds, Memory: 5.25Mb

Actual result:
--------------
$ phpcs --standard=PEAR bug.php
--------------------------------------------------------------------------------
FOUND 5 ERROR(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
2 | ERROR | Missing file doc comment
2 | ERROR | Missing class doc comment
2 | ERROR | Opening brace of a class must be on the line after the
definition
4 | ERROR | Missing function doc comment
4 | ERROR | Opening brace should be on a new line
--------------------------------------------------------------------------------

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

Search Discussions

  • Gennadiy at Jul 18, 2011 at 1:11 pm
    Edit report at http://pear.php.net/bugs/bug.php?id=18670&edit=1

    ID: 18670
    Comment by: gennadiy@gmail.com
    Reported By: johnston dot joshua at gmail dot com
    Summary: UpperCaseConstantNameSniff fails on dynamic retrieval
    of class constant
    Status: Open
    Type: Bug
    Package: PHP_CodeSniffer
    Operating System: Lunux
    Package Version: 1.3.0
    PHP Version: 5.3.6
    Roadmap Versions:
    New Comment:

    The Patch fixes the problem.

    It should be applied to
    PHP/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php


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

    [2011-07-18 15:09:30] gennadiylitvinyuk

    Added #patch
    bug:18670;patch:ConstantsNamingConvention.patch;revision:1310998170;.

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

    [2011-07-18 15:07:55] gennadiylitvinyuk

    I have the same issue.

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

    [2011-07-15 22:30:53] treegi

    Description:
    ------------
    The constant sniff assumes that arguments to constant() should be all
    uppercase when it is valid to have constant('self::SOME_CONST'); if you
    are doing dynamic constant retrieval

    Test script:
    ---------------
    <?php
    // bug.php
    class ConstTest {
    const TESTER = '1';
    public function __construct() {
    echo constant('self::TESTER');
    }
    }
    ?>


    Expected result:
    ----------------
    $ phpcs --standard=PEAR bug.php

    --------------------------------------------------------------------------------
    FOUND 6 ERROR(S) AFFECTING 3 LINE(S)
    --------------------------------------------------------------------------------
    2 | ERROR | Missing file doc comment
    2 | ERROR | Missing class doc comment
    2 | ERROR | Opening brace of a class must be on the line after the
    definition
    4 | ERROR | Missing function doc comment
    4 | ERROR | Opening brace should be on a new line
    5 | ERROR | Constants must be uppercase; expected 'SELF::TESTER' but
    found
    'self::TESTER'
    --------------------------------------------------------------------------------

    Time: 0 seconds, Memory: 5.25Mb

    Actual result:
    --------------
    $ phpcs --standard=PEAR bug.php
    --------------------------------------------------------------------------------
    FOUND 5 ERROR(S) AFFECTING 2 LINE(S)
    --------------------------------------------------------------------------------
    2 | ERROR | Missing file doc comment
    2 | ERROR | Missing class doc comment
    2 | ERROR | Opening brace of a class must be on the line after the
    definition
    4 | ERROR | Missing function doc comment
    4 | ERROR | Opening brace should be on a new line
    --------------------------------------------------------------------------------

    ------------------------------------------------------------------------
  • Johnston Joshua at Jul 18, 2011 at 1:23 pm
    Edit report at http://pear.php.net/bugs/bug.php?id=18670&edit=1

    ID: 18670
    Updated by: johnston.joshua@gmail.com
    Reported By: johnston dot joshua at gmail dot com
    Summary: UpperCaseConstantNameSniff fails on dynamic retrieval
    of class constant
    Status: Open
    Type: Bug
    Package: PHP_CodeSniffer
    Operating System: Lunux
    Package Version: 1.3.0
    PHP Version: 5.3.6
    Roadmap Versions:
    New Comment:

    @Gennadiy

    The patch works but it doesn't enforce the sniff correctly.
    constant('self::lowercase') would pass and it shouldn't. For
    UpperCaseConstantNameSniff a string constant should match the pattern:
    /^(\w+::)?[A-Z0-9_]+\z/


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

    [2011-07-18 15:11:43] gennadiylitvinyuk

    The Patch fixes the problem.

    It should be applied to
    PHP/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php

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

    [2011-07-18 15:09:30] gennadiylitvinyuk

    Added #patch
    bug:18670;patch:ConstantsNamingConvention.patch;revision:1310998170;.

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

    [2011-07-18 15:07:55] gennadiylitvinyuk

    I have the same issue.

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

    [2011-07-15 22:30:53] treegi

    Description:
    ------------
    The constant sniff assumes that arguments to constant() should be all
    uppercase when it is valid to have constant('self::SOME_CONST'); if you
    are doing dynamic constant retrieval

    Test script:
    ---------------
    <?php
    // bug.php
    class ConstTest {
    const TESTER = '1';
    public function __construct() {
    echo constant('self::TESTER');
    }
    }
    ?>


    Expected result:
    ----------------
    $ phpcs --standard=PEAR bug.php

    --------------------------------------------------------------------------------
    FOUND 6 ERROR(S) AFFECTING 3 LINE(S)
    --------------------------------------------------------------------------------
    2 | ERROR | Missing file doc comment
    2 | ERROR | Missing class doc comment
    2 | ERROR | Opening brace of a class must be on the line after the
    definition
    4 | ERROR | Missing function doc comment
    4 | ERROR | Opening brace should be on a new line
    5 | ERROR | Constants must be uppercase; expected 'SELF::TESTER' but
    found
    'self::TESTER'
    --------------------------------------------------------------------------------

    Time: 0 seconds, Memory: 5.25Mb

    Actual result:
    --------------
    $ phpcs --standard=PEAR bug.php
    --------------------------------------------------------------------------------
    FOUND 5 ERROR(S) AFFECTING 2 LINE(S)
    --------------------------------------------------------------------------------
    2 | ERROR | Missing file doc comment
    2 | ERROR | Missing class doc comment
    2 | ERROR | Opening brace of a class must be on the line after the
    definition
    4 | ERROR | Missing function doc comment
    4 | ERROR | Opening brace should be on a new line
    --------------------------------------------------------------------------------

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedJul 18, '11 at 1:08p
activeJul 18, '11 at 1:23p
posts3
users2
websitepear.php.net

2 users in discussion

Gennadiy: 2 posts Johnston Joshua: 1 post

People

Translate

site design / logo © 2022 Grokbase