Conditions | 6 |
Paths | 9 |
Total Lines | 36 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
15 | public function buildIndexFromPath(string $path, array $excludedPathsRegexp = []): Index |
||
16 | { |
||
17 | if (!is_dir($path) || !is_readable($path)) |
||
18 | { |
||
19 | throw new \InvalidArgumentException("Given path {$path} does not exist or is not readable."); |
||
20 | } |
||
21 | |||
22 | $finder = new Finder(); |
||
23 | $finder->in($path); |
||
24 | $finder->ignoreDotFiles(false); |
||
25 | |||
26 | foreach ($excludedPathsRegexp as $excludedPathRegexp) |
||
27 | { |
||
28 | $finder->notPath($excludedPathRegexp); |
||
29 | } |
||
30 | |||
31 | $index = new Index(); |
||
32 | |||
33 | foreach ($finder->directories() as $fileInfo) |
||
34 | { |
||
35 | /** @var SplFileInfo $fileInfo */ |
||
36 | |||
37 | $index->addObject(IndexObject::fromPath($path, $fileInfo->getRelativePathname())); |
||
38 | } |
||
39 | |||
40 | foreach ($finder->files() as $fileInfo) |
||
41 | { |
||
42 | /** @var SplFileInfo $fileInfo */ |
||
43 | |||
44 | $index->addObject(IndexObject::fromPath($path, $fileInfo->getRelativePathname())); |
||
45 | } |
||
46 | |||
47 | // todo: add symlinks |
||
48 | |||
49 | return $index; |
||
50 | } |
||
51 | } |
||
52 |