Config::isEnabled()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Copyright © O2TI. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See COPYING.txt for license details.
7
 */
8
9
namespace O2TI\InputMasking\Helper;
10
11
use Magento\Framework\App\Config\ScopeConfigInterface;
12
use Magento\Framework\App\Helper\AbstractHelper;
13
use Magento\Store\Model\ScopeInterface;
14
use Magento\Store\Model\StoreManagerInterface;
15
16
/**
17
 * Class Config - Helper configuration.
18
 */
19
class Config extends AbstractHelper
20
{
21
    public const CONFIG_PATH_GENERAL = 'input_masking/general/%s';
22
23
    public const CONFIG_PATH_ADDRESS_INPUT = 'input_masking/general/address/%s/%s';
24
25
    public const CONFIG_PATH_CUSTOMER_INPUT = 'input_masking/general/customer/%s/%s';
26
27
    /**
28
     * @var ScopeConfigInterface
29
     */
30
    protected $scopeConfig;
31
32
    /**
33
     * @var StoreManagerInterface
34
     */
35
    protected $storeManagerInterface;
36
37
    /**
38
     * @param ScopeConfigInterface  $scopeConfig
39
     * @param StoreManagerInterface $storeManagerInterface
40
     */
41
    public function __construct(
42
        ScopeConfigInterface $scopeConfig,
43
        StoreManagerInterface $storeManagerInterface
44
    ) {
45
        $this->scopeConfig = $scopeConfig;
46
        $this->storeManagerInterface = $storeManagerInterface;
47
    }
48
49
    /**
50
     * Get Configs Module.
51
     *
52
     * @param string $field
53
     *
54
     * @return string
55
     */
56
    public function getConfigModule(string $field): ?string
57
    {
58
        $storeId = $this->storeManagerInterface->getStore()->getId();
59
        $configPath = sprintf(self::CONFIG_PATH_GENERAL, $field);
60
61
        return $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId);
62
    }
63
64
    /**
65
     * Get Config Address Input.
66
     *
67
     * @param string $input
68
     * @param string $field
69
     *
70
     * @return string
71
     */
72
    public function getConfigAddressInput(string $input, string $field): ?string
73
    {
74
        $storeId = $this->storeManagerInterface->getStore()->getId();
75
        $configPath = sprintf(self::CONFIG_PATH_ADDRESS_INPUT, $input, $field);
76
77
        return $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId);
78
    }
79
80
    /**
81
     * Get Config Customer Input.
82
     *
83
     * @param string $input
84
     * @param string $field
85
     *
86
     * @return string
87
     */
88
    public function getConfigCustomerInput(string $input, string $field): ?string
89
    {
90
        $storeId = $this->storeManagerInterface->getStore()->getId();
91
        $configPath = sprintf(self::CONFIG_PATH_CUSTOMER_INPUT, $input, $field);
92
93
        return $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId);
94
    }
95
96
    /**
97
     * Get If is Enabled Module.
98
     *
99
     * @return bool
100
     */
101
    public function isEnabled(): ?bool
102
    {
103
        return $this->getConfigModule('enabled');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getConfigModule('enabled') could return the type string which is incompatible with the type-hinted return boolean|null. Consider adding an additional type-check to rule them out.
Loading history...
104
    }
105
}
106