FileSystemAdapterFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 14
ccs 8
cts 8
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\Filesystem\FilesystemCachePool;
8
use League\Flysystem\FilesystemInterface;
9
use Psr\Container\ContainerInterface;
10
use WShafer\PSR11PhpCache\Exception\InvalidConfigException;
11
12
class FileSystemAdapterFactory implements FactoryInterface
13
{
14 2
    public function __invoke(ContainerInterface $container, array $options): FilesystemCachePool
15
    {
16 2
        $flySystemServiceName = (string)($options['flySystemService'] ?? '');
17 2
        $folder = (string)($options['folder'] ?? 'cache');
18
19 2
        $flySystem = $container->get($flySystemServiceName);
20
21 2
        if (!$flySystem instanceof FilesystemInterface) {
22 1
            throw new InvalidConfigException(
23 1
                'Service provided for the filesystem must be an instance of ' . FilesystemInterface::class
24
            );
25
        }
26
27 1
        return new FilesystemCachePool($flySystem, $folder);
28
    }
29
}
30