Skip to content

PSR2/PropertyDeclaration: update for properties with asymmetric visibility #1119

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

Draft
wants to merge 2 commits into
base: php-8.4/feature/file-methods-support-asym-visibility
Choose a base branch
from

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 6, 2025

Description

⚠️ This PR depends on PR #1116.

PSR2/PropertyDeclaration: update for properties with asymmetric visibility [1]

Per the FIG PSR-PER updates (next version), the "properties must have visibility declared" rule is also satisfied if only write visibility is declared.

The public keyword MAY be omitted when using a set-visibility on a public-read property.

Includes updated test expectations (on the tests previously added in #871).

PSR2/PropertyDeclaration: update for properties with asymmetric visibility [2]

Per the FIG PSR-PER updates (next version), the "set-visibility MUST be after the (read-)visibility".

This commit implements this, but as there may be two visibility modifiers, a minor refactor of the code involved in the wrong order checks for the final keyword and the static and readonly keywords is also needed as we can no longer presume that we can use the visibility keyword found with a search backwards to re-position other keywords.

Includes plenty of tests.
Includes a minor update to pre-existing test expectations (whitespace only), which is related to the refactor of the "fix"-code. As this sniff does not enforce any spacing requirements after the keywords, this difference is neglicable for the purpose of this sniff.

Note: in a future iteration, we may want to look at making the code for the "order" checks more efficient, but for now, at least it will work correctly again.

Suggested changelog entry

  • Added support for PHP 8.4 asymmetric visibility modifiers to the following sniffs:
    • PSR2.Classes.PropertyDeclaration

Related issues/external references

Refs:

Follow up on #851
Follow up on #1116

Related to #734

jrfnl added 2 commits June 6, 2025 02:10
…ility [1]

Per the FIG PSR-PER updates (next version), the "properties must have visibility declared" rule is also satisfied if only write visibility is declared.

> The `public` keyword MAY be omitted when using a set-visibility on a public-read property.

Includes updated test expectations (on the tests previously added in 871).

Refs:
* php-fig/per-coding-style 99
* php-fig/per-coding-style 114
…ility [2]

Per the FIG PSR-PER updates (next version), the "set-visibility MUST be _after_ the (read-)visibility".

This commit implements this, but as there may be two visibility modifiers, a minor refactor of the code involved in the wrong order checks for the `final` keyword and the `static` and `readonly` keywords is also needed as we can no longer presume that we can use the visibility keyword found with a search backwards to re-position other keywords.

Includes plenty of tests.
Includes a minor update to pre-existing test expectations (whitespace only), which is related to the refactor of the "fix"-code. As this sniff does not enforce any spacing requirements after the keywords, this difference is neglicable for the purpose of this sniff.

Note: in a future iteration, we may want to look at making the code for the "order" checks more efficient, but for now, at least it will work correctly again.

Refs:
* php-fig/per-coding-style 99
* php-fig/per-coding-style 114
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant