TempFile   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 27
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A __destruct() 0 6 2
1
<?php
2
3
namespace TreeHouse\Feeder\Resource;
4
5
/**
6
 * Provides a temporary file to work with.
7
 */
8
final class TempFile extends \SplFileObject
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $fileName;
14
15
    /**
16
     * @param string|null $filename Leave empty to generate a tmp name
17
     */
18 114
    public function __construct($filename = null)
19
    {
20 114
        $this->fileName = $filename ?: tempnam(sys_get_temp_dir(), 'feeder');
21
22 114
        parent::__construct($this->fileName, 'a+');
23 114
    }
24
25
    /**
26
     * Clean up when done.
27
     */
28 84
    public function __destruct()
29
    {
30 84
        if (file_exists($this->fileName)) {
31 84
            unlink($this->fileName);
32 84
        }
33 84
    }
34
}
35