ContentDisposition   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 62
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A getValue() 0 10 1
A newInline() 0 4 1
A newAttachment() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Header;
5
6
use Genkgo\Mail\HeaderInterface;
7
8
final class ContentDisposition implements HeaderInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    private $value;
14
15
    /**
16
     * @var string
17
     */
18
    private $filename;
19
20
    /**
21
     * @param string $value
22
     * @param string $filename
23
     */
24 37
    private function __construct(string $value, string $filename)
25
    {
26 37
        $this->value = $value;
27 37
        $this->filename = $filename;
28 37
    }
29
30
    /**
31
     * @return HeaderName
32
     */
33 37
    public function getName(): HeaderName
34
    {
35 37
        return new HeaderName('Content-Disposition');
36
    }
37
38
    /**
39
     * @return HeaderValue
40
     */
41 12
    public function getValue(): HeaderValue
42
    {
43 12
        return (new HeaderValue($this->value))
44 12
            ->withParameter(
45 12
                new HeaderValueParameter(
46 12
                    'filename',
47 12
                    (string)OptimalEncodedHeaderValue::forPhrase($this->filename)
48
                )
49
            );
50
    }
51
52
    /**
53
     * @param string $filename
54
     * @return ContentDisposition
55
     */
56 13
    public static function newInline(string $filename)
57
    {
58 13
        return new self('inline', $filename);
59
    }
60
61
    /**
62
     * @param string $filename
63
     * @return ContentDisposition
64
     */
65 30
    public static function newAttachment(string $filename)
66
    {
67 30
        return new self('attachment', $filename);
68
    }
69
}
70