Passed
Push — Generators ( 4d090d...b2c8db )
by Roy
05:49 queued 14s
created

Entity::convertPathToNamespace()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace LaravelModulize\Support;
4
5
use Illuminate\Support\Str;
6
7
class Entity
8
{
9 8
    public static function getClassName($name)
10
    {
11 8
        return Str::contains($name, '/')
12 6
            ? array_reverse(explode('/', $name, 2))[0]
13 8
            : $name;
14
    }
15
16 2
    public static function getClassNamespace($name)
17
    {
18 2
        return Str::contains($name, '/')
19 2
            ? self::convertPathToNamespace($name)
20 2
            : '';
21
    }
22
23 2
    public static function convertPathToNamespace($name)
24
    {
25 2
        return Str::contains($name, '/')
26 2
            ? Str::start(
27 2
                str_replace('/', '', self::getPathBeforeClassName($name)),
28 2
                '\\'
29
            )
30 2
            : '';
31
32
    }
33
34 4
    public static function getPathBeforeClassName($name)
35
    {
36 4
        return Str::before($name, self::getClassName($name));
37
    }
38
}
39