Total Complexity | 8 |
Total Lines | 78 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
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 |
|
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 |
|
87 | 2 | } |
|
88 | } |
||
89 |