Skip to content

Commit

Permalink
Merge pull request #32 from symplify/tv-multi-files
Browse files Browse the repository at this point in the history
Allow multiple files
  • Loading branch information
TomasVotruba committed Dec 16, 2023
2 parents 9903d3e + f81fb3d commit 453a8e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Console/Command/SwitchFormatCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function configure(): void

$this->addArgument(
Option::SOURCES,
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
InputArgument::IS_ARRAY,
'Path to directory/file with configs'
);

Expand Down
22 changes: 12 additions & 10 deletions src/Finder/ConfigFileFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ final class ConfigFileFinder
*/
public function findFileInfos(array $sources): array
{
if (count($sources) === 1 && is_file($sources[0])) {
$path = realpath($sources[0]);
return [
new SplFileInfo(
$path,
$sources[0],
$sources[0]
)];
$fileInfos = [];
$directories = [];

foreach ($sources as $source) {
if (is_file($source)) {
$fileInfos[] = new SplFileInfo(realpath($source), $source, $source);
} else {
$directories[] = $source;
}
}

$finder = new Finder();
$finder->files()
->in($sources)
->name(self::CONFIG_SUFFIXES_REGEX);
->in($directories)
->name(self::CONFIG_SUFFIXES_REGEX)
->append($fileInfos);

return iterator_to_array($finder->getIterator());
}
Expand Down

0 comments on commit 453a8e6

Please sign in to comment.