GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 5ee131...02dba5 )
by Axel
03:06
created

CacheManager::getCacheTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace ChangelogParser\Manager;
4
5
class CacheManager {
6
    /** @var int **/
7
    protected $cacheTime = 3600;
8
    
9
    /**
10
     * Time in seconds
11
     * 
12
     * @param int $cacheTime
13
     */
14
    public function setCacheTime($cacheTime) {
15
        $this->cacheTime = $cacheTime;
16
    }
17
    
18
    /**
19
     * @return int
20
     */
21
    public function getCacheTime() {
22
        return $this->cacheTime;
23
    }
24
    
25
    /**
26
     * @param string $changelogFile
27
     * @param string $cacheFile
28
     * @param string $content
29
     */
30 2
    public function generateCache($changelogFile, $cacheFile, $content) {
31 2
        file_put_contents($this->generateCachePath($changelogFile, $cacheFile), $content);
32 2
    }
33
    
34
    /**
35
     * @param string $changelogFile
36
     * @param string $cacheFile
37
     * @return mixed
38
     */
39 2
    public function getCache($changelogFile, $cacheFile) {
40 2
        $path = $this->generateCachePath($changelogFile, $cacheFile);
41 2
        if(!is_file($path) || ($generationTime = filemtime($path)) === false || $generationTime < (time() - $this->cacheTime)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
42 2
            clearstatcache(true, $path);
43 2
            return false;
44
        }
45
        $content = file_get_contents($path);
46
        clearstatcache(true, $path);
47
        return $content;
48
    }
49
    
50
    /**
51
     * @param string $changelogFile
52
     * @param string $cacheFile
53
     * @return string
54
     */
55 2
    public function generateCachePath($changelogFile, $cacheFile) {
56 2
        $changelogSignature = str_replace([':', ' ', '/', '\\'], '-', strtolower(basename(dirname($changelogFile)) . '-' . basename($changelogFile, 'md')));
57
        
58 2
        return realpath(__DIR__ . "/../../data/cache"). '/' . $changelogSignature . "-$cacheFile.cache";
59
    }
60
}