8000 [Finder] Allow arrays as parameters of some methods for better fluent experience and code readability by jfredon · Pull Request #27891 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Finder] Allow arrays as parameters of some methods for better fluent experience and code readability #27891

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 41 additions & 27 deletions src/Symfony/Component/Finder/Finder.php
< 10000 td class="blob-num blob-num-deletion empty-cell">
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,20 @@ public function files()
*
* $finder->depth('> 1') // the Finder will start matching at level 1.
* $finder->depth('< 3') // the Finder will descend at most 3 levels of directories below the starting point.
* $finder->depth(['>= 1', '< 3'])
*
* @param string|int $level The depth level expression
* @param string|int|string[]|int[] $levels The depth level expression or an array of depth levels
*
* @return $this
*
* @see DepthRangeFilterIterator
* @see NumberComparator
*/
public function depth($level)
public function depth($levels)
{
$this->depths[] = new Comparator\NumberComparator($level);
foreach ((array) $levels as $level) {
$this->depths[] = new Comparator\NumberComparator($level);
}

return $this;
}
Expand All @@ -131,18 +134,21 @@ public function depth($level)
* $finder->date('until 2 days ago');
* $finder->date('> now - 2 hours');
* $finder->date('>= 2005-10-15');
* $finder->date(['>= 2005-10-15', '<= 2006-05-27']);
*
* @param string $date A date range string
* @param string|string[] $dates A date range string or an array of date ranges
*
* @return $this
*
* @see strtotime
* @see DateRangeFilterIterator
* @see DateComparator
*/
public function date($date)
public function date($dates)
{
$this->dates[] = new Comparator\DateComparator($date);
foreach ((array) $dates as $date) {
$this->dates[] = new Comparator\DateComparator($date);
}

return $this;
}
Expand All @@ -155,32 +161,33 @@ public function date($date)
* $finder->name('*.php')
* $finder->name('/\.php$/') // same as above
* $finder->name('test.php')
* $finder->name(['test.py', 'test.php'])
*
* @param string $pattern A pattern (a regexp, a glob, or a string)
* @param string|string[] $patterns A pattern (a regexp, a glob, or a string) or an array of patterns
*
* @return $this
*
* @see FilenameFilterIterator
*/
public function name($pattern)
public function name($patterns)
{
$this->names[] = $pattern;
$this->names = \array_merge($this->names, (array) $patterns);

return $this;
}

/**
* Adds rules that files must not match.
*
* @param string $pattern A pattern (a regexp, a glob, or a string)
* @param string|string[] $patterns A pattern (a regexp, a glob, or a string) or an array of patterns
*
* @return $this
*
* @see FilenameFilterIterator
*/
public function notName($pattern)
public function notName($patterns)
{
$this->notNames[] = $pattern;
$this->notNames = \array_merge($this->notNames, (array) $patterns);

return $this;
}
Expand All @@ -192,16 +199,17 @@ public function notName($pattern)
*
* $finder->contains('Lorem ipsum')
* $finder->contains('/Lorem ipsum/i')
* $finder->contains(['dolor', '/ipsum/i'])
*
* @param string $pattern A pattern (string or regexp)
* @param string|string[] $patterns A pattern (string or regexp) or an array of patterns
*
* @return $this
*
* @see FilecontentFilterIterator
*/
public function contains($pattern)
public function contains($patterns)
{
$this->contains[] = $pattern;
$this->contains = \array_merge($this->contains, (array) $patterns);

return $this;
}
Expand All @@ -213,16 +221,17 @@ public function contains($pattern)
*
* $finder->notContains('Lorem ipsum')
* $finder->notContains('/Lorem ipsum/i')
* $finder->notContains(['lorem', '/dolor/i'])
*
* @param string $pattern A pattern (string or regexp)
* @param string|string[] $patterns A pattern (string or regexp) or an array of patterns
*
* @return $this
*
* @see FilecontentFilterIterator
*/
public function notContains($pattern)
public function notContains($patterns)
{
$this->notContains[] = $pattern;
$this->notContains = \array_merge($this->notContains, (array) $patterns);

return $this;
}
Expand All @@ -234,18 +243,19 @@ public function notContains($pattern)
*
* $finder->path('some/special/dir')
* $finder->path('/some\/special\/dir/') // same as above
* $finder->path(['some dir', 'another/dir'])
*
* Use only / as dirname separator.
*
* @param string $pattern A pattern (a regexp or a string)
* @param string|string[] $patterns A pattern (a regexp or a string) or an array of patterns
*
* @return $this
*
* @see FilenameFilterIterator
*/
public function path($pattern)
public function path($patterns)
{
$this->paths[] = $pattern;
$this->paths = \array_merge($this->paths, (array) $patterns);

return $this;
}
Expand All @@ -257,18 +267,19 @@ public function path($pattern)
*
* $finder->notPath('some/special/dir')
* $finder->notPath('/some\/special\/dir/') // same as above
* $finder->notPath(['some/file.txt', 'another/file.log'])
*
* Use only / as dirname separator.
*
* @param string $pattern A pattern (a regexp or a string)
* @param string|string[] $patterns A pattern (a regexp or a string) or an array of patterns
*
* @return $this
*
* @see FilenameFilterIterator
*/
public function notPath($pattern)
public function notPath($patterns)
{
$this->notPaths[] = $pattern;
$this->notPaths = \array_merge($this->notPaths, (array) $patterns);

return $this;
}
Expand All @@ -279,17 +290,20 @@ public function notPath($pattern)
* $finder->size('> 10K');
* $finder->size('<= 1Ki');
* $finder->size(4);
* $finder->size(['> 10K', '< 20K'])
*
* @param string|int $size A size range string or an integer
* @param string|int|string[]|int[] $sizes A size range string or an integer or an array of size ranges
*
* @return $this
*
* @see SizeRangeFilterIterator
* @see NumberComparator
*/
public function size($size)
public function size($sizes)
{
$this->sizes[] = new Comparator\NumberComparator($size);
foreach ((array) $sizes as $size) {
$this->sizes[] = new Comparator\NumberComparator($size);
}

return $this;
}
Expand Down
Loading
0