Skip to content

[Feature Request]: Add a sniff to enforce property type #78

@gmazzap

Description

@gmazzap

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions