Completed
Pull Request — master (#2)
by
unknown
15:16
created

ExtensionConfiguration::getBanTimeout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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
    /**
14
     * ExtensionConfiguration constructor.
15
     */
16 6
    public function __construct()
17
    {
18 6
        $this->configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['varnish']);
19 6
    }
20
21
    /**
22
     * @return boolean
23
     */
24 2
    public function isDebug()
25
    {
26 2
        return (boolean)$this->get('debug');
27
    }
28
29
    /**
30
     * @return array
31
     */
32 2
    public function getHosts()
33
    {
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 2
            }
39 2
        });
40 2
        return $hosts;
41
    }
42
43
    /**
44
     * @return integer
45
     */
46 1
    public function getDefaultTimeout()
47
    {
48 1
        return (int)$this->get('default_timeout');
49
    }
50
51
    /**
52
     * @return integer
53
     */
54 1
    public function getBanTimeout()
55
    {
56 1
        return (int)$this->get('ban_timeout');
57
    }
58
59
    /**
60
     * @param string $key
61
     * @return string
62
     */
63 6
    private function get($key)
64
    {
65 6
        return $this->configuration[$key];
66
    }
67
}
68