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

[Util] Early strtolower() on StaticRectorStrings::isInArrayInsensitive() #232

Merged
merged 1 commit into from
Jun 16, 2021

Conversation

samsonasik
Copy link
Member

instead of run strtolower inside foreach, make variable and early assign for strtolower.

@samsonasik
Copy link
Member Author

samsonasik commented Jun 16, 2021

@TomasVotruba we may need a new rule for this, eg: MoveFunctionVariableBeforeLoopRector, this can be happen on another use case:

function findFirstLengthEquals($data, $value)
{
+     $strlenValue = strlen($value);
      foreach ($data as $d) {
-             if (strlen($d) === strlen($value)) {
+             if (strlen($d) === $strlenValue) {
                  return $d;
             }
      } 
      return null;
}

what do you think?

@TomasVotruba
Copy link
Member

I think this can be handled maually, the complexity for Rector seems to high for such a specific case.

@TomasVotruba TomasVotruba merged commit 6311c8b into main Jun 16, 2021
@TomasVotruba TomasVotruba deleted the early-strtolower-foreach branch June 16, 2021 10:30
@staabm
Copy link
Contributor

staabm commented Jun 16, 2021

I think this can be handled maually, the complexity for Rector seems to high for such a specific case.

If a rector-rule could do this for all pure-functions (instead of a specific rector for e.g. strlen() only), it could be worthwhile.

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