-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Is your feature request related to a problem?
We already enforce functions' arguments and return types, considering that version v2 of this repo is PHP 7.4+ we should also enforce types on properties.
Describe the desired solution
Add a sniff that adds a warning whenever a class or trait declares properties without a type.
Describe the alternatives that you have considered
We either add it or not.
Additional context
To be noted: property type is invariant, so if a class overrides a property from a parent class in vendor (so the parent will not be scanned via the sniff) and the parent type has no type declaration, forcing the type declaration on the child (that would be scanned) will cause a parse error. PHPCS can't know that having a single-file context. Example
Using this rule with inheritance and without a static analyzer like Psalm could be dangerous.
(Another good reason to use Psalm and use inheritance sparingly).
Code of Conduct
- I agree to follow this project's Code of Conduct