Test Failed
Push — master ( 20befe...72a3ae )
by Julien
11:57
created

ServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 11
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 10
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 15 2
1
<?php
2
/**
3
 * This file is part of the Zemit Framework.
4
 *
5
 * (c) Zemit Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE.txt
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Zemit\Provider\Cache;
12
13
use Phalcon\Cache;
14
use Phalcon\Cache\AdapterFactory;
15
use Phalcon\Storage\SerializerFactory;
16
use Zemit\Provider\AbstractServiceProvider;
17
18
/**
19
 * Class ServiceProvider
20
 *
21
 * @author Julien Turbide <[email protected]>
22
 * @copyright Zemit Team <[email protected]>
23
 *
24
 * @since 1.0
25
 * @version 1.0
26
 *
27
 * @package Zemit\Provider\ModelsCache
28
 */
29
class ServiceProvider extends AbstractServiceProvider
30
{
31
    /**
32
     * The Service name.
33
     * @var string
34
     */
35
    protected $serviceName = 'cache';
36
    
37
    /**
38
     * {@inheritdoc}
39
     *
40
     * @return void
41
     */
42
    public function register(\Phalcon\Di\DiInterface $di): void
43
    {
44
        $di->setShared($this->getName(), function() use ($di) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
45
            
46
            $config = $di->get('config')->cache;
47
            $driverName = $di->get('bootstrap')->getMode() === 'console'? 'cli' : 'driver';
48
            $driver = $config->drivers->{$config->$driverName};
49
            
50
            $options = array_merge($config->default->toArray(), $driver->toArray());
51
            
52
            $serializerFactory = new SerializerFactory();
53
            $adapterFactory = new AdapterFactory($serializerFactory);
54
            $adapter = $adapterFactory->newInstance($config->$driverName, $options);
55
    
56
            return new Cache($adapter);
57
        });
58
    }
59
}
60