Header   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 73
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A fromString() 0 3 1
A getField() 0 3 1
A toRfc2822() 0 3 1
A getValue() 0 3 1
A __construct() 0 4 1
A fromRfc2822() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpEmail;
6
7
class Header
8
{
9
    /**
10
     * @var string
11
     */
12
    private $field;
13
    /**
14
     * @var string
15
     */
16
    private $value;
17
18
    /**
19
     * @param string $field
20
     * @param string $value
21
     */
22 2
    public function __construct(string $field, string $value)
23
    {
24 2
        $this->field = $field;
25 2
        $this->value = $value;
26
    }
27
28
    /**
29
     * @param string $header
30
     *
31
     * @return Header
32
     */
33 1
    public static function fromRfc2822(string $header): Header
34
    {
35 1
        $parts = explode(':', $header, 2);
36
37 1
        return new static($parts[0], trim($parts[1]));
38
    }
39
40
    /**
41
     * @param string $header
42
     *
43
     * @return Header
44
     */
45 1
    public static function fromString(string $header): Header
46
    {
47 1
        return self::fromRfc2822($header);
48
    }
49
50
    /**
51
     * @return string
52
     */
53 2
    public function getField(): string
54
    {
55 2
        return $this->field;
56
    }
57
58
    /**
59
     * @return string
60
     */
61 2
    public function getValue(): string
62
    {
63 2
        return $this->value;
64
    }
65
66
    /**
67
     * @return string
68
     */
69 1
    public function toRfc2822(): string
70
    {
71 1
        return sprintf('%s: %s', $this->field, $this->value);
72
    }
73
74
    /**
75
     * @return string
76
     */
77 1
    public function __toString(): string
78
    {
79 1
        return $this->toRfc2822();
80
    }
81
}
82