PurgingConfigProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

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