Total Complexity | 7 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
15 | class File |
||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $path; |
||
21 | |||
22 | /** |
||
23 | * File constructor. |
||
24 | * |
||
25 | * @param string $path |
||
26 | * @throws FileDoesNotExist |
||
27 | */ |
||
28 | 16 | public function __construct(string $path) |
|
32 | 14 | } |
|
33 | |||
34 | /** |
||
35 | * @return bool |
||
36 | * @throws FileDoesNotExist |
||
37 | */ |
||
38 | 16 | private function pathExists(): bool |
|
39 | { |
||
40 | 16 | if (!file_exists($this->path)) { |
|
41 | 4 | throw new FileDoesNotExist(ErrorMessages::FILE_DOES_NOT_EXIST); |
|
42 | } |
||
43 | 14 | return true; |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return string |
||
48 | * @throws EmptyFile |
||
49 | * @throws FileCouldNotBeOpenedException |
||
50 | */ |
||
51 | 14 | public function getContents(): string |
|
52 | { |
||
53 | 14 | $contents = file_get_contents($this->path); |
|
54 | |||
55 | 14 | if ($contents === false) { |
|
56 | 2 | throw new FileCouldNotBeOpenedException(ErrorMessages::FILE_COULD_NOT_BE_OPENED); |
|
57 | } |
||
58 | |||
59 | 12 | if ($contents === '') { |
|
60 | 2 | throw new EmptyFile(ErrorMessages::EMPTY_FILE); |
|
61 | } |
||
62 | |||
63 | 10 | return $contents; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * @return string |
||
68 | */ |
||
69 | 4 | public function getPath(): string |
|
72 | } |
||
73 | } |
||
74 |