-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
functionMap: additions, improvement, corrections #127
Conversation
'stripslashes_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], | ||
'urldecode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], | ||
'urlencode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], | ||
'wp_clear_scheduled_hook' => ['(0|positive-int|($wp_error is false ? false : \WP_Error))', 'args'=>$cronArgsType], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware PHPStan supported this syntax for conditional return types, nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me neither. It's great! It helps to simplify some of the conditions and make them easier to read.
@@ -130182,6 +130191,7 @@ function get_tax_sql($tax_query, $primary_table, $primary_id_column) | |||
* @param string $filter Optional. How to sanitize term fields. Default 'raw'. | |||
* @return WP_Term|array|WP_Error|null WP_Term instance (or array) on success, depending on the `$output` value. | |||
* WP_Error if `$taxonomy` does not exist. Null for miscellaneous failure. | |||
* @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output | |||
* @phpstan-return ($output is 'ARRAY_A' ? array<string, string|int>|\WP_Error|null : ($output is 'ARRAY_N' ? list<string|int>|\WP_Error|null : \WP_Term|\WP_Error|null)) | |||
*/ | |||
function get_term($term, $taxonomy = '', $output = \OBJECT, $filter = 'raw') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core says: constant
phpstan says: string
viktor says: WordPress
define( 'OBJECT', 'OBJECT' );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be fair, core also says string but passes the default string as a constant. But yeah, define( 'OBJECT', 'OBJECT' );
is weird.
Here it comes, a blind merge ... |
* Improve return type of get_comment() and get_post() * Add wpdb::get_row() to functions map * Add tests for wp_clear_scheduled_hook() * Add wpdb::get_results() to the functions map * Add get_bookmark() to function map * Add get_category() to function map * Add argument type to get_term() * Use fully qualified name * Add get_category_by_path() to function map * Remove types already added without function map * Add spaces around array assignment operator * Regenerate function map * Add trailing comma to last array item
* Improve return type of get_comment() and get_post() * Add wpdb::get_row() to functions map * Add tests for wp_clear_scheduled_hook() * Add wpdb::get_results() to the functions map * Add get_bookmark() to function map * Add get_category() to function map * Add argument type to get_term() * Use fully qualified name * Add get_category_by_path() to function map * Remove types already added without function map * Add spaces around array assignment operator * Regenerate function map * Add trailing comma to last array item
Most of the PR deals with the
$output
argument and conditional return types handling$output ∈ {OBJECT, ARRAY_A, ARRAY_N}
.Additions:
wpdb::get_row()
,wpdb::get_results()
,get_bookmark()
,get_category()
andget_category_by_path()
. I added tests, but did not test each parameter variation or unions.