8000 [Finder] Removed duplicated toRegex() code by jaytaph · Pull Request #14287 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Finder] Removed duplicated toRegex() code #14287

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

Merged
merged 1 commit into from
Apr 15, 2015
Merged

[Finder] Removed duplicated toRegex() code #14287

merged 1 commit into from
Apr 15, 2015

Conversation

jaytaph
Copy link
Contributor
@jaytaph jaytaph commented Apr 9, 2015

This patch removes duplicated toRegex() code by using the already existing Glob class. As this class wasn't unit-tested to begin with, this duplication also makes sure this class is tested properly.

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #14075
License MIT

8000
@aitboudad aitboudad changed the title Removed duplicated toRegex() code [Finder] Removed duplicated toRegex() code Apr 9, 2015
return new Regex('^'.$regex.'$');
$regex = FinderGlob::toRegex($this->pattern, $strictLeadingDot, $strictWildcardSlash);

return new Regex(substr($regex, 1, -1));
Copy link
Contributor

Choose a reason for hiding this comment

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

you can pass delimiter to Regex class:

return new Regex($regex, '', '#');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The delimiter is hardcoded in the Glob::toRegex(). I can't remove that without breaking BC, hence the reason for stripping it away before turning it into a regex.

Copy link
Contributor

Choose a reason for hiding this comment

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

well it look like a hack, why not adding new argument in toRegex ?

public static function toRegex(..., $delimiter = '#')
{
    ....
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If that doesnt break any bc rules, i'm happy to change that

Copy link
Member

Choose a reason for hiding this comment

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

Adding a new optional argument is not a BC break according to our BC promise (http://symfony.com/doc/current/contributing/code/bc.html).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect, I'll change the PR with this update

@jaytaph
Copy link
Contributor Author
jaytaph commented Apr 10, 2015

@aitboudad @fabpot Added an optional argument. However, one thing that is missing here (but this seems to be the case everywhere considering regular expressions in the Finder, is that it always assumes the start and end delimiter to be the same. This is not the case in some occasions: the end-delimiter for [ is ], and the same goes for {, < and (. But i think this is maybe something for another issue?

@fabpot
Copy link
Member
fabpot commented Apr 15, 2015

Thank you @jaytaph.

@fabpot fabpot merged commit 6150c3a into symfony:2.7 Apr 15, 2015
fabpot added a commit that referenced this pull request Apr 15, 2015
This PR was merged into the 2.7 branch.

Discussion
----------

[Finder] Removed duplicated toRegex() code

This patch removes duplicated `toRegex()` code by using the already existing `Glob` class. As this class wasn't unit-tested to begin with, this duplication also makes sure this class is tested properly.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14075
| License       | MIT

Commits
-------

6150c3a Removed duplicated toRegex() code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0