ChainCacheAdapterFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 20 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WShafer\PSR11PhpCache\Adapter;
6
7
use Cache\Adapter\Chain\CachePoolChain;
8
use Psr\Container\ContainerInterface;
9
use WShafer\PSR11PhpCache\Exception\InvalidConfigException;
10
11
class ChainCacheAdapterFactory implements FactoryInterface
12
{
13
    /**
14
     * @param ContainerInterface $container
15
     * @param array              $options
16
     * @return CachePoolChain
17
     */
18 2
    public function __invoke(ContainerInterface $container, array $options): CachePoolChain
19
    {
20
        if (
21 2
            empty($options['services'])
22 2
            || !is_array($options['services'])
23
        ) {
24 1
            throw new InvalidConfigException(
25 1
                'You must provide an array of preconfigured cache services to use for the chain'
26
            );
27
        }
28
29 1
        $skipOnFailure = $options['skipOnFailure'] ?? false;
30
31 1
        $pools = [];
32
33 1
        foreach ($options['services'] as $service) {
34 1
            $pools[] = $container->get($service);
35
        }
36
37 1
        return new CachePoolChain($pools, ['skip_on_failure' => $skipOnFailure]);
38
    }
39
}
40