Completed
Push — master ( 02d26c...304629 )
by Walter
03:17
created

StorageFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B createService() 0 29 5
1
<?php
2
3
namespace PhpAbModule\Service;
4
5
use PhpAb\Engine\Engine;
6
use PhpAb\Storage\Cookie;
7
use PhpAb\Storage\Runtime;
8
use PhpAb\Storage\Session;
9
use RuntimeException;
10
use Zend\ServiceManager\FactoryInterface;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
13
class StorageFactory implements FactoryInterface
14
{
15
    public function createService(ServiceLocatorInterface $serviceLocator)
16
    {
17
        $config = $serviceLocator->get('Config');
18
19
        if (array_key_exists('storage_options', $config['phpab'])) {
20
            $options = $config['phpab']['storage_options'];
21
        } else {
22
            $options = [];
23
        }
24
25
        switch ($config['phpab']['storage']) {
26
            case 'cookie':
27
                $storage = new Cookie($options['name'], $options['ttl']);
28
                break;
29
30
            case 'runtime':
31
                $storage = new Runtime();
32
                break;
33
34
            case 'session':
35
                $storage = new Session($options['name']);
36
                break;
37
38
            default:
39
                throw new RuntimeException('Invalid storage provider set: ' . $config['phpab']['storage']);
40
        }
41
42
        return $storage;
43
    }
44
}
45