Completed
Push — 5.x ( e82a2b...3cd537 )
by Lars
04:29
created

__destruct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4286
cc 2
eloc 3
nc 2
nop 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
 * @author Romain-Geissler
13
 */
14
class Swift_ByteStream_TemporaryFileByteStream extends Swift_ByteStream_FileByteStream
0 ignored issues
show
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...
15
{
16 8
    public function __construct()
17
    {
18 8
        $filePath = tempnam(sys_get_temp_dir(), 'FileByteStream');
19
20 8
        if ($filePath === false) {
21
            throw new Swift_IoException('Failed to retrieve temporary file name.');
22
        }
23
24 8
        parent::__construct($filePath, true);
25 8
    }
26
27 8
    public function getContent()
28
    {
29 8
        if (($content = file_get_contents($this->getPath())) === false) {
30
            throw new Swift_IoException('Failed to get temporary file content.');
31
        }
32
33 8
        return $content;
34
    }
35
36 8
    public function __destruct()
37
    {
38 8
        if (file_exists($this->getPath())) {
39 8
            @unlink($this->getPath());
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
40
        }
41 8
    }
42
}
43