Passed
Push — master ( ae2bb8...f2edfe )
by Maciej
02:47
created

PurgingConfigProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isPurgeCustomHostEnabled() 0 4 1
A getCustomPurgeHosts() 0 6 1
A getAdditionalHostForHeader() 0 4 1
1
<?php
2
/**
3
 * File: PurgingConfigProvider.php
4
 *
5
 * @author Maciej Sławik <[email protected]>
6
 * @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl)
7
 */
8
9
namespace LizardMedia\VarnishWarmer\Model\Config;
10
11
use LizardMedia\VarnishWarmer\Api\Config\PurgingConfigProviderInterface;
12
use Magento\Framework\App\Config\ScopeConfigInterface;
13
14
/**
15
 * Class PurgingConfigProvider
16
 * @package LizardMedia\VarnishWarmer\Api\Config
17
 */
18
class PurgingConfigProvider implements PurgingConfigProviderInterface
19
{
20
    const XML_PATH_USE_CUSTOM_HOST = 'lm_varnish/purge/different_purge_host';
21
    const XML_PATH_CUSTOM_HOST = 'lm_varnish/purge/custom_host';
22
    const XML_PATH_CUSTOM_HEADER_HOST = 'lm_varnish/purge/header_host';
23
24
    const PURGE_HOSTS_DELIMITER = ',';
25
26
    /**
27
     * @var ScopeConfigInterface
28
     */
29
    protected $scopeConfig;
30
31
    /**
32
     * GeneralConfigProvider constructor.
33
     * @param ScopeConfigInterface $scopeConfig
34
     */
35
    public function __construct(ScopeConfigInterface $scopeConfig)
36
    {
37
        $this->scopeConfig = $scopeConfig;
38
    }
39
40
    /**
41
     * @return bool
42
     */
43
    public function isPurgeCustomHostEnabled(): bool
44
    {
45
        return (bool)$this->scopeConfig->getValue(self::XML_PATH_USE_CUSTOM_HOST);
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public function getCustomPurgeHosts(): array
52
    {
53
        $hostsFieldValue = (string)$this->scopeConfig->getValue(self::XML_PATH_CUSTOM_HOST);
54
        return explode(self::PURGE_HOSTS_DELIMITER, $hostsFieldValue);
55
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getAdditionalHostForHeader(): string
62
    {
63
        return (string)$this->scopeConfig->getValue(self::XML_PATH_CUSTOM_HEADER_HOST);
64
    }
65
}
66