Completed
Pull Request — master (#23)
by Kuba
01:38
created

Cache::setFilename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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