Passed
Pull Request — master (#444)
by Alejandro
08:10
created

CacheFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 4
c 0
b 0
f 0
dl 0
loc 11
rs 10
ccs 5
cts 5
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 9 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Common\Cache;
5
6
use Doctrine\Common\Cache;
7
use Interop\Container\ContainerInterface;
8
use Shlinkio\Shlink\Core\Options\AppOptions;
9
use Zend\ServiceManager\Factory\FactoryInterface;
10
11
use function Shlinkio\Shlink\Common\env;
12
13
class CacheFactory implements FactoryInterface
14
{
15 2
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): Cache\Cache
16
    {
17
        // TODO Make use of the redis cache via RedisFactory when possible
18
19 2
        $appOptions = $container->get(AppOptions::class);
20 2
        $adapter = env('APP_ENV', 'pro') === 'pro' ? new Cache\ApcuCache() : new Cache\ArrayCache();
21 2
        $adapter->setNamespace((string) $appOptions);
22
23 2
        return $adapter;
24
    }
25
}
26