DoctrineCacheAdapterFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 32
ccs 6
cts 6
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A __invoke() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WShafer\PSR11PhpCache\Adapter;
6
7
use Cache\Adapter\Doctrine\DoctrineCachePool;
8
use Doctrine\Common\Cache\Cache;
9
use Psr\Container\ContainerInterface;
10
use WShafer\PSR11PhpCache\Exception\InvalidConfigException;
11
use WShafer\PSR11PhpCache\Exception\MissingLibraryException;
12
13
class DoctrineCacheAdapterFactory implements FactoryInterface
14
{
15
    /**
16
     * MemcachedAdapterFactory constructor.
17
     *
18
     * @codeCoverageIgnore
19
     */
20
    public function __construct()
21
    {
22
        if (!interface_exists(Cache::class)) {
23
            throw new MissingLibraryException(
24
                'Doctrine Cache is not installed.'
25
            );
26
        }
27
    }
28
29
    /**
30
     * @param ContainerInterface $container
31
     * @param array              $options
32
     *
33
     * @return DoctrineCachePool
34
     */
35 2
    public function __invoke(ContainerInterface $container, array $options): DoctrineCachePool
36
    {
37 2
        if (empty($options['service'])) {
38 1
            throw new InvalidConfigException(
39 1
                'You must provide a doctrine cache service name to use'
40
            );
41
        }
42
43 1
        $cache = $container->get($options['service']);
44 1
        return new DoctrineCachePool($cache);
45
    }
46
}
47