Passed
Push — 1.0.0 ( d49389...cbb558 )
by Zaahid
03:21
created

UUEncodedPart::setFilename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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
namespace ZBateson\MailMimeParser\Message\Part;
8
9
use Psr\Http\Message\StreamInterface;
10
use ZBateson\MailMimeParser\Stream\StreamFactory;
11
12
/**
13
 * A specialized NonMimePart representing a uuencoded part.
14
 * 
15
 * This represents part of a message that is not a mime message.  A multi-part
16
 * mime message may have a part with a Content-Transfer-Encoding of x-uuencode
17
 * but that would be represented by a normal MimePart.
18
 * 
19
 * UUEncodedPart extends NonMimePart to return a Content-Transfer-Encoding of
20
 * x-uuencode, a Content-Type of application-octet-stream, and a
21
 * Content-Disposition of 'attachment'.  It also expects a mode and filename to
22
 * initialize it, and adds 'filename' parts to the Content-Disposition and
23
 * 'name' to Content-Type.
24
 * 
25
 * @author Zaahid Bateson
26
 */
27
class UUEncodedPart extends NonMimePart
28
{
29
    /**
30
     * @var int the unix file permission
31
     */
32
    protected $mode = null;
33
    
34
    /**
35
     * @var string the name of the file in the uuencoding 'header'.
36
     */
37
    protected $filename = null;
38
    
39
    /**
40
     * @param PartStreamFilterManager $partStreamFilterManager
41
     * @param StreamFactory $streamFactory
42
     * @param PartBuilder $partBuilder
43
     * @param StreamInterface $stream
44
     * @param StreamInterface $contentStream
45
     */
46 1
    public function __construct(
47
        PartStreamFilterManager $partStreamFilterManager,
48
        StreamFactory $streamFactory,
49
        PartBuilder $partBuilder,
50
        StreamInterface $stream = null,
51
        StreamInterface $contentStream = null
52
    ) {
53 1
        parent::__construct($partStreamFilterManager, $streamFactory, $stream, $contentStream);
54 1
        $this->mode = $partBuilder->getProperty('mode');
0 ignored issues
show
Documentation Bug introduced by
It seems like $partBuilder->getProperty('mode') can also be of type string. However, the property $mode is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
55 1
        $this->filename = $partBuilder->getProperty('filename');
56 1
    }
57
    
58
    /**
59
     * Returns the file mode included in the uuencoded header for this part.
60
     * 
61
     * @return int
62
     */
63 1
    public function getUnixFileMode()
64
    {
65 1
        return $this->mode;
66
    }
67
    
68
    /**
69
     * Returns the filename included in the uuencoded header for this part.
70
     * 
71
     * @return string
72
     */
73 1
    public function getFilename()
74
    {
75 1
        return $this->filename;
76
    }
77
78
    /**
79
     * Sets the unix file mode for the uuencoded header.
80
     *
81
     * @param int $mode
82
     */
83
    public function setUnixFileMode($mode)
84
    {
85
        $this->mode = $mode;
86
        $this->onChange();
87
    }
88
89
    /**
90
     * Sets the filename included in the uuencoded header.
91
     *
92
     * @param string $filename
93
     */
94
    public function setFilename($filename)
95
    {
96
        $this->filename = $filename;
97
        $this->onChange();
98
    }
99
    
100
    /**
101
     * Returns false.
102
     * 
103
     * @return bool
104
     */
105 1
    public function isTextPart()
106
    {
107 1
        return false;
108
    }
109
    
110
    /**
111
     * Returns text/plain
112
     * 
113
     * @return string
114
     */
115 1
    public function getContentType()
116
    {
117 1
        return 'application/octet-stream';
118
    }
119
    
120
    /**
121
     * Returns null
122
     * 
123
     * @return string
124
     */
125
    public function getCharset()
126
    {
127
        return null;
128
    }
129
    
130
    /**
131
     * Returns 'inline'.
132
     * 
133
     * @return string
134
     */
135 1
    public function getContentDisposition()
136
    {
137 1
        return 'attachment';
138
    }
139
    
140
    /**
141
     * Returns 'x-uuencode'.
142
     * 
143
     * @return string
144
     */
145 1
    public function getContentTransferEncoding()
146
    {
147 1
        return 'x-uuencode';
148
    }
149
}
150