-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Implement short inline syntax for array parameters and return values #15
Comments
There is room for improvement in core's source code. This package does not alter the source code in any way, simply removes function contents. |
A few observations:
|
( new WP_Http )->request( 'http://example.com', [
'banana' => 'yellow',
] );
|
|
PHP has object properties for more than a decade. Code could be written in a human-friendly way. |
Oh yes I completely agree, these array-style arguments are a nightmare. I regret using them in some of my libraries such as Extended CPTs. This is why I started playing around with |
Smart people started building dirt-hiding-layers between WordPress core and project-specific code - meaning what you write and read. dirt=techdebt |
Alternative: Convince PHPStan and Psalm to support this hash style notation. |
WordPress marches into a dead-end. Let's convince others to join :) |
Potential solution for the machine-readable versus human-readable: Use |
Neither PHPStan nor Psalm support the hash-style notation used by WordPress for its array parameters and array return values.
This means there's currently no way to inform static analysis tools of the types of the array elements passed to or returned by functions such as
wp_remote_post()
and classes such asWP_Query
.It would be great to:
wp_remote_post() $args
to their canonical function parameter such asWP_Http::request() $args
and then apply the same docblock from the canonical function in its wrapper functions. This allows for parameter type checking in wrapper functions which are more commonly used. This likely needs to happen as a separate second step as it will be a manual process to create the mapping. WordPress core isn't well documented or consistently documented in this regard.Approach
It's possible that
johnbillion/wp-parser-lib
could be used to aid the transformation as it's able to tokenise the hash style array notation.Considerations
Unfortunately the short inline syntax supported by PHPStan and Psalm don't allow for human-readable documentation of the array elements. This means the stubs will be better for PHPStan and Psalm but worse for humans. Maybe two sets of stubs needs to be created, one with the human-readable docblock from core and one with the short inline syntax for use in static analysis.
Refs
The text was updated successfully, but these errors were encountered: