Skip to content

Commit df04da9

Browse files
committed
Generic LowerCaseConstantSniff and UpperCaseConstantSniff no longer report errors on classes named True, False or Null
1 parent b121fb4 commit df04da9

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

CodeSniffer/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
7575
return;
7676
}
7777

78+
// Is this a class name?
79+
if ($tokens[$prevPtr]['code'] === T_CLASS
80+
|| $tokens[$prevPtr]['code'] === T_EXTENDS
81+
|| $tokens[$prevPtr]['code'] === T_IMPLEMENTS
82+
) {
83+
return;
84+
}
85+
7886
// Class or namespace?
7987
if ($tokens[($stackPtr - 1)]['code'] === T_NS_SEPARATOR) {
8088
return;

CodeSniffer/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6666
return;
6767
}
6868

69+
// Is this a class name?
70+
if ($tokens[$prevPtr]['code'] === T_CLASS
71+
|| $tokens[$prevPtr]['code'] === T_EXTENDS
72+
|| $tokens[$prevPtr]['code'] === T_IMPLEMENTS
73+
) {
74+
return;
75+
}
76+
6977
// Class or namespace?
7078
if ($tokens[($stackPtr - 1)]['code'] === T_NS_SEPARATOR) {
7179
return;

CodeSniffer/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ $x->NULL = 7;
5252

5353
use Zend\Log\Writer\NULL as NullWriter;
5454
new \Zend\Log\Writer\NULL()
55+
56+
class True extends Null implements False {}
5557
?>

CodeSniffer/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ $x->null = 7;
5353
use Zend\Log\Writer\Null as NullWriter;
5454
new \Zend\Log\Writer\Null()
5555

56+
class True extends Null implements False {}
57+
5658
?>

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
4141
- AbstractPatternSniff now sets the ignoreComments option using a public var rather than through the constructor
4242
-- This allows the setting to be overwritten in ruleset.xml files
4343
-- Old method remains for backwards compatibility
44+
- Generic LowerCaseConstantSniff and UpperCaseConstantSniff no longer report errors on classes named True, False or Null
4445
- PEAR ValidFunctionNameSniff no longer enforces exact case matching for PHP magic methods
4546
- Squiz SwitchDeclarationSniff now allows RETURN statements to close a CASE or DEFAULT statement
4647
- Squiz BlockCommentSniff now correctly reports an error for blank lines before blocks at the start of a control structure

0 commit comments

Comments
 (0)