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 ( 16de70...bb4133 )
by Hilari
04:04
created

PimpleCacheProvider::getCache()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.2
cc 4
eloc 6
nc 3
nop 1
1
<?php
2
3
namespace Cmp\Cache\Infrastructure\Provider;
4
5
use Closure;
6
use Cmp\Cache\Application\CacheFactory;
7
use InvalidArgumentException;
8
use Pimple\Container;
9
use Pimple\ServiceProviderInterface;
10
use Redis;
11
12
/**
13
 * Class PimpleCacheProvider
14
 *
15
 * @package Cmp\Cache\Infrastructure\Provider
16
 */
17
class PimpleCacheProvider implements ServiceProviderInterface
18
{
19
    /**
20
     * Registers cache services on the given container.
21
     *
22
     * @param Container $pimple A container instance
23
     */
24
    public function register(Container $pimple)
25
    {
26
        $pimple['cache.backend'] = 'array';
27
        $pimple['cache.debug']   = false;
28
29
        $pimple['cache'] = function () use ($pimple) {
30
            $cache = $this->getCache($pimple['cache.backend']);
31
32
            if ($pimple['cache.debug']) {
33
                $cache = CacheFactory::decorateForTesting($cache);
34
            }
35
36
            return $cache;
37
        };
38
    }
39
40
    /**
41
     * Gets a cache object based on the backend requested
42
     *
43
     * @param $backend
44
     *
45
     * @return Closure|\Cmp\Cache\Infrastructure\ArrayCache
46
     */
47
    private function getCache($backend)
48
    {
49
        if (is_array($backend) && isset($backend['redis'])) {
50
            return $this->getRedis($backend['redis']);
51
        }
52
53
        if ($backend == 'array') {
54
            return CacheFactory::arrayCache();
55
        }
56
57
        throw new InvalidArgumentException("Invalid cache backend");
58
    }
59
60
    /**
61
     * Return a factory closure to build
62
     *
63
     * @param array|Redis $redis
64
     *
65
     * @return Closure
66
     */
67
    private function getRedis($redis)
68
    {
69
        if ($redis instanceof Redis) {
1 ignored issue
show
Bug introduced by
The class Redis does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
70
            return CacheFactory::redisCache($redis);
71
        }
72
73
        $host    = isset($redis['host']) ? $redis['host'] : '127.0.0.1';
74
        $port    = isset($redis['port']) ? $redis['port'] : 6379;
75
        $db      = isset($redis['db']) ? $redis['db'] : 0;
76
        $timeout = isset($redis['timeout']) ? $redis['timeout'] : 0.0;
77
78
        return CacheFactory::redisFromParams($host, $port, $db, $timeout);
79
    }
80
}
81