Completed
Push — master ( d12d51...b647e5 )
by Edson
01:35
created

File::exists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Sketch\Tpl;
4
5
class File
6
{
7
    private $fname;
8
    private $file;
9
10 2
    public function __construct(string $fname = null)
11
    {
12 2
        $this->fname = $fname;
13 2
    }
14
15 2
    /**
16
     * @return bool
17
     */
18 2
    public function exists(): bool
19
    {
20 2
        if (file_exists($this->fname))
21 2
            return true;
22 2
23
        return false;
24 2
    }
25
26 2
    /**
27
     * @return bool|resource
28 2
     */
29
    public function open()
30 2
    {
31
        return $this->file = fopen($this->fname, 'r');
32 2
    }
33
34
    public function create()
35 2
    {
36
        return $this->file = fopen($this->fname, 'w+');
37 2
    }
38 2
39
    public function write(string $content): void
40
    {
41
        fwrite($this->file, $content);
42
        fseek($this->file, 0);
43
    }
44
45
    public function read(array $data): string
46
    {
47
        extract($data);
48
49
        ob_start();
50
51
        include $this->fname;
52
53
        return ob_get_clean();
54
    }
55
56
    public function close(): void
57
    {
58
        fclose($this->file);
59
    }
60
}
61