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

Squiz.WhiteSpace.ScopeKeywordSpacing false positive for static return type #3188

Closed
mathieutu opened this issue Dec 24, 2020 · 4 comments · Fixed by #3189
Closed

Squiz.WhiteSpace.ScopeKeywordSpacing false positive for static return type #3188

mathieutu opened this issue Dec 24, 2020 · 4 comments · Fixed by #3189
Milestone

Comments

@mathieutu
Copy link

Describe the bug
Php8 allows static as a valid return type. I've seen the PHPCS PR which allows that.
However I still have an issue with the Squiz.WhiteSpace.ScopeKeywordSpacing.Incorrect rule.

Code sample

public static function fCreate($attributes = []): static
{
    return static::factory()->create($attributes);
}

Error

 35 | ERROR | [x] Scope keyword "static" must be followed by a single space; found 0 (Squiz.WhiteSpace.ScopeKeywordSpacing.Incorrect)
 43 | ERROR | [x] Scope keyword "static" must be followed by a single space; found newline
    |       |     (Squiz.WhiteSpace.ScopeKeywordSpacing.Incorrect)

Expected behavior
Phpcs should not emit an error for a space after static.
And actually static as a return type should be considerated by phpcs as a Scope Keyword.

Versions:

  • OS: MacOS 10.15.7
  • PHP: 8
  • PHPCS: 3.5.8
  • Standard: [PSR2, PSR12]
@jrfnl
Copy link
Contributor

jrfnl commented Dec 24, 2020

Thanks for reporting this. I can not reproduce the first error. The second one (line 43) I can reproduce with your code sample.

PR #3189 should fix this. Testing appreciated.

@mathieutu
Copy link
Author

mathieutu commented Dec 24, 2020

Thanks for this so fast response!

Indeed, the error line 35 was actually caused by

    public static function myMethod(): static|\Closure

Do you think your fix will cover it too?

EDIT: saw the code you've made for union, so it'll work!

@mathieutu
Copy link
Author

mathieutu commented Dec 24, 2020

@jrfnl I can confirm it's ok, both problems solved!

Thanks for being so efficient!

@jrfnl
Copy link
Contributor

jrfnl commented Dec 24, 2020

Thanks for testing @mathieutu! Glad to see the confirmation that this will now be fixed once the PR is merged.

@gsherwood gsherwood added this to the 3.6.0 milestone Jan 14, 2021
@gsherwood gsherwood changed the title PHP8 static return type seen as ScopeKeyword Squiz.WhiteSpace.ScopeKeywordSpacing false positive for static return type Jan 14, 2021
gsherwood added a commit that referenced this issue Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants