HeaderFactory::create()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 20
ccs 12
cts 12
cp 1
rs 9.4285
cc 3
eloc 12
nc 3
nop 1
crap 3
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