Completed
Pull Request — master (#17)
by Thijs
04:30
created

FsStorage::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.032
1
<?php
2
3
namespace lucidtaz\yii2scssphp\storage;
4
5
use RuntimeException;
6
7
class FsStorage implements Storage
8
{
9 2
    public function exists(string $filename): bool
10
    {
11 2
        return file_exists($filename);
12
    }
13
14 2
    public function get(string $filename): string
15
    {
16 2
        $contents = file_get_contents($filename);
17 2
        if ($contents === false) {
18
            throw new RuntimeException('Could not read ' . $filename);
19
        }
20 2
        return $contents;
21
    }
22
23 3
    public function put(string $filename, string $contents): bool
24
    {
25 3
        return file_put_contents($filename, $contents) !== false;
26
    }
27
28 2
    public function remove(string $filename): bool
29
    {
30 2
        return @unlink($filename);
31
    }
32
33 1
    public function touch(string $filename, int $mtime): bool
34
    {
35 1
        return touch($filename, $mtime);
36
    }
37
38 2
    public function getMtime(string $filename): int
39
    {
40 2
        $mtime = @filemtime($filename);
41 2
        if ($mtime === false) {
42 1
            throw new RuntimeException('Could not determine mtime for ' . $filename);
43
            // ... or should we adhere to PHP's int|false convention?
44
        }
45 1
        return $mtime;
46
    }
47
}
48