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

Linter to make properties and methods only accessible through $this #549

Open
lexidor opened this issue Oct 5, 2023 · 0 comments
Open

Comments

@lexidor
Copy link
Contributor

lexidor commented Oct 5, 2023

final class Example {
  public function __construct(
    private int $private,
    <<ThisOnly>> private int $thisOnly,
  ) {}

  private function priv(): void {}
  <<ThisOnly>>
  private function thisMethod(): void {}
)

Within the body of this class, $this->thisOnly and $this->thisMethod() would be valid. expression->thisOnly and expression->thisMethod() would be an error.

There is no need to check the type of expression. There is a small chance that thisOnly is a public property on some unrelated class, but this would be a known false positive.

The ThisOnly attribute name is a placeholder. Feel free to suggest a better one. Important, this Linter should work on any attribute matching the name. It would be a shame if hhast became a dependency of a project because it needs the attribute. Hhast is a dev dependency.

facebook/hhvm#7574

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

1 participant