UUEncodedPart::getContentDisposition()   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
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of the ZBateson\MailMimeParser project.
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php BSD
6
 */
7
8
namespace ZBateson\MailMimeParser\Message;
9
10
use Psr\Log\LoggerInterface;
11
use ZBateson\MailMimeParser\MailMimeParser;
12
13
/**
14
 * Implementation of a non-mime message's uuencoded attachment part.
15
 *
16
 * @author Zaahid Bateson
17
 */
18
class UUEncodedPart extends NonMimePart implements IUUEncodedPart
19
{
20
    /**
21
     * @var int the unix file permission
22
     */
23
    protected ?int $mode = null;
24
25
    /**
26
     * @var string the name of the file in the uuencoding 'header'.
27
     */
28
    protected ?string $filename = null;
29
30 9
    public function __construct(
31
        ?int $mode = null,
32
        ?string $filename = null,
33
        ?IMimePart $parent = null,
34
        ?LoggerInterface $logger = null,
35
        ?PartStreamContainer $streamContainer = null
36
    ) {
37 9
        $di = MailMimeParser::getGlobalContainer();
38 9
        parent::__construct(
39 9
            $logger ?? $di->get(LoggerInterface::class),
40 9
            $streamContainer ?? $di->get(PartStreamContainer::class),
41 9
            $parent
42 9
        );
43 9
        $this->mode = $mode;
44 9
        $this->filename = $filename;
45
    }
46
47
    /**
48
     * Returns the filename included in the uuencoded 'begin' line for this
49
     * part.
50
     */
51 4
    public function getFilename() : ?string
52
    {
53 4
        return $this->filename;
54
    }
55
56 1
    public function setFilename(string $filename) : static
57
    {
58 1
        $this->filename = $filename;
59 1
        $this->notify();
60 1
        return $this;
61
    }
62
63
    /**
64
     * Returns false.
65
     *
66
     * Although the part may be plain text, there is no reliable way of
67
     * determining its type since uuencoded 'begin' lines only include a file
68
     * name and no mime type.  The file name's extension may be a hint.
69
     *
70
     * @return false
71
     */
72 3
    public function isTextPart() : bool
73
    {
74 3
        return false;
75
    }
76
77
    /**
78
     * Returns 'application/octet-stream'.
79
     */
80 4
    public function getContentType(string $default = 'application/octet-stream') : ?string
81
    {
82 4
        return 'application/octet-stream';
83
    }
84
85
    /**
86
     * Returns null
87
     */
88 4
    public function getCharset() : ?string
89
    {
90 4
        return null;
91
    }
92
93
    /**
94
     * Returns 'attachment'.
95
     */
96 4
    public function getContentDisposition(?string $default = 'attachment') : ?string
97
    {
98 4
        return 'attachment';
99
    }
100
101
    /**
102
     * Returns 'x-uuencode'.
103
     */
104 3
    public function getContentTransferEncoding(?string $default = 'x-uuencode') : ?string
105
    {
106 3
        return 'x-uuencode';
107
    }
108
109 1
    public function getUnixFileMode() : ?int
110
    {
111 1
        return $this->mode;
112
    }
113
114 1
    public function setUnixFileMode(int $mode) : static
115
    {
116 1
        $this->mode = $mode;
117 1
        $this->notify();
118 1
        return $this;
119
    }
120
}
121