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

TypeNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 7 2
A isNativeType() 0 8 2
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