Completed
Push — master ( af18ae...2b759d )
by Carlos
26:26 queued 12:07
created

Cache::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the overtrue/phplint.
5
 *
6
 * (c) 2016 overtrue <[email protected]>
7
 */
8
9
namespace Overtrue\PHPLint;
10
11
/**
12
 * Class Cache.
13
 */
14
class Cache
15
{
16
    /**
17
     * @var string
18
     */
19
    protected static $filename = '.phplint-cache';
20
21
    /**
22
     * Fetch cache.
23
     *
24
     * @return mixed
25
     */
26
    public static function get()
27
    {
28
        $content = file_get_contents(self::getFilename());
29
30
        return $content ? json_decode($content, true) : null;
31
    }
32
33
    /**
34
     * Check cache exists.
35
     *
36
     * @return bool
37
     */
38
    public static function exists()
39
    {
40
        return file_exists(self::getFilename());
41
    }
42
43
    /**
44
     * Alias if exists();.
45
     *
46
     * @return bool
47
     */
48
    public static function isCached()
49
    {
50
        return self::exists();
51
    }
52
53
    /**
54
     * Set cache.
55
     *
56
     * @param mixed $contents
57
     */
58
    public static function put($contents)
59
    {
60
        return file_put_contents(self::getFilename(), json_encode($contents));
61
    }
62
63
    /**
64
     * Return cache filename.
65
     *
66
     * @return string
67
     */
68
    public static function getFilename()
69
    {
70
        return (getcwd() ?: './').self::$filename;
71
    }
72
}
73