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

FsStorage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 41
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A exists() 0 4 1
A put() 0 4 1
A remove() 0 4 1
A touch() 0 4 1
A get() 0 8 2
A getMtime() 0 9 2
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