TempFile::__destruct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4286
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
/*
3
 * This file is part of badcow-common.
4
 *
5
 * (c) Samuel Williams <[email protected]>
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
namespace Badcow\Common;
12
13
class TempFile extends File
14
{
15
    private $doNotDestroy = false;
16
17
    /**
18
     * @param string $prefix
19
     */
20 9
    public function __construct($prefix = '')
21
    {
22 9
        parent::__construct(tempnam(sys_get_temp_dir(), $prefix));
23 9
    }
24
25
    /**
26
     * Do not destroy the file on exit.
27
     * 
28
     * @param bool $val
29
     */
30 3
    public function doNotDestroy($val = true)
31
    {
32 3
        $this->doNotDestroy = (bool) $val;
33 3
    }
34
35
    /**
36
     * The destructor
37
     */
38 9
    public function __destruct()
39
    {
40 9
        if ($this->doNotDestroy) {
41 3
            return;
42
        }
43
        
44 6
        $this->delete();
45
    }
46
}