HeaderFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 0
cbo 0
dl 0
loc 39
ccs 18
cts 18
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 20 3
A splitEntry() 0 13 2
1
<?php
2
3
namespace Fracture\Http;
4
5
class HeaderFactory
6
{
7
8 5
    public function create($header)
9
    {
10 5
        $parts = $this->splitEntry($header);
11
12 5
        if (false === $parts) {
13 1
            return null;
14
        }
15
16 4
        list($name, $value) = $parts;
17 4
        $name = str_replace('-', '', $name);
18 4
        $class = '\Fracture\Http\Headers\\' . $name;
19
20 4
        if (false === class_exists($class)) {
21 1
            return null;
22
        }
23
24 3
        $instance = new $class($value);
25 3
        $instance->prepare();
26 3
        return $instance;
27
    }
28
29
30 2
    public function splitEntry($header)
31
    {
32 2
        $separator = strpos($header, ': ');
33
34 2
        if (false === $separator) {
35 1
            return false;
36
        }
37
38
        return [
39 1
            substr($header, 0, $separator),
40 1
            substr($header, $separator + 2),
41
        ];
42
    }
43
}
44