AdaptorCacheFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 7
dl 0
loc 34
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 24 3
1
<?php
2
declare(strict_types=1);
3
4
namespace WShafer\PSR11FlySystem\Cache;
5
6
use League\Flysystem\Cached\Storage\Adapter;
7
use WShafer\PSR11FlySystem\Exception\MissingConfigException;
8
use WShafer\PSR11FlySystem\Exception\MissingServiceException;
9
use WShafer\PSR11FlySystem\FlySystemFactory;
10
use WShafer\PSR11FlySystem\FlySystemManager;
11
12
class AdaptorCacheFactory extends ContainerAwareCacheAbstract
13
{
14
    /**
15
     * @param array $options
16
     *
17
     * @return Adapter
18
     *
19
     * @SuppressWarnings(PHPMD.StaticAccess)
20
     */
21 3
    public function __invoke(array $options)
22
    {
23 3
        if (empty($options['adaptor'])) {
24 1
            throw new MissingConfigException(
25 1
                'Unable to locate cache file adaptor in config'
26
            );
27
        }
28
29 2
        $adaptor = $options['adaptor'];
30 2
        $fileName = $options['fileName'] ?? 'file_cache';
31 2
        $ttl = $options['ttl'] ?? null;
32
33
        /** @var FlySystemManager $manager */
34 2
        $manager = FlySystemFactory::getFlySystemManager($this->getContainer());
35 2
        $adaptorManager = $manager->getAdaptorManager();
36
37 2
        if (!$adaptorManager->has($adaptor)) {
38 1
            throw new MissingServiceException(
39 1
                'Unable to locate file system: '.$adaptor
40
            );
41
        }
42
43 1
        return new Adapter($adaptorManager->get($adaptor), $fileName, $ttl);
44
    }
45
}
46