TempFile   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 4
c 3
b 0
f 2
lcom 1
cbo 1
dl 0
loc 34
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A doNotDestroy() 0 4 1
A __destruct() 0 8 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
}