CacheFactory::createService()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 10
cts 10
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 2
1
<?php
2
namespace mxdiModule\Factory\Cache;
3
4
use Zend\Cache\Storage\Adapter\AbstractAdapter;
5
use Zend\Cache\Storage\Plugin\Serializer;
6
use Zend\Cache\Storage\StorageInterface;
7
use Zend\Cache\StorageFactory;
8
use Zend\ServiceManager\FactoryInterface;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
11
class CacheFactory implements FactoryInterface
12
{
13
    /**
14
     * Create service
15
     *
16
     * @param ServiceLocatorInterface $serviceLocator
17
     * @return StorageInterface
18
     */
19 1
    public function createService(ServiceLocatorInterface $serviceLocator)
20
    {
21 1
        $config = $serviceLocator->get('config')['mxdimodule'];
22
23 1
        $cache = StorageFactory::adapterFactory(
24 1
            $config['cache_adapter'],
25 1
            $config['cache_options']
26 1
        );
27
28 1
        if ($cache instanceof AbstractAdapter) {
29 1
            $cache->addPlugin(new Serializer());
30 1
        }
31
32 1
        return $cache;
33
    }
34
}
35