Passed
Pull Request — master (#27)
by Anatoly
04:06
created

ContentMD5Header::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-message/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-message
10
 */
11
12
namespace Sunrise\Http\Message\Header;
13
14
/**
15
 * Import classes
16
 */
17
use Sunrise\Http\Message\Exception\InvalidHeaderValueException;
18
use Sunrise\Http\Message\Header;
19
20
/**
21
 * @link https://tools.ietf.org/html/rfc2616#section-14.15
22
 */
23
class ContentMD5Header extends Header
24
{
25
26
    /**
27
     * Regular Expression for a MD5 digest validation
28
     *
29
     * @link https://tools.ietf.org/html/rfc2045#section-6.8
30
     *
31
     * @var string
32
     */
33
    public const RFC2045_MD5_DIGEST = '/^[A-Za-z0-9\+\/]+=*$/';
34
35
    /**
36
     * @var string
37
     */
38
    private string $value;
39
40
    /**
41
     * Constructor of the class
42
     *
43
     * @param string $value
44
     *
45
     * @throws InvalidHeaderValueException
46
     *         If the value isn't valid.
47
     */
48 7
    public function __construct(string $value)
49
    {
50 7
        $this->validateValueByRegex(self::RFC2045_MD5_DIGEST, $value);
51
52 5
        $this->value = $value;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 5
    public function getFieldName(): string
59
    {
60 5
        return 'Content-MD5';
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 3
    public function getFieldValue(): string
67
    {
68 3
        return $this->value;
69
    }
70
}
71