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 only_direct_assign config for SimplifyUselessVariableRector #6034

Merged
merged 1 commit into from
Jun 26, 2024

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Jun 25, 2024

When a variable is assigned using concatenation it should not simplify the variable.

This looks weird:

 $content = 'Hello, ';
-$content .= 'World!';

-return $content;
+return $content . 'World!';

It would be better to keep the original:

$content = 'Hello, ';
$content .= 'World!';

return $content;

@TomasVotruba
Copy link
Member

Sounds good 👍 Could you send a feature as well together?

@samsonasik
Copy link
Member

@ruudk @TomasVotruba I think this should be configurable, eg: only_direct_assign with default to false so original opiniated functionality still works

@ruudk ruudk changed the title Add failing test for SimplifyUselessVariableRector Add SKIP_CONCAT config for SimplifyUselessVariableRector Jun 26, 2024
@ruudk
Copy link
Contributor Author

ruudk commented Jun 26, 2024

Great, I just updated the PR with an implementation. Let me know if you prefer other naming or have any feedback. Thanks!

When a variable is assigned using concatenation it should not simplify the variable.

This looks weird:
```diff
 $content = 'Hello, ';
-$content .= 'World!';

-return $content;
+return $content . 'World!';
```

It would be better to keep the original:
```php
$content = 'Hello, ';
$content .= 'World!';

return $content;
```
@ruudk ruudk changed the title Add SKIP_CONCAT config for SimplifyUselessVariableRector Add only_direct_assign config for SimplifyUselessVariableRector Jun 26, 2024
@ruudk ruudk requested a review from samsonasik June 26, 2024 08:11
@TomasVotruba TomasVotruba merged commit 3058379 into rectorphp:main Jun 26, 2024
35 checks passed
@TomasVotruba
Copy link
Member

Thank you @ruudk 👍

@ruudk ruudk deleted the SkipMultiConcatString branch June 26, 2024 08:32
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