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

Remove duplicate code and avoid running same regex in loop over and over #13

Merged
merged 2 commits into from
Apr 17, 2020

Conversation

danez
Copy link
Contributor

@danez danez commented Apr 16, 2020

No description provided.

@@ -123,32 +123,23 @@ private function analyzeFile($file)
if (preg_match('/\Wuse\s+\\\?'.str_replace('\\', '\\\\', $usedEntityNamespaceT).';/', $fileContent)) {
continue 2;
}
if (preg_match('/\Wuse\s+\\\?[a-zA-Z0-9_\\\]+\sas\s'.$aliasName.';/', $fileContent)) {
continue 2;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to run this in this loop as nothing that changes in the iteration has an effect on the regex.

$regexUsedEntity = str_replace('\\', '\\\\', $usedEntity);
if (preg_match('/\Wuse\s+(\\\?|[a-zA-Z0-9_\\\]+\\\\)'.$regexUsedEntity.';/', $fileContent)) {
continue;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the combination of the two regexes into one.

@danez danez merged commit c8b5a0d into master Apr 17, 2020
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.

None yet

1 participant