Skip to content

functionMap: additions, improvement, corrections#127

Merged
szepeviktor merged 13 commits intophp-stubs:masterfrom
IanDelMar:output
Nov 2, 2023
Merged

functionMap: additions, improvement, corrections#127
szepeviktor merged 13 commits intophp-stubs:masterfrom
IanDelMar:output

Conversation

@IanDelMar
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

* @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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

szepeviktor commented Nov 2, 2023

Here it comes, a blind merge ...

@szepeviktor szepeviktor merged commit 5e28d4b into php-stubs:master Nov 2, 2023
@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