Failed Conditions
Pull Request — master (#10)
by Maximo
03:05
created

CacheDataProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 32
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 27 1
1
<?php
0 ignored issues
show
Coding Style introduced by
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
2
3
namespace Gewaer\Providers;
4
5
use function Gewaer\Core\envValue;
6
use Phalcon\Cache\Backend\Libmemcached;
7
use Phalcon\Cache\Frontend\Data;
8
use Phalcon\Di\ServiceProviderInterface;
9
use Phalcon\DiInterface;
10
11
class CacheDataProvider implements ServiceProviderInterface
12
{
13
    /**
14
     * @param DiInterface $container
15
     */
16 6
    public function register(DiInterface $container)
17
    {
18 6
        $container->setShared(
19 6
            'cache',
20
            function () {
21 2
                $prefix = 'data';
22 2
                $frontAdapter = Data::class;
23
                $frontOptions = [
24 2
                    'lifetime' => envValue('CACHE_LIFETIME', 86400),
25
                ];
26
                $backOptions = [
27 2
                    'servers' => [
28
                        0 => [
29 2
                            'host' => envValue('DATA_API_MEMCACHED_HOST', '127.0.0.1'),
30 2
                            'port' => envValue('DATA_API_MEMCACHED_PORT', 11211),
31 2
                            'weight' => envValue('DATA_API_MEMCACHED_WEIGHT', 100),
32
                        ],
33
                    ],
34
                    'client' => [
35
                        \Memcached::OPT_HASH => \Memcached::HASH_MD5,
36
                        \Memcached::OPT_PREFIX_KEY => 'api-',
37
                    ],
38 2
                    'lifetime' => 3600,
39 2
                    'prefix' => $prefix . '-',
40
                ];
41
42 2
                return new Libmemcached(new $frontAdapter($frontOptions), $backOptions);
43 6
            }
44
        );
45 6
    }
46
}
47