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

functionMap: additions, improvement, corrections #127

Merged
merged 13 commits into from
Nov 2, 2023

Conversation

IanDelMar
Copy link
Contributor

@IanDelMar IanDelMar commented Nov 1, 2023

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() and get_category_by_path(). I added tests, but did not test each parameter variation or unions.

'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],
Copy link
Contributor

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

Copy link
Contributor Author

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')
Copy link
Member

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' );

Copy link
Contributor Author

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.

@szepeviktor
Copy link
Member

szepeviktor commented Nov 2, 2023

Here it comes, a blind merge ...

@szepeviktor szepeviktor merged commit 5e28d4b into php-stubs:master Nov 2, 2023
1 check passed
@IanDelMar IanDelMar deleted the output branch November 2, 2023 23:56
IanDelMar added a commit to IanDelMar/wordpress-stubs that referenced this pull request Nov 4, 2023
* 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
IanDelMar added a commit to IanDelMar/wordpress-stubs that referenced this pull request Nov 4, 2023
IanDelMar added a commit to IanDelMar/wordpress-stubs that referenced this pull request Nov 11, 2023
* 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
IanDelMar added a commit to IanDelMar/wordpress-stubs that referenced this pull request Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants