Passed
Push — master ( b647e5...e2d0b4 )
by Edson
01:29
created

File   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
dl 0
loc 54
ccs 16
cts 22
cp 0.7272
rs 10
c 0
b 0
f 0
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A open() 0 3 1
A write() 0 4 1
A read() 0 9 1
A exists() 0 6 2
A create() 0 3 1
A close() 0 3 1
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
    /**
16
     * @return bool
17
     */
18
    public function exists(): bool
19
    {
20
        if (file_exists($this->fname))
21
            return true;
22
23
        return false;
24
    }
25
26
    /**
27
     * @return bool|resource
28
     */
29
    public function open()
30
    {
31
        return $this->file = fopen($this->fname, 'r');
32
    }
33
34 2
    public function create()
35
    {
36 2
        return $this->file = fopen($this->fname, 'w+');
37
    }
38
39 2
    public function write(string $content): void
40
    {
41 2
        fwrite($this->file, $content);
42 2
        fseek($this->file, 0);
43 2
    }
44
45 2
    public function read(array $data): string
46
    {
47 2
        extract($data);
48
49 2
        ob_start();
50
51 2
        include $this->fname;
52
53 2
        return ob_get_clean();
54
    }
55
56 2
    public function close(): void
57
    {
58 2
        fclose($this->file);
59 2
    }
60
}
61