ContentTransferEncoding::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Header;
5
6
use Genkgo\Mail\HeaderInterface;
7
8
final class ContentTransferEncoding implements HeaderInterface
9
{
10
    private const VALID_ENCODINGS = [
11
        '7bit' => true,
12
        '8bit' => true,
13
        'binary' => true,
14
        'quoted-printable' => true,
15
        'base64' => true,
16
        'ietf-token' => true,
17
        'x-token' => true,
18
    ];
19
20
    /**
21
     * @var string
22
     */
23
    private $encoding;
24
25
    /**
26
     * @param string $encoding
27
     */
28 88
    public function __construct($encoding)
29
    {
30 88
        if (!isset(self::VALID_ENCODINGS[$encoding])) {
31
            throw new \InvalidArgumentException('Invalid Content-Transfer-Encoding ' . $encoding);
32
        }
33
34 88
        $this->encoding = $encoding;
35 88
    }
36
37
    /**
38
     * @return HeaderName
39
     */
40 88
    public function getName(): HeaderName
41
    {
42 88
        return new HeaderName('Content-Transfer-Encoding');
43
    }
44
45
    /**
46
     * @return HeaderValue
47
     */
48 40
    public function getValue(): HeaderValue
49
    {
50 40
        return new HeaderValue($this->encoding);
51
    }
52
}
53