Completed
Push — master ( e045b6...635827 )
by
unknown
16:24
created

ExtensionConfiguration   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 62
ccs 15
cts 15
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isDebug() 0 4 1
A getHosts() 0 10 3
A getDefaultTimeout() 0 4 1
A getBanTimeout() 0 4 1
A get() 0 4 1
1
<?php
2
namespace Aoe\Varnish\TYPO3\Configuration;
3
4
use TYPO3\CMS\Core\SingletonInterface;
5
6
class ExtensionConfiguration implements SingletonInterface
7
{
8
    /**
9
     * @var array
10
     */
11
    private $configuration;
12
13 4
    /**
14
     * ExtensionConfiguration constructor.
15 4
     */
16 4
    public function __construct()
17
    {
18
        $this->configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['varnish']);
19
    }
20
21 2
    /**
22
     * @return boolean
23 2
     */
24
    public function isDebug()
25
    {
26
        return (boolean)$this->get('debug');
27
    }
28
29 2
    /**
30
     * @return array
31 2
     */
32 2
    public function getHosts()
33 2
    {
34 2
        $hosts = explode(',', $this->get('hosts'));
35 2
        array_walk($hosts, function (&$value) {
36 2
            if (false === strpos($value, 'https://') && false === strpos($value, 'http://')) {
37 2
                $value = 'http://' . $value;
38
            }
39
        });
40
        return $hosts;
41
    }
42
43
    /**
44 4
     * @return integer
45
     */
46 4
    public function getDefaultTimeout()
47
    {
48
        return (int)$this->get('default_timeout');
49
    }
50
51
    /**
52
     * @return integer
53
     */
54
    public function getBanTimeout()
55
    {
56
        return (int)$this->get('ban_timeout');
57
    }
58
59
    /**
60
     * @param string $key
61
     * @return string
62
     */
63
    private function get($key)
64
    {
65
        return $this->configuration[$key];
66
    }
67
}
68