Swift_EmbeddedFile::fromPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 4
cp 0
crap 2
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
 * An embedded file, in a multipart message.
13
 *
14
 * @author Chris Corbyn
15
 */
16 View Code Duplication
class Swift_EmbeddedFile extends Swift_Mime_EmbeddedFile
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 EmbeddedFile.
20
     *
21
     * Details may be optionally provided to the constructor.
22
     *
23
     * @param string|Swift_OutputByteStream $data
24
     * @param string                        $filename
25
     * @param string                        $contentType
26
     */
27 19
    public function __construct($data = null, $filename = null, $contentType = null)
28
    {
29 19
        call_user_func_array(
30 19
            array($this, 'Swift_Mime_EmbeddedFile::__construct'),
31 19
            Swift_DependencyContainer::getInstance()->createDependenciesFor('mime.embeddedfile')
32 19
        );
33
34 19
        $this->setBody($data);
35 19
        $this->setFilename($filename);
36
37 19
        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...
38 3
            $this->setContentType($contentType);
39 3
        }
40 19
    }
41
42
    /**
43
     * Create a new EmbeddedFile.
44
     *
45
     * @param string|Swift_OutputByteStream $data
46
     * @param string                        $filename
47
     * @param string                        $contentType
48
     *
49
     * @return Swift_Mime_EmbeddedFile
50
     */
51
    public static function newInstance($data = null, $filename = null, $contentType = null)
52
    {
53
        return new self($data, $filename, $contentType);
54
    }
55
56
    /**
57
     * Create a new EmbeddedFile from a filesystem path.
58
     *
59
     * @param string $path
60
     *
61
     * @return Swift_Mime_EmbeddedFile
62
     */
63
    public static function fromPath($path)
64
    {
65
        return self::newInstance()->setFile(
66
            new Swift_ByteStream_FileByteStream($path)
67
        );
68
    }
69
}
70