-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Fully qualify all global function calls. #718
Conversation
5778b60
to
112f5f1
Compare
Did you manually do this? I wonder if we could use Rector to automate this and if we should add a rule to make sure functions are always imported. I know they are in PHPStan, it'd be worth checking how that project enforces this |
Yeah i did do it manually not sure about the rector aspect with regards to the automation, as that would require either pre-commit hooks or for github actions to add commits onto opened prs to apply changes. It would be easy to add a phpcs sniff to enforce they're always fully-qualified though, phpstan itself uses https://github.com/slevomat/coding-standard and the sniff is Adopting the full |
Drupal core also uses parts of slevomat/coding-standard (https://git.drupalcode.org/project/coder/-/blob/8.3.x/composer.json?ref_type=heads#L21) It's used by Drupal core https://git.drupalcode.org/project/drupal/-/blob/11.x/core/phpcs.xml.dist?ref_type=heads#L255 I think it'd be great to add it as a dev dependency and include that one rule to start |
Turns out it also prevents the use of inline namespaces and a few others, which increases the size of the changeset. I've resolved all the violations it came up with in a separate commit to make it easier for you to review. |
34377ac
to
02cfd04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, and the extra fixes. There wasn't really a pattern for using FQCN or not. This is a nice addition to standardize and clean things up.
Modern php has several optimizations it can apply to global functions at compile-time, but only when they are fully-qualified.
For example it can translate several functions into specific opcodes which are faster than their function equivalent.
It can also do compile-time evaluation of constant operands for several functions.
Additionally, fully-qualifying global functions avoids a local namespace lookup and as such makes calls faster in general. The improvement will be pretty minor but every little helps, especially in situations where these functions may be called thousands of times in a single analysis.