Passed
Pull Request — master (#213)
by
unknown
03:11
created

UUEncodedPart::setUnixFileMode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
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 ZBateson\MailMimeParser\MailMimeParser;
11
12
/**
13
 * Implementation of a non-mime message's uuencoded attachment part.
14
 *
15
 * @author Zaahid Bateson
16
 */
17
class UUEncodedPart extends NonMimePart implements IUUEncodedPart
18
{
19
    /**
20
     * @var int the unix file permission
21
     */
22
    protected $mode = null;
23
24
    /**
25
     * @var string the name of the file in the uuencoding 'header'.
26
     */
27
    protected $filename = null;
28
29 10
    public function __construct(?int $mode = null, ?string $filename = null, ?IMimePart $parent = null, ?PartStreamContainer $streamContainer = null)
30
    {
31 10
        if ($streamContainer === null) {
32
            $di = MailMimeParser::getDependencyContainer();
33
            $streamContainer = $di[\ZBateson\MailMimeParser\Message\PartStreamContainer::class];
34
            $streamFactory = $di[\ZBateson\MailMimeParser\Stream\StreamFactory::class];
35
            $streamContainer->setStream($streamFactory->newMessagePartStream($this));
36
        }
37 10
        parent::__construct(
38 10
            $streamContainer,
39 10
            $parent
40 10
        );
41 10
        $this->mode = $mode;
42 10
        $this->filename = $filename;
43
    }
44
45
    /**
46
     * Returns the filename included in the uuencoded 'begin' line for this
47
     * part.
48
     *
49
     * @return string
50
     */
51 4
    public function getFilename() : ?string
52
    {
53 4
        return $this->filename;
54
    }
55
56 1
    public function setFilename(string $filename) : self
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
     * @return string
81
     */
82 4
    public function getContentType(string $default = 'application/octet-stream') : ?string
83
    {
84 4
        return 'application/octet-stream';
85
    }
86
87
    /**
88
     * Returns null
89
     */
90 4
    public function getCharset() : ?string
91
    {
92 4
        return null;
93
    }
94
95
    /**
96
     * Returns 'attachment'.
97
     */
98 4
    public function getContentDisposition(?string $default = 'attachment') : ?string
99
    {
100 4
        return 'attachment';
101
    }
102
103
    /**
104
     * Returns 'x-uuencode'.
105
     */
106 3
    public function getContentTransferEncoding(?string $default = 'x-uuencode') : ?string
107
    {
108 3
        return 'x-uuencode';
109
    }
110
111 1
    public function getUnixFileMode() : ?int
112
    {
113 1
        return $this->mode;
114
    }
115
116 1
    public function setUnixFileMode(int $mode) : self
117
    {
118 1
        $this->mode = $mode;
119 1
        $this->notify();
120 1
        return $this;
121
    }
122
}
123