Completed
Push — master ( 138942...e63bfe )
by Edson
01:14
created

File   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 78
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 4 1
A create() 0 3 1
A close() 0 3 1
A __construct() 0 3 1
A read() 0 9 1
A open() 0 3 1
A exists() 0 7 2
1
<?php
2
3
namespace Sketch\Tpl;
4
5
/**
6
 * Class File
7
 * @package Sketch\Tpl
8
 */
9
class File
10
{
11
    /**
12
     * @var string
13
     */
14
    private $fname;
15
    /**
16
     * @var
17
     */
18
    private $file;
19
20
    /**
21
     * File constructor.
22
     * @param string|null $fname
23
     */
24 6
    public function __construct(string $fname = null)
25
    {
26 6
        $this->fname = $fname;
27 6
    }
28
29
    /**
30
     * @return bool
31
     */
32 4
    public function exists(): bool
33
    {
34 4
        if (file_exists($this->fname)) {
35 2
            return true;
36
        }
37
38 2
        return false;
39
    }
40
41
    /**
42
     * @return bool|resource
43
     */
44 2
    public function open()
45
    {
46 2
        return $this->file = fopen($this->fname, 'r');
47
    }
48
49
    /**
50
     * @return bool|resource
51
     */
52 4
    public function create()
53
    {
54 4
        return $this->file = fopen($this->fname, 'w+');
55
    }
56
57
    /**
58
     * @param string $content
59
     */
60 2
    public function write(string $content): void
61
    {
62 2
        fwrite($this->file, $content);
63 2
        fseek($this->file, 0);
64 2
    }
65
66
    /**
67
     * @param array $data
68
     * @return string
69
     */
70 2
    public function read(array $data): string
71
    {
72 2
        extract($data);
73
74 2
        ob_start();
75
76 2
        include $this->fname;
77
78 2
        return ob_get_clean();
79
    }
80
81
    /**
82
     *
83
     */
84 2
    public function close(): void
85
    {
86 2
        fclose($this->file);
87 2
    }
88
}
89