Issues (83)

src/FilesystemFacade.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hanneskod\readmetester;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
use Symfony\Component\Finder\Finder;
9
10
class FilesystemFacade
11
{
12
    public function __construct(
13
        private EventDispatcherInterface $dispatcher,
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_PRIVATE, expecting T_VARIABLE on line 13 at column 8
Loading history...
14
    ) {}
15
16
    /**
17
     * @param array<string> $paths
18
     * @param array<string> $extensions
19
     * @param array<string> $ignore
20
     * @return iterable<Compiler\InputInterface>
21
     */
22
    public function getFilesystemInput(string $cwd, array $paths, array $extensions, array $ignore): iterable
23
    {
24
        $finder = (new Finder())->files()->in($cwd)->ignoreUnreadableDirs();
25
26
        // Set paths to scan
27
28
        $finder->path(
29
            array_map(
30
                fn($path) => '/^' . preg_quote($path, '/') . '/i',
31
                $paths
32
            )
33
        );
34
35
        // Set file extensions
36
37
        $finder->name(
38
            array_map(
39
                fn($extension) => '/\\.' . preg_quote($extension, '/') . '$/i',
40
                $extensions
41
            )
42
        );
43
44
        // Set paths to ignore
45
46
        $finder->notPath(
47
            array_map(
48
                fn($path) => '/^' . preg_quote($path, '/') . '/i',
49
                $ignore
50
            )
51
        );
52
53
        foreach ($finder as $file) {
54
            yield new Compiler\FileInput($file);
55
            $this->dispatcher->dispatch(new Event\FileIncluded($file));
56
        }
57
    }
58
}
59