Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1 | Generic/LowerCaseKeyword: simplify registered tokens + add enum support #3574

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 16 additions & 77 deletions src/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util;
use PHP_CodeSniffer\Util\Common;
use PHP_CodeSniffer\Util\Tokens;

class LowerCaseKeywordSniff implements Sniff
{
Expand All @@ -24,83 +25,21 @@ class LowerCaseKeywordSniff implements Sniff
*/
public function register()
{
return [
T_ABSTRACT,
T_ARRAY,
T_AS,
T_BREAK,
T_CALLABLE,
T_CASE,
T_CATCH,
T_CLASS,
T_CLONE,
T_CLOSURE,
T_CONST,
T_CONTINUE,
T_DECLARE,
T_DEFAULT,
T_DO,
T_ECHO,
T_ELSE,
T_ELSEIF,
T_EMPTY,
T_ENDDECLARE,
T_ENDFOR,
T_ENDFOREACH,
T_ENDIF,
T_ENDSWITCH,
T_ENDWHILE,
T_ENUM,
T_EVAL,
T_EXIT,
T_EXTENDS,
T_FINAL,
T_FINALLY,
T_FN,
T_FOR,
T_FOREACH,
T_FUNCTION,
T_GLOBAL,
T_GOTO,
T_IF,
T_IMPLEMENTS,
T_INCLUDE,
T_INCLUDE_ONCE,
T_INSTANCEOF,
T_INSTEADOF,
T_INTERFACE,
T_ISSET,
T_LIST,
T_LOGICAL_AND,
T_LOGICAL_OR,
T_LOGICAL_XOR,
T_MATCH,
T_MATCH_DEFAULT,
T_NAMESPACE,
T_NEW,
T_PARENT,
T_PRINT,
T_PRIVATE,
T_PROTECTED,
T_PUBLIC,
T_READONLY,
T_REQUIRE,
T_REQUIRE_ONCE,
T_RETURN,
T_SELF,
T_STATIC,
T_SWITCH,
T_THROW,
T_TRAIT,
T_TRY,
T_UNSET,
T_USE,
T_VAR,
T_WHILE,
T_YIELD,
T_YIELD_FROM,
$targets = Tokens::$contextSensitiveKeywords;
$targets += [
T_CLOSURE => T_CLOSURE,
T_EMPTY => T_EMPTY,
T_ENUM_CASE => T_ENUM_CASE,
T_EVAL => T_EVAL,
T_ISSET => T_ISSET,
T_MATCH_DEFAULT => T_MATCH_DEFAULT,
T_PARENT => T_PARENT,
T_SELF => T_SELF,
T_UNSET => T_UNSET,
];

return $targets;

}//end register()


Expand All @@ -124,7 +63,7 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'mixed');
}

$messageKeyword = Util\Common::prepareForOutput($keyword);
$messageKeyword = Common::prepareForOutput($keyword);

$error = 'PHP keywords must be lowercase; expected "%s" but found "%s"';
$data = [
Expand Down
4 changes: 3 additions & 1 deletion src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class Reading {
Public READOnly int $var;
}

EnuM Enum {
EnuM ENUM: string
{
Case HEARTS;
}

__HALT_COMPILER(); // An exception due to phar support.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class Reading {
public readonly int $var;
}

enum Enum {
enum ENUM: string
{
case HEARTS;
}

__HALT_COMPILER(); // An exception due to phar support.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getErrorList()
35 => 1,
39 => 2,
42 => 1,
44 => 1,
];

}//end getErrorList()
Expand Down