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