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

Leverage PHP 7 language features #7597

Closed
swissspidy opened this issue May 19, 2021 · 7 comments · Fixed by #8321
Closed

Leverage PHP 7 language features #7597

swissspidy opened this issue May 19, 2021 · 7 comments · Fixed by #8321
Labels
P2 Should do soon Type: Code Quality Things that need a refactor, rewrite or just some good old developer ❤️ Type: Infrastructure Changes impacting testing infrastructure or build tooling

Comments

@swissspidy
Copy link
Collaborator

Task Description

With the PHP version requirement bump we can use language features introduced in PHP 7, like scalar type declarations, return type declarations, and the null coalescing operator.

See https://www.php.net/manual/en/migration70.new-features.php for a full list of changes.

I expect the IDE can help with a lot of these optimizations.

@swissspidy swissspidy added P2 Should do soon Type: Infrastructure Changes impacting testing infrastructure or build tooling Type: Code Quality Things that need a refactor, rewrite or just some good old developer ❤️ Pod: WP & Infra labels May 19, 2021
@spacedmonkey
Copy link
Contributor

Useful features.

  • Scalar type declarations
  • Return type declarations
  • Group use declarations

@swissspidy
Copy link
Collaborator Author

PHPStorm gives me tons of recommendations for automatically adding types and using null coalescing operators throughout the code base. That seems like a good start. Don't think grouping use statements provides much value, so we can skip that for now.

We have to be careful adding type declarations to add_action/add_filter callbacks, as it's not guaranteed that we get the expected type.

@spacedmonkey
Copy link
Contributor

PHPStorm gives me tons of recommendations for automatically adding types and using null coalescing operators throughout the code base

How do you see these recommendations?

@swissspidy
Copy link
Collaborator Author

I think the ones I get are provided by the https://plugins.jetbrains.com/plugin/7622-php-inspections-ea-extended- plugin. Can highly recommend installing it 👍

@spacedmonkey
Copy link
Contributor

This might be useful as well - https://github.com/rectorphp/rector

@spacedmonkey
Copy link
Contributor

After trying out refactor, here is the output.

55d3a46

@swissspidy
Copy link
Collaborator Author

swissspidy commented Jul 8, 2021

Looks promising 👍

We'll probably have to remove some of those for add_filter/add_action callbacks as mentioned above.
Also, we can add return type declarations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Should do soon Type: Code Quality Things that need a refactor, rewrite or just some good old developer ❤️ Type: Infrastructure Changes impacting testing infrastructure or build tooling
Projects
None yet
2 participants