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

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

-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: squiz
This bug has been fixed in SVN.

If this was a documentation problem, the fix will appear on pear.php.net
by the end of next Sunday (CET).

If this was a problem with the pear.php.net website, the change should
be live shortly.

Otherwise, the fix will appear in the package's next release.

Thank you for the report and for helping us make PEAR better.




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

[2011-07-18 15:23:48] treegi

@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/

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

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

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

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedAug 5, '11 at 3:18a
activeAug 5, '11 at 3:18a
posts1
users1
websitepear.php.net

1 user in discussion

Gsherwood: 1 post

People

Translate

site design / logo © 2022 Grokbase