Completed
Push — master ( 74d8c1...00f6f4 )
by Westin
08:22
created

ContainerAwareCacheAbstract   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
__invoke() 0 1 ?
A getContainer() 0 4 1
A setContainer() 0 4 1
A getService() 0 12 3
1
<?php
2
declare(strict_types=1);
3
4
namespace WShafer\PSR11FlySystem\Cache;
5
6
use League\Flysystem\Cached\Storage\Psr6Cache;
7
use Psr\Container\ContainerInterface;
8
use WShafer\PSR11FlySystem\ContainerAwareInterface;
9
use WShafer\PSR11FlySystem\Exception\MissingServiceException;
10
use WShafer\PSR11FlySystem\FactoryInterface;
11
12
abstract class ContainerAwareCacheAbstract implements FactoryInterface, ContainerAwareInterface
13
{
14
    /** @var ContainerInterface */
15
    protected $container;
16
17
    abstract public function __invoke(array $options);
18
19
    public function getContainer(): ContainerInterface
20
    {
21
        return $this->container;
22
    }
23
24
    public function setContainer(ContainerInterface $container)
25
    {
26
        $this->container = $container;
27
    }
28
29
    public function getService($serviceName)
30
    {
31
        if (empty($serviceName)
32
            || !$this->getContainer()->has($serviceName)
33
        ) {
34
            throw new MissingServiceException(
35
                'Unable to locate service '.$serviceName
36
            );
37
        }
38
39
        return $this->getContainer()->get($serviceName);
40
    }
41
}
42