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 support for placing string literals into PHPStan types #111

Merged
merged 7 commits into from
Oct 17, 2023

Conversation

johnbillion
Copy link
Contributor

@johnbillion johnbillion commented Oct 16, 2023

Quite a few parameters in WordPress accept a string from a known list of possible values. This change adds REGULAR EXPRESSIONS to pluck out those possible values from the parameter and return tag docblocks and place them into PHPStan tags. This means anybody using PHPStan will see an error if they attempt to pass an invalid string value.

Take a look at the changes in wordpress-stubs.php to see what I mean.

I've also removed add_meta_box() and remove_meta_box() from the function map file because they're now redundant.

This only handles top-level string parameters and return types for now. Support for string values within args arrays can happen another day.

@szepeviktor
Copy link
Member

Thank you.

Could you revert those 2 $context types?

@johnbillion
Copy link
Contributor Author

I was planning on leaving those out due to #30

visitor.php Outdated Show resolved Hide resolved
@szepeviktor
Copy link
Member

This is too complex for me.
I would add these to WordPress core.

I let you cook this soup!

johnbillion and others added 2 commits October 17, 2023 15:11
Co-authored-by: IanDelMar <42134098+IanDelMar@users.noreply.github.com>
@johnbillion johnbillion requested a review from IanDelMar October 17, 2023 14:18
functionMap.php Show resolved Hide resolved
functionMap.php Show resolved Hide resolved
visitor.php Outdated Show resolved Hide resolved
visitor.php Show resolved Hide resolved
visitor.php Outdated Show resolved Hide resolved
johnbillion and others added 2 commits October 17, 2023 19:31
Co-authored-by: IanDelMar <42134098+IanDelMar@users.noreply.github.com>
@johnbillion johnbillion requested a review from IanDelMar October 17, 2023 18:37
@szepeviktor szepeviktor merged commit c0a1041 into php-stubs:master Oct 17, 2023
1 check passed
@szepeviktor
Copy link
Member

A big 🟢 green light!

@johnbillion johnbillion deleted the string-literals branch October 17, 2023 19:37
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