PathResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 2
b 0
f 0
dl 0
loc 26
ccs 13
cts 14
cp 0.9286
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A resolve() 0 20 3
1
<?php
2
3
/*
4
 *  This file is part of the Micro framework package.
5
 *
6
 *  (c) Stanislau Komar <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace Micro\Plugin\Configuration\Helper\Business\Path;
13
14
use Micro\Plugin\Configuration\Helper\Business\Plugin\PluginClassResolverInterface;
15
16
class PathResolver implements PathResolverInterface
17
{
18 1
    public function __construct(private readonly PluginClassResolverInterface $pluginClassResolver)
19
    {
20 1
    }
21
22 1
    public function resolve(string $relative): string
23
    {
24 1
        if (!str_starts_with($relative, '@')) {
25 1
            return $relative;
26
        }
27
28 1
        $alias = explode(\DIRECTORY_SEPARATOR, $relative);
29
30 1
        $plugin = $this->pluginClassResolver->resolve(ltrim($alias[0], '@'));
31 1
        $reflection = new \ReflectionClass($plugin);
32
33 1
        $file = $reflection->getFileName();
34 1
        if (false === $file) {
35
            return $relative;
36
        }
37
38 1
        $basePath = \dirname($file);
39 1
        $alias[0] = $basePath;
40
41 1
        return implode(\DIRECTORY_SEPARATOR, $alias);
42
    }
43
}
44