TempFile::doNotDestroy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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
}