Factory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 5
Bugs 2 Features 1
Metric Value
wmc 2
c 5
b 2
f 1
lcom 0
cbo 3
dl 0
loc 42
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 32 2
1
<?php
2
3
/**
4
 * Factory class for Cerberus.
5
 *
6
 * @author  Leandro Silva <[email protected]>
7
 * @license https://github.com/mt-olympus/cerberus/blob/master/LICENSE MIT Licence
8
 */
9
namespace Cerberus;
10
11
use Interop\Container\ContainerInterface;
12
use Zend\Cache\StorageFactory;
13
14
/**
15
 * Factory class for Cerberus.
16
 *
17
 * @author  Leandro Silva <[email protected]>
18
 * @license https://github.com/mt-olympus/cerberus/blob/master/LICENSE MIT Licence
19
 */
20
class Factory
21
{
22
    /**
23
     * Invoke method.
24
     *
25
     * @param \Interop\Container\ContainerInterface $container
26
     *
27
     * @return \Cerberus\Cerberus
28
     */
29
    public function __invoke(ContainerInterface $container)
30
    {
31
        $config = $container->get('config');
32
        if (!isset($config['cerberus'])) {
33
            $storageConfig = [
34
                'adapter' => [
35
                    'name' => 'filesystem',
36
                    'options' => [
37
                        'cache_dir' => 'data/cache',
38
                        'namespace' => 'cerberus',
39
                    ],
40
                ],
41
                'plugins' => [
42
                    // Don't throw exceptions on cache errors
43
                    'exception_handler' => [
44
                        'throw_exceptions' => false,
45
                    ],
46
                    'Serializer',
47
                ],
48
            ];
49
            $maxFailure = 5;
50
            $timeout = 60;
51
        } else {
52
            $storageConfig = $config['cerberus']['storage'];
53
            $maxFailure = (int) $config['cerberus']['max_failure'];
54
            $timeout = (int) $config['cerberus']['timeout'];
55
        }
56
57
        $storage = StorageFactory::factory($storageConfig);
58
59
        return new Cerberus($storage, $maxFailure, $timeout);
60
    }
61
}
62