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

[Feature Request]: support WP constants #5

Closed
1 task done
luislard opened this issue Aug 29, 2023 · 5 comments
Closed
1 task done

[Feature Request]: support WP constants #5

luislard opened this issue Aug 29, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@luislard
Copy link

Is your feature request related to a problem?

The stubs does not include WP constants like DAY_IN_SECONDS so we get psalm issues in our PR's

Describe the desired solution

A file with WP defined constants is included into latest.php

Describe the alternatives that you have considered

havent thought in an alternative

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@luislard luislard added the enhancement New feature or request label Aug 29, 2023
@gmazzap
Copy link
Contributor

gmazzap commented Aug 29, 2023

One of the reasons this repo exists is because alternative packages don't have constants.

So yes, we should have constants.

Here the config that includes constants: https://github.com/inpsyde/wp-stubs/blob/main/generate.php#L41

So not sure why constants are not there...

@tfrommen
Copy link
Member

tfrommen commented Aug 29, 2023

I ran into this as well just last week.
In the generated files, there are constants, but very few only.

I don't know if, by default, the parser only looks at define and const in the global scope, but maybe not in functions? A lot of the default contants are defined through the wp_initial_constants function.

@tfrommen
Copy link
Member

tfrommen commented Aug 29, 2023

Oh, it does indeed seem to be the issue.

https://github.com/php-stubs/generator/blob/bf758105124218225d59e698913ac852ee7d79c7/src/NodeVisitor.php#L136-L138

Since it is possible to supply a custom visitor, I guess we may want to create one that parses function bodies, maybe of select function names only...?

@gmazzap
Copy link
Contributor

gmazzap commented Aug 29, 2023

@tfrommen we already have a custom visitor which is used to generate some class/function stubs from fixtures instead of the WP code.

The purpose is to use advanced Psalm types for argument and return types.

Extending that visitor to also parse functions to extract constants looks like a good idea to me.

@tfrommen tfrommen mentioned this issue Feb 28, 2024
3 tasks
@tfrommen
Copy link
Member

This has been implemented in #7. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants