mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-20 23:41:57 +02:00
Fix FilesFinder for multiple suffixes
This commit is contained in:
parent
9ccf28e75b
commit
3528c0d0fe
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Rector\FileSystem;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\Exception\FileSystem\DirectoryNotFoundException;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
@ -43,11 +42,11 @@ final class FilesFinder
|
||||
{
|
||||
$this->ensureDirectoriesExist($directories);
|
||||
|
||||
$suffixes = $this->normalizeSuffixesToPattern($suffixes);
|
||||
$suffixesPattern = $this->normalizeSuffixesToPattern($suffixes);
|
||||
|
||||
$finder = Finder::create()
|
||||
->files()
|
||||
->name($suffixes)
|
||||
->name($suffixesPattern)
|
||||
->in($directories)
|
||||
->exclude(['examples', 'Examples', 'stubs', 'Stubs', 'fixtures', 'Fixtures', 'polyfill', 'Polyfill'])
|
||||
->notName('*polyfill*')
|
||||
@ -75,11 +74,8 @@ final class FilesFinder
|
||||
*/
|
||||
private function normalizeSuffixesToPattern(array $suffixes): string
|
||||
{
|
||||
$suffixesPattern = '';
|
||||
foreach ($suffixes as $suffix) {
|
||||
$suffixesPattern = Strings::startsWith($suffix, '*.') ? $suffix : '*.' . $suffix;
|
||||
}
|
||||
$suffixesPattern = implode('|', $suffixes);
|
||||
|
||||
return $suffixesPattern;
|
||||
return '#\.(' . $suffixesPattern . ')$#';
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,10 @@ final class FilesFinderTest extends AbstractContainerAwareTestCase
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
yield [['*.php'], 1, 'SomeFile.php'];
|
||||
yield [['*.yml'], 1, 'some_config.yml'];
|
||||
yield [['php'], 1, 'SomeFile.php'];
|
||||
yield [['yml'], 1, 'some_config.yml'];
|
||||
yield [['yaml'], 1, 'other_config.yaml'];
|
||||
yield [['php'], 1, 'SomeFile.php'];
|
||||
yield [['yaml', 'yml'], 2, 'some_config.yml'];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user