Lines
0.00%
0 / 6
Methods
0.00%
0 / 2
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| findClassNameForFile | 0.00% | 0 / 5 | 0.00% | 0 / 1 | 6 | ||
| 7 | final readonly class AutoloadRoot | |
| 8 | { | |
| 9 | private const string PHP_EXTENSION = '.php'; | |
| 10 | ||
| 11 | public function __construct( | |
| 12 | public string $namespacePrefix, | |
| 13 | public string $directory, | |
| 14 | ) {} | |
| 15 | ||
| 16 | /** @return class-string|null */ | |
| 17 | public function findClassNameForFile(string $file): ?string | |
| 18 | { | |
| 19 | if (!str_starts_with($file, $this->directory . \DIRECTORY_SEPARATOR)) { | |
| 20 | return null; | |
| 21 | } | |
| 22 | ||
| 23 | $relative = substr($file, \strlen($this->directory) + 1, -\strlen(self::PHP_EXTENSION)); | |
| 24 | $class = $this->namespacePrefix . strtr($relative, \DIRECTORY_SEPARATOR, '\\'); | |
| 25 | ||
| 26 | /** @var class-string $class */ | |
| 27 | return $class; | |
| 28 | } | |
| 29 | } |