Tmp::__destruct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 2
eloc 2
c 2
b 0
f 1
nc 2
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Bavix\Tests;
4
5
class Tmp
6
{
7
8
    /**
9
     * @var string
10
     */
11
    protected $file;
12
13
    /**
14
     * Tmp constructor.
15
     */
16 5
    public function __construct()
17
    {
18 5
        $this->file = tempnam(sys_get_temp_dir(), 'bavix');
19 5
        \touch($this->file);
20
21 5
        register_shutdown_function([$this, '__destruct']);
22 5
    }
23
24 1
    public function __destruct()
25
    {
26 1
        if (file_exists($this->file))
27
        {
28 1
            unlink($this->file);
29
        }
30 1
    }
31
32 5
    public function __toString()
33
    {
34 5
        return (string)$this->file;
35
    }
36
37
}
38