Passed
Pull Request — master (#27)
by Anatoly
39:10
created

ContentDispositionHeader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 54
ccs 12
cts 12
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFieldValue() 0 8 2
A __construct() 0 8 1
A getFieldName() 0 3 1
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\Exception\InvalidHeaderValueParameterException;
19
use Sunrise\Http\Message\Header;
20
21
/**
22
 * Import functions
23
 */
24
use function sprintf;
25
26
/**
27
 * @link https://tools.ietf.org/html/rfc2616#section-19.5.1
28
 */
29
class ContentDispositionHeader extends Header
30
{
31
32
    /**
33
     * @var string
34
     */
35
    private string $type;
36
37
    /**
38
     * @var array<string, string>
39
     */
40
    private array $parameters;
41
42
    /**
43
     * Constructor of the class
44
     *
45
     * @param string $type
46
     * @param array<array-key, mixed> $parameters
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<array-key, mixed> at position 2 could not be parsed: Unknown type name 'array-key' at position 2 in array<array-key, mixed>.
Loading history...
47
     *
48
     * @throws InvalidHeaderValueException
49
     *         If the type isn't valid.
50
     *
51
     * @throws InvalidHeaderValueParameterException
52
     *         If the parameters aren't valid.
53
     */
54 16
    public function __construct(string $type, array $parameters = [])
55
    {
56 16
        $this->validateToken($type);
57
58 14
        $parameters = $this->validateParameters($parameters);
59
60 10
        $this->type = $type;
61 10
        $this->parameters = $parameters;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 9
    public function getFieldName(): string
68
    {
69 9
        return 'Content-Disposition';
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 8
    public function getFieldValue(): string
76
    {
77 8
        $v = $this->type;
78 8
        foreach ($this->parameters as $name => $value) {
79 7
            $v .= sprintf('; %s="%s"', $name, $value);
80
        }
81
82 8
        return $v;
83
    }
84
}
85