Skip to content

Commit

Permalink
support paths referring to files as well
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik committed Sep 16, 2022
1 parent 8dd3b26 commit 36f2190
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/ApiGen.php
Expand Up @@ -8,12 +8,12 @@
use Symfony\Component\Console\Style\OutputStyle;

use function array_column;
use function array_keys;
use function array_slice;
use function count;
use function hrtime;
use function implode;
use function iterator_to_array;
use function is_dir;
use function is_file;
use function memory_get_peak_usage;
use function sprintf;

Expand Down Expand Up @@ -63,11 +63,30 @@ public function generate(): void
*/
protected function findFiles(): array
{
$finder = Finder::findFiles(...$this->include)
->exclude(...$this->exclude)
->from(...$this->paths);
$files = [];
$dirs = [];

$files = array_keys(iterator_to_array($finder));
foreach ($this->paths as $path) {
if (is_file($path)) {
$files[] = $path;

} elseif (is_dir($path)) {
$dirs[] = $path;

} else {
$this->output->error(sprintf('Path "%s" does not exist.', $path));
}
}

if (count($dirs) > 0) {
$finder = Finder::findFiles(...$this->include)
->exclude(...$this->exclude)
->from(...$dirs);

foreach ($finder as $file => $_) {
$files[] = $file;
}
}

if (!count($files)) {
throw new \RuntimeException('No source files found.');
Expand Down

0 comments on commit 36f2190

Please sign in to comment.