ClassNameTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 23
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getClassName() 0 16 3
1
<?php
2
3
namespace Riesenia\Pohoda\DI;
4
5
trait ClassNameTrait
6
{
7
    /**
8
     * @param string|class-string $name
0 ignored issues
show
Documentation Bug introduced by
The doc comment string|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in string|class-string.
Loading history...
9
     * @return string
10
     * The difference in absolute-relative paths are signalized by slash in the beginning of string
11
     */
12 19
    public function getClassName(string $name): string
13
    {
14 19
        $namespaceSub = explode('\\', __NAMESPACE__);
15 19
        $namespaceSub = array_slice($namespaceSub, 0, -1);
16 19
        $namespaceSub = implode('\\', $namespaceSub);
17
18 19
        if (str_starts_with($name, '\\')) {
19
            // absolute path
20 1
            return substr($name, 1);
21
        }
22
23 18
        if (str_starts_with($name, $namespaceSub)) {
24 2
            return $name;
25
        }
26
27 17
        return $namespaceSub . '\\' . $name;
28
    }
29
}
30