Passed
Push — master ( 0c6c2f...4ea690 )
by Frank
02:07
created

TypeNormalizer::normalize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing\CodeGeneration;
6
7
use ReflectionClass;
8
use ReflectionException;
9
use function ltrim;
10
11
/**
12
 * @internal
13
 */
14
class TypeNormalizer
15
{
16 4
    public static function normalize(string $type): string
17
    {
18 4
        $type = ltrim($type, '\\');
19
20 4
        return static::isNativeType($type)
21 3
            ? $type
22 4
            : '\\' . $type;
23
    }
24
25 4
    public static function isNativeType(string $type)
26
    {
27
        try {
28 4
            new ReflectionClass(ltrim($type, '\\'));
29
30 4
            return false;
31 3
        } catch (ReflectionException $isNativeType) {
32 3
            return true;
33
        }
34
    }
35
}
36