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   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 57.89%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 8
c 3
b 0
f 2
lcom 1
cbo 0
dl 0
loc 56
ccs 11
cts 19
cp 0.5789
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setCacheTime() 0 3 1
A getCacheTime() 0 3 1
A generateCache() 0 3 1
A getCache() 0 10 4
A generateCachePath() 0 5 1
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
}