DoctrineCacheAdapterFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
rs 10
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