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

File::write()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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
    /**
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