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 — update-dep ( 101307...f9b6c2 )
by
unknown
02:01
created

CacheManager   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 2
dl 0
loc 93
ccs 36
cts 38
cp 0.9474
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCachePath() 0 4 1
A isCachingEnabled() 0 8 2
A cacheExists() 0 12 4
A getCacheUrl() 0 13 3
A createCache() 0 8 2
A deleteCache() 0 7 2
1
<?php
2
namespace HtImgModule\Service;
3
4
use HtImgModule\Options\CacheOptionsInterface;
5
use Imagine\Image\ImageInterface;
6
7
class CacheManager implements CacheManagerInterface
8
{
9
    /**
10
     * @var CacheOptionsInterface
11
     */
12
    protected $cacheOptions;
13
14
    /**
15
     * Constructor
16
     *
17
     * @param CacheOptionsInterface $cacheOptions
18
     */
19 2
    public function __construct(CacheOptionsInterface $cacheOptions)
20
    {
21 2
        $this->cacheOptions = $cacheOptions;
22 2
    }
23
24
    /**
25
     * {@inheritDoc}
26
     */
27 1
    public function cacheExists($relativeName, $filter, $formatOrImage = null)
28
    {
29 1
        $cachePath = $this->getCachePath($relativeName, $filter, $formatOrImage);
30 1
        if (is_file($cachePath) && is_readable($cachePath)) {
31 1
            if ((time() - filemtime($cachePath)) < $this->cacheOptions->getCacheExpiry()) {
32 1
                return true;
33
            }
34
            unlink($cachePath);
35
        }
36
37 1
        return false;
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43 1
    public function getCacheUrl($relativeName, $filter, $formatOrImage = null)
44
    {
45 1
        if (is_readable($formatOrImage)) {
46 1
            $format = pathinfo($formatOrImage, PATHINFO_EXTENSION);
47 1
        } else {
48 1
            $format = $formatOrImage;
49
        }
50 1
        if (!$format) {
51 1
             return $this->cacheOptions->getCachePath() . '/' . $filter . '/'. $relativeName;
52
        } else {
53 1
            return $this->getCacheUrl($relativeName, $filter) . '.' . $format;
54
        }
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60 1
    public function getCachePath($relativeName, $filter, $formatOrImage = null)
61
    {
62 1
        return $this->cacheOptions->getWebRoot() . '/' . $this->getCacheUrl($relativeName, $filter, $formatOrImage);
63
    }
64
65
    /**
66
     * {@inheritDoc}
67
     */
68 1
    public function createCache($relativeName, $filter, ImageInterface $image, $formatOrImage = null, array $saveOptions = [])
69
    {
70 1
        $cachePath = $this->getCachePath($relativeName, $filter, $formatOrImage);
71 1
        if (!is_dir(dirname($cachePath))) {
72 1
            mkdir(dirname($cachePath), 0755, true);
73 1
        }
74 1
        $image->save($cachePath, $saveOptions);
75 1
    }
76
77
    /**
78
     * {@inheritDoc}
79
     */
80 1
    public function deleteCache($relativeName, $filter, $formatOrImage = null)
81
    {
82 1
        $cachePath = $this->getCachePath($relativeName, $filter, $formatOrImage);
83 1
        if (is_readable($cachePath)) {
84 1
            unlink($cachePath);
85 1
        }
86 1
    }
87
88
    /**
89
     * {@inheritDoc}
90
     */
91 1
    public function isCachingEnabled($filter, array $filterOptions)
92
    {
93 1
        if (isset($filterOptions['enable_cache'])) {
94 1
            return (bool) $filterOptions['enable_cache'];
95
        }
96
97 1
        return $this->cacheOptions->getEnableCache();
98
    }
99
}
100