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.

CacheManager   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 73.68%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 8
c 4
b 0
f 2
lcom 1
cbo 0
dl 0
loc 56
ccs 14
cts 19
cp 0.7368
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 3
    public function generateCache($changelogFile, $cacheFile, $content) {
31 3
        file_put_contents($this->generateCachePath($changelogFile, $cacheFile), $content);
32 3
    }
33
    
34
    /**
35
     * @param string $changelogFile
36
     * @param string $cacheFile
37
     * @return mixed
38
     */
39 4
    public function getCache($changelogFile, $cacheFile) {
40 4
        $path = $this->generateCachePath($changelogFile, $cacheFile);
41 4
        if (!is_file($path) || ($generationTime = filemtime($path)) === false || $generationTime < (time() - $this->cacheTime)) {
42 3
            clearstatcache(true, $path);
43 3
            return false;
44
        }
45 1
        $content = file_get_contents($path);
46 1
        clearstatcache(true, $path);
47 1
        return $content;
48
    }
49
    
50
    /**
51
     * @param string $changelogFile
52
     * @param string $cacheFile
53
     * @return string
54
     */
55 5
    private function generateCachePath($changelogFile, $cacheFile) {
56 5
        $changelogSignature = str_replace([':', ' ', '/', '\\'], '-', strtolower(basename(dirname($changelogFile)) . '-' . basename($changelogFile, '.md')));
57
        
58 5
        return realpath(__DIR__ . "/../../data/cache"). '/' . $changelogSignature . "-$cacheFile.cache";
59
    }
60
}