Test Failed
Branch 1.0.0 (84f469)
by Zaahid
05:36
created

UUEncodedPart::getContentType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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
/**
10
 * A specialized NonMimePart representing a uuencoded part.
11
 * 
12
 * This represents part of a message that is not a mime message.  A multi-part
13
 * mime message may have a part with a Content-Transfer-Encoding of x-uuencode
14
 * but that would be represented by a normal MimePart.
15
 * 
16
 * UUEncodedPart extends NonMimePart to return a Content-Transfer-Encoding of
17
 * x-uuencode, a Content-Type of application-octet-stream, and a
18
 * Content-Disposition of 'attachment'.  It also expects a mode and filename to
19
 * initialize it, and adds 'filename' parts to the Content-Disposition and
20
 * 'name' to Content-Type.
21
 * 
22
 * @author Zaahid Bateson
23
 */
24
class UUEncodedPart extends NonMimePart
25
{
26
    /**
27
     * @var int the unix file permission
28
     */
29
    protected $mode = null;
30
    
31
    /**
32
     * @var string the name of the file in the uuencoding 'header'.
33
     */
34
    protected $filename = null;
35
    
36
    /**
37
     * Initiates the UUEncodedPart with the passed mode and filename.
38
     * 
39
     * @param string $messageObjectId
40
     * @param PartBuilder $partBuilder
41
     * @param PartStreamFilterManager $partStreamFilterManager
42
     */
43
    public function __construct(
44
        $messageObjectId,
45
        PartBuilder $partBuilder,
46
        PartStreamFilterManager $partStreamFilterManager
47
    ) {
48
        parent::__construct($messageObjectId, $partBuilder, $partStreamFilterManager);
49
        $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...
50
        $this->filename = $partBuilder->getProperty('filename');
51
    }
52
    
53
    /**
54
     * Returns the file mode included in the uuencoded header for this part.
55
     * 
56
     * @return int
57
     */
58
    public function getUnixFileMode()
59
    {
60
        return $this->mode;
61
    }
62
    
63
    /**
64
     * Returns the filename included in the uuencoded header for this part.
65
     * 
66
     * @return string
67
     */
68
    public function getFilename()
69
    {
70
        return $this->filename;
71
    }
72
    
73
    /**
74
     * Returns false.
75
     * 
76
     * @return bool
77
     */
78
    public function isTextPart()
79
    {
80
        return false;
81
    }
82
    
83
    /**
84
     * Returns text/plain
85
     * 
86
     * @return string
87
     */
88
    public function getContentType()
89
    {
90
        return 'application/octet-stream';
91
    }
92
    
93
    /**
94
     * Returns null
95
     * 
96
     * @return string
97
     */
98
    public function getCharset()
99
    {
100
        return null;
101
    }
102
    
103
    /**
104
     * Returns 'inline'.
105
     * 
106
     * @return string
107
     */
108
    public function getContentDisposition()
109
    {
110
        return 'attachment';
111
    }
112
    
113
    /**
114
     * Returns 'x-uuencode'.
115
     * 
116
     * @return string
117
     */
118
    public function getContentTransferEncoding()
119
    {
120
        return 'x-uuencode';
121
    }
122
}
123