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

Add dynamic return type for get_permalink()/get_the_permalink() #139

Merged
merged 3 commits into from Feb 4, 2023

Conversation

IanDelMar
Copy link
Sponsor Contributor

Adds dynamic function return type extension for get_permalink() and get_the_permalink().

Copy link
Contributor

@herndlm herndlm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also small idea for an improvement - what do you think of letting it return false in case the arg is not an object AND not an integer? That could help find some false usages of those functions :)

@szepeviktor
Copy link
Owner

@IanDelMar Thank you for working on a Saturday! 📅

Co-authored-by: Viktor Szépe <viktor@szepe.net>
@IanDelMar
Copy link
Sponsor Contributor Author

Also small idea for an improvement - what do you think of letting it return false in case the arg is not an object AND not an integer? That could help find some false usages of those functions :)

PHPStan knows that the first argument must be of type int or WP_Post because of the stubs file. So there is an error if you use a non integer, non WP_Post argument. Using a string type argument gives Parameter #1 $post of function get_permalink expects int|WP_Post, string given.

Using the return value as an argument for a function that expects a string, e.g. str_replace( 'a string', 'a new string', get_permalink( 'not expected string' ) ) gives Parameter #3 $subject of function str_replace expects array|string, string|false given.

But maybe it is helpful for some users to have Parameter #3 $subject of function str_replace expects array|string, false given. instead.

Co-Authored-By: Martin Herndl <martin@herndl.org>
@szepeviktor szepeviktor merged commit 08aefe9 into szepeviktor:master Feb 4, 2023
@herndlm
Copy link
Contributor

herndlm commented Feb 4, 2023

Oh, of course, makes sense. Thx!

@IanDelMar IanDelMar deleted the get-permalink branch February 4, 2023 13:08
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.

None yet

3 participants