Skip to content

Commit

Permalink
NewMagicClassConstant: bug fix - work around a tokenizer issue
Browse files Browse the repository at this point in the history
As noted inline:
> In PHPCS < 3.4.1, the class keyword after a double colon + comment may be tokenized as
> `T_CLASS` instead of as `T_STRING`, so registering both.

Adjusted an existing unit test to safeguard this change.

Upstream issue about the tokenizer problem:
* squizlabs/PHP_CodeSniffer#2431
  • Loading branch information
jrfnl committed Aug 9, 2020
1 parent da5fa17 commit 8d7efd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion PHPCompatibility/Sniffs/Constants/NewMagicClassConstantSniff.php
Expand Up @@ -46,7 +46,16 @@ class NewMagicClassConstantSniff extends Sniff
*/
public function register()
{
return array(\T_STRING);
/*
* In PHPCS < 3.4.1, the class keyword after a double colon + comment may be tokenized as
* `T_CLASS` instead of as `T_STRING`, so registering both.
*
* @link https://github.com/squizlabs/php_codesniffer/issues/2431
*/
return array(
\T_STRING,
\T_CLASS,
);
}

/**
Expand Down
Expand Up @@ -9,7 +9,7 @@ namespace foo {
namespace MyNameSpace {
class xyz {}

remove_filter('theme_filter', [\MyNameSpace\xyz::class, 'methodName'], 30);
remove_filter('theme_filter', [\MyNameSpace\xyz:: /* comment */ class, 'methodName'], 30);
}

/*
Expand Down

0 comments on commit 8d7efd1

Please sign in to comment.