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

Nullable static return typehint causes whitespace error #3277

Closed
jnoordsij opened this issue Mar 20, 2021 · 2 comments
Closed

Nullable static return typehint causes whitespace error #3277

jnoordsij opened this issue Mar 20, 2021 · 2 comments
Milestone

Comments

@jnoordsij
Copy link

Describe the bug
Since PHP8, static is allowed as return type. In #3189 a fix was added to prevent this from yielding whitespace errors. However, a nullable static return type still produces an error.

Code sample

<?php

namespace App\Example;

class Example
{
    # works fine now
    public function testA(): static
    {
        return new static();
    }

    # Scope keyword "static" must be followed by a single space; found newline
    public function testB(): ?static
    {
        return new static();
    }
}

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
    <rule ref="PSR12"/>
</ruleset>

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php
  3. See error message displayed
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------

 14 | ERROR | [x] Scope keyword "static" must be followed by a single space;
    |       |     found newline
--------------------------------------------------------------------------------

Expected behavior
No error

Versions (please complete the following information):

  • OS: Windows 10 & Alpine 3.13
  • PHP: 8.0
  • PHPCS: master
  • Standard: PSR12
@gsherwood
Copy link
Member

Thanks for picking this up. I've committed a fix and it will be in 3.6.0.

@jnoordsij
Copy link
Author

Thanks for the quick fix! Looking forward to the release.

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