| Total Complexity | 6 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 21 | class Finder implements FinderInterface |
||
| 22 | { |
||
| 23 | private array $searchPath; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Constructor. |
||
| 27 | * |
||
| 28 | * @param mixed ...$searchPath The paths where SVG files are located |
||
| 29 | */ |
||
| 30 | 9 | public function __construct(...$searchPath) |
|
| 31 | { |
||
| 32 | 9 | $this->searchPath = $searchPath; |
|
| 33 | } |
||
| 34 | |||
| 35 | 4 | public function resolve(string $ident): \SplFileInfo |
|
| 36 | { |
||
| 37 | 4 | foreach ($this->searchPath as $basePath) { |
|
| 38 | 4 | $fullPath = rtrim($basePath, '/\\').'/'.$ident; |
|
| 39 | 4 | if ('.svg' !== substr($fullPath, -4)) { |
|
| 40 | 2 | $fullPath .= '.svg'; // Add svg extension |
|
| 41 | } |
||
| 42 | |||
| 43 | 4 | if (is_file($fullPath)) { |
|
| 44 | 3 | return new \SplFileInfo($fullPath); |
|
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | 1 | throw new FileNotFoundException(sprintf( |
|
| 49 | 1 | 'SVG file for "%s" could not be found on "%s".', |
|
| 50 | 1 | $ident, |
|
| 51 | 1 | (string) $this, |
|
| 52 | 1 | )); |
|
| 53 | } |
||
| 54 | |||
| 55 | 1 | public function __toString(): string |
|
| 58 | } |
||
| 59 | } |
||
| 60 |