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

Tokenizer detects wrong token for php ::class feature with spaces #2138

Closed
umherirrender opened this issue Aug 22, 2018 · 1 comment
Closed
Milestone

Comments

@umherirrender
Copy link

The following code:

class Foo {
}

if ( class_exists( Test :: class ) ) {
	Test :: callStuff();
}
if ( class_exists( Test2 ::class ) ) {
	Test2 :: callStuff();
}

the "class" in line 6 is token T_CLASS, while the "class" in line 9 is T_STRING. php lint is okay with a space there
This results in false positive on line 6 with the code ":: class" for some sniffs. The use of "::class" is okay in line 9.

  6 | ERROR | [ ] Only one object structure is allowed in a file
    |       |     (Generic.Files.OneObjectStructurePerFile.MultipleFound)
  6 | ERROR | [ ] Class name ")" is not in PascalCase format
    |       |     (Squiz.Classes.ValidClassName.NotCamelCaps)

It seems you have just to use $lastNotEmptyToken instead of -1 in PHP.php (search for classname::class)

@gsherwood gsherwood added this to the 3.3.2 milestone Aug 24, 2018
gsherwood added a commit that referenced this issue Aug 24, 2018
@gsherwood
Copy link
Member

Thanks for reporting this, and you were 100% right on the fix.

wmfgerrit pushed a commit to wikimedia/mediawiki-tools-codesniffer that referenced this issue Aug 24, 2018
Test for using no space before and after -> or ::
The sniff is an autofix sniff

On testing I found problems with ":: class" in phpcs,
see squizlabs/PHP_CodeSniffer#2138
but that used very low.

Change-Id: I3b1c3b78fbe7650e06aaa0f6df00c937f575ca5d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants