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

Visibility must be declared on property when attribute added to the Property #3211

Closed
JerryMSunny opened this issue Feb 8, 2021 · 2 comments

Comments

@JerryMSunny
Copy link

JerryMSunny commented Feb 8, 2021

When attribute is used on Class property the sniffer gives false positive error : Visibility must be declared on property

Code sample

#[Attribute(Attribute::TARGET_PROPERTY)]
class Key
{
}

class Student
{
    #[Key]
    private string $rollNumber;

    public function someFunction
    {
        ...
    }
}

To reproduce
Steps to reproduce the behavior:

  1. Create a file called Student.php with the code sample above...
  2. Run phpcs Student.php
  3. See error message displayed
Visibility must be declared on property $rollNumber;

Versions (please complete the following information):

  • OS: Ubuntu 18.04
  • PHP: 8.0
  • PHPCS: 4.0.x-dev
  • Standard: PSR12
@jrfnl
Copy link
Contributor

jrfnl commented Feb 8, 2021

@JerryMSunny PHP 8.0 attributes are not yet supported in PHPCS - see #3182. There is an open PR to fix this - #3203.

I have just tested your code sample against the open PR and that PR would fix the above issue as reported.

However, it also highlights that potentially some sniffs may need adjusting for attributes once the above mentioned PR has been merged. For example, the PSR1.Files.SideEffects sniff would start throwing an error after #3203 would be merged, while it shouldn't.

@gsherwood
Copy link
Member

Can confirm that merging the attribute PR has fixed this issue, so closing it. If you have additional use cases that are not fixed, please report them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants