Completed
Pull Request — master (#400)
by Alejandro
06:15 queued 49s
created

CacheFactory::resolveCacheAdapter()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6.0702

Importance

Changes 0
Metric Value
cc 6
eloc 13
nc 6
nop 1
dl 0
loc 15
ccs 7
cts 8
cp 0.875
crap 6.0702
rs 9.2222
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Common\Factory;
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 2
        $appOptions = $container->get(AppOptions::class);
18 2
        $adapter = env('APP_ENV', 'pro') === 'pro' ? new Cache\ApcuCache() : new Cache\ArrayCache();
19 2
        $adapter->setNamespace((string) $appOptions);
20
21 2
        return $adapter;
22
    }
23
}
24