Factory::buildFromString()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
crap 3.0416
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CompoLab\Domain\Type;
4
5
final class Factory
6
{
7 7
    public static function buildFromString(string $string): Type
8
    {
9 7
        if (preg_match('/^git$/i', $string)) {
10 6
            return new Git;
11
        }
12
13 2
        if (preg_match('/^tar$/i', $string)) {
14 2
            return new Tar;
15
        }
16
17
        throw new \RuntimeException(sprintf('Impossible to create a type from string "%s"', $string));
18
    }
19
}
20