Swift_MimePart::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 16
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 4
nop 3
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
ccs 16
cts 16
cp 1
crap 3
1
<?php
2
3
/*
4
 * This file is part of SwiftMailer.
5
 * (c) 2004-2009 Chris Corbyn
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
/**
12
 * A MIME part, in a multipart message.
13
 *
14
 * @author Chris Corbyn
15
 */
16 View Code Duplication
class Swift_MimePart extends Swift_Mime_MimePart
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
17
{
18
    /**
19
     * Create a new MimePart.
20
     *
21
     * Details may be optionally passed into the constructor.
22
     *
23
     * @param string $body
24
     * @param string $contentType
25
     * @param string $charset
26
     */
27 37
    public function __construct($body = null, $contentType = null, $charset = null)
28
    {
29 37
        call_user_func_array(
30 37
            array($this, 'Swift_Mime_MimePart::__construct'),
31 37
            Swift_DependencyContainer::getInstance()
32 37
                ->createDependenciesFor('mime.part')
33 37
            );
34
35 37
        if (!isset($charset)) {
36 36
            $charset = Swift_DependencyContainer::getInstance()
37 36
                ->lookup('properties.charset');
38 36
        }
39 37
        $this->setBody($body);
40 37
        $this->setCharset($charset);
41 37
        if ($contentType) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $contentType of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
42 4
            $this->setContentType($contentType);
43 4
        }
44 37
    }
45
46
    /**
47
     * Create a new MimePart.
48
     *
49
     * @param string $body
50
     * @param string $contentType
51
     * @param string $charset
52
     *
53
     * @return self
54
     */
55 4
    public static function newInstance($body = null, $contentType = null, $charset = null)
56
    {
57 4
        return new self($body, $contentType, $charset);
58
    }
59
}
60