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::cacheExists()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.25

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 8
cp 0.75
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 3
nop 3
crap 4.25
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