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

PHPDoc type definitions - what's the standard we follow? #811

Open
fredden opened this issue Feb 11, 2025 · 0 comments
Open

PHPDoc type definitions - what's the standard we follow? #811

fredden opened this issue Feb 11, 2025 · 0 comments

Comments

@fredden
Copy link
Member

fredden commented Feb 11, 2025

Background

This codebase uses PHPDoc tags to specify property (@var), parameter (@param), and return (@return) types. This pre-dates the same being supported in native PHP. There are plans to move these types from the comments into PHP, but in the meantime (while we still support old versions of PHP), the comments remain and should be respected.

Problem

While working on #344 (comment), it has come to light that the syntax used in these comments to specify the contents of an array is not valid according to PSR-5. The syntax seems to be widely understood and is supported by other tools, but is not documented. Additionally, there is no validation of these comments within this codebase with the current tooling1. This leads to situations where developers must make a "best guess" for the format and trust that other humans validate the syntax during code review.

Way forward

Please can we define what syntax is valid / supported / accepted for type declarations within this codebase. This may include asking the maintainers of PSR-5 to update that document, and then pointing to this newly-updated-PSR-5 as the standard which we follow. Or we may like to point to a different standard such as that used by PHPStan.
Ideally this would include an automatic static-analysis check (perhaps with a PHP_CodeSniffer sniff) to validate the syntax of these special comments.

References

Footnotes

  1. It is possible for PHPStan to validate these comments in their current form, but doing so requires setting a PHPStan level higher than we are able to for other reasons. There are no PHP_CodeSniffer rules in the current ruleset which validate the format of these types.

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

No branches or pull requests

1 participant