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

PHP 8.0 | TypeDeclaration sniffs: examine properties declared in the constructor correctly #1447

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Dec 26, 2022

PHP 8.0 | NewTypedProperties: examine properties declared in the constructor

Typed properties declared via a class constructor should also be examined by the NewTypedProperties sniff as the allowed types for properties are different than those for parameters.

Includes:

  • Adding T_FUNCTION to the tokens to be examined.
  • Splitting the "type checking" logic off into its own method to allow for multiple properties declared in a constructor.

Includes unit tests.

Ref: https://wiki.php.net/rfc/constructor_promotion

PHP 8.0 | NewParamTypeDeclarations: ignore promoted properties

Properties declared via a class constructor follow the property type rules, not the parameter type rules, so ignore them for this sniff. These will be examined in the NewTypedProperties sniff instead.

Includes unit tests.

Related to #809

…tructor

Typed properties declared via a class constructor should also be examined by the `NewTypedProperties` sniff as the allowed types for properties are different than those for parameters.

Includes:
* Adding `T_FUNCTION` to the tokens to be examined.
* Splitting the "type checking" logic off into its own method to allow for multiple properties declared in a constructor.

Includes unit tests.

Ref: https://wiki.php.net/rfc/constructor_promotion
Properties declared via a class constructor follow the property type rules, not the parameter type rules, so ignore them for this sniff. These will be examined in the `NewTypedProperties` sniff instead.

Includes unit tests.
@wimg wimg merged commit 344191d into develop Dec 30, 2022
@wimg wimg deleted the php-8.0/newtypedproperties-newparamtype-support-constructor-property-promotion branch December 30, 2022 15:38
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.

None yet

2 participants