Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.
This repository was archived by the owner on Dec 1, 2024. It is now read-only.

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

Description

@lexidor
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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions