Passed
Push — master ( 3849b2...6d2bbe )
by Edson
01:17
created

File   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
eloc 16
dl 0
loc 49
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 4 1
A close() 0 3 1
A exists() 0 7 2
A __construct() 0 3 1
A open() 0 3 1
A read() 0 9 1
A create() 0 3 1
1
<?php
2
3
namespace Bonfim\Tpl;
4
5
class File
6
{
7
    private $fname;
8
    private $file;
9
10
    public function __construct(string $fname = null)
11
    {
12
        $this->fname = $fname;
13
    }
14
15
    public function exists(): bool
16
    {
17
        if (file_exists($this->fname)) {
18
            return true;
19
        }
20
21
        return false;
22
    }
23
24
    public function open()
25
    {
26
        return $this->file = fopen($this->fname, 'r');
27
    }
28
29
    public function create()
30
    {
31
        return $this->file = fopen($this->fname, 'w+');
32
    }
33
34
    public function write(string $content): void
35
    {
36
        fwrite($this->file, $content);
37
        fseek($this->file, 0);
38
    }
39
40
    public function read(array $data): string
41
    {
42
        extract($data);
43
44
        ob_start();
45
46
        include $this->fname;
47
48
        return ob_get_clean();
49
    }
50
51
    public function close(): void
52
    {
53
        fclose($this->file);
54
    }
55
}
56