[DeadCode] RemoveDeadZeroAndOneOperationRector should not remove Constants#4910
Merged
TomasVotruba merged 3 commits intorectorphp:mainfrom Sep 19, 2023
Merged
[DeadCode] RemoveDeadZeroAndOneOperationRector should not remove Constants#4910TomasVotruba merged 3 commits intorectorphp:mainfrom
TomasVotruba merged 3 commits intorectorphp:mainfrom
Conversation
Member
|
Hi, the constants should not be removed indeed 👍 Could you send fix as well? Thanks |
Contributor
Author
|
@TomasVotruba I added a fix. I do see some failed checks, but I'm not sure if they are related to my changes. Please let me know if there's any action required from my side. |
Contributor
Author
|
@TomasVotruba all checks are green after merging latest main |
samsonasik
reviewed
Sep 19, 2023
Comment on lines
+17
to
+37
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector\Fixture; | ||
|
|
||
| class SkipConstants | ||
| { | ||
| public const ONE = 1; | ||
|
|
||
| public function run() | ||
| { | ||
| $value = 5 * self::ONE; | ||
| $value = 5 / self::ONE; | ||
| $value = self::ONE * 5; | ||
| $value = self::ONE / 5; | ||
| } | ||
| } | ||
|
|
||
| ?> |
Member
There was a problem hiding this comment.
second part is unneeded for equal content
Suggested change
| ?> | |
| ----- | |
| <?php | |
| namespace Rector\Tests\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector\Fixture; | |
| class SkipConstants | |
| { | |
| public const ONE = 1; | |
| public function run() | |
| { | |
| $value = 5 * self::ONE; | |
| $value = 5 / self::ONE; | |
| $value = self::ONE * 5; | |
| $value = self::ONE / 5; | |
| } | |
| } | |
| ?> |
Member
There was a problem hiding this comment.
Indeed, I'll get this merged and fixup as the main work is done 👍
Member
|
@TwanVermeulen Thank you, this is good to go 👍 🙂 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm curious about your thoughts!
Sometimes we use constants that explain a certain number by words.
If the constant number does not change the outcome of a mathematical expression, it's currently removed by
RemoveDeadZeroAndOneOperationRector. So for constants that have a value of 1 this would be the case.I would prefer to keep the constant, since it's added to increase readability.
What do you think? I added a test case that currently fails, but should pass imho.
Thanks for your input