Header::toRfc2822()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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