Lines 0.00% 0 / 6
Functions and Methods 0.00% 0 / 2
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
AutoloadRoot 0.00% 0 / 6 0.00% 0 / 2 12 0.00% 0 / 1
 __construct 0.00% 0 / 1 0.00% 0 / 1 2
 findClassNameForFile 0.00% 0 / 5 0.00% 0 / 1 6
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Config;
6
7final 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}