CacheManagerFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 24
ccs 0
cts 9
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 14 2
1
<?php
2
3
namespace SvImages\Service\Factory;
4
5
use SvImages\Cache\FlySystemStorage;
6
use SvImages\Cache\StorageInterface;
7
use SvImages\Exception\InvalidArgumentException;
8
use SvImages\Options\ModuleOptions;
9
use SvImages\Service\CacheManager;
10
use Zend\ServiceManager\FactoryInterface;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
13
/**
14
 * @author Vytautas Stankus <[email protected]>
15
 * @license MIT
16
 */
17
class CacheManagerFactory implements FactoryInterface
18
{
19
    /**
20
     * Create service
21
     *
22
     * @param ServiceLocatorInterface $serviceLocator
23
     *
24
     * @return CacheManager
25
     */
26
    public function createService(ServiceLocatorInterface $serviceLocator)
27
    {
28
        /** @var ModuleOptions $options */
29
        $options = $serviceLocator->get(ModuleOptions::class);
30
31
        if (!$serviceLocator->has($options->getCache())) {
32
            throw new InvalidArgumentException('Images cache storage is not set.');
33
        }
34
35
        /** @var StorageInterface $storage */
36
        $storage = $serviceLocator->get($options->getCache());
37
38
        return new CacheManager($storage);
39
    }
40
}
41