Conditions | 7 |
Paths | 4 |
Total Lines | 23 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
39 | public function locateConfigFile(string $path): string |
||
40 | { |
||
41 | if (is_file($path)) { |
||
42 | return $path; |
||
43 | } |
||
44 | |||
45 | $dirPath = realpath($path) ?: getcwd(); |
||
46 | if (! is_dir((string) $dirPath)) { |
||
47 | // @codeCoverageIgnoreStart |
||
48 | throw new DataFileNotFoundException($path); |
||
49 | // @codeCoverageIgnoreEnd |
||
50 | } |
||
51 | |||
52 | do { |
||
53 | $maybePath = sprintf('%s/%s', $dirPath, $this->configName); |
||
54 | if (file_exists($maybePath) || file_exists($maybePath .= '.dist')) { |
||
55 | return $maybePath; |
||
56 | } |
||
57 | |||
58 | $dirPath = dirname($dirPath); // @phpstan-ignore-line |
||
59 | } while (dirname($dirPath) !== $dirPath); |
||
60 | |||
61 | throw new DataFileNotFoundException($path); |
||
62 | } |
||
64 |