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

PrivateInFinalClassRule fails with traits containing an abstract protected method implemented in a final class #838

Open
kayw-geek opened this issue Sep 23, 2024 · 0 comments
Assignees
Labels

Comments

@kayw-geek
Copy link

Description

The PrivateInFinalClassRule in PHPStan is currently failing under the following scenario:

When a trait declares an abstract protected method and a final class uses this trait and implements the abstract method, PHPStan issues an error due to the implemented method being protected instead of private. However, I believe that the implemented abstract method should retain the same access modifier, which is protected.

Steps to Reproduce

  1. Create a trait with an abstract protected method:

    trait ExampleTrait {
        abstract protected function exampleMethod();
    }
  2. Create a final class that uses the trait and implements the abstract method with a protected access modifier:

    final class ExampleClass {
        use ExampleTrait;
    
        protected function exampleMethod() {
            // implementation
        }
    }
  3. Run PHPStan analysis on the above code

Expected Behavior

PHPStan should not issue an error when a final class implements an abstract protected method from a trait.

@localheinz localheinz self-assigned this Dec 1, 2024
@localheinz localheinz added the bug label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants