PathResolver::resolve()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 20
ccs 11
cts 12
cp 0.9167
rs 9.9
cc 3
nc 3
nop 1
crap 3.0052
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