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 suggestion: new sniff EchoConcatenation #2259

Closed
jrfnl opened this issue Nov 27, 2018 · 2 comments
Closed

Feature suggestion: new sniff EchoConcatenation #2259

jrfnl opened this issue Nov 27, 2018 · 2 comments

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Nov 27, 2018

Inspired by this Twitter thread and this article.

Using concatenation exponentially increases the memory PHP uses. While in a lot of cases, there is no alternative, there are some specific situations, where there is, most notably when using echo where comma's or interpolation can be used instead.

Question: Would there be interest in a sniff to detect (and possibly auto-fix) this ?

I image a sniff like this could go into the Generic.CodeAnalysis category.

Detect:

echo "Hello " . $name . "! Welcome!"; // Use comma's or interpolation instead.
echo '<div><span>' . function_call($foo) . '</span>' . function_call($bar) . '</div>'; // Use comma's instead.

Recommended alternative way of writing this code:

echo "Hello $name! Welcome!";
echo '<div><span>', function_call($foo), '</span>', function_call($bar), '</div>';

For more code examples, see the ClearPHP article.

@gsherwood
Copy link
Member

I like it

@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 2, 2023

Closing as replaced by PHPCSStandards/PHPCSExtra#285

@jrfnl jrfnl closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2023
@github-project-automation github-project-automation bot moved this to Ready for Release in PHPCS v3 Development Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for Release
Development

No branches or pull requests

2 participants