Passed
Push — master ( d775ca...750957 )
by Volodymyr
04:15 queued 10s
created

Config   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isMinifyBodyScript() 0 8 1
A getDisableAttribute() 0 8 1
A getExcludeControllers() 0 8 1
A getExcludePaths() 0 8 1
A isEnabled() 0 8 1
1
<?php
2
/**
3
 * Copyright (c) 2019. Volodymyr Hryvinskyi.  All rights reserved.
4
 * @author: <mailto:[email protected]>
5
 * @github: <https://github.com/hryvinskyi>
6
 */
7
8
declare(strict_types=1);
9
10
namespace Hryvinskyi\DeferJs\Helper;
11
12
use Magento\Framework\App\Helper\AbstractHelper;
13
use Magento\Store\Model\ScopeInterface;
14
15
/**
16
 * Class Config
17
 */
18
class Config extends AbstractHelper
19
{
20
    /**
21
     * Configuration paths
22
     */
23
    const XML_HRYVINSKYI_DEFER_JS_GENERAL_ENABLED = 'hryvinskyi_defer_js/general/enabled';
24
    const XML_HRYVINSKYI_DEFER_JS_DISABLE_ATTRIBUTE = 'hryvinskyi_defer_js/general/disable_attribute';
25
    const XML_HRYVINSKYI_DEFER_JS_MINIFY_BODY_SCRIPTS = 'hryvinskyi_defer_js/general/minify_body_scripts';
26
    const XML_HRYVINSKYI_DEFER_JS_EXCLUDE_CONTROLLERS = 'hryvinskyi_defer_js/general/exclude_controllers';
27
    const XML_HRYVINSKYI_DEFER_JS_EXCLUDE_PATHS = 'hryvinskyi_defer_js/general/exclude_paths';
28
29
    /**
30
     * @param string $scopeType
31
     * @param null|string $scopeCode
32
     *
33
     * @return bool
34
     */
35
    public function isEnabled(
36
        string $scopeType = ScopeInterface::SCOPE_WEBSITE,
37
        $scopeCode = null
38
    ): bool {
39
        return $this->scopeConfig->isSetFlag(
40
            self::XML_HRYVINSKYI_DEFER_JS_GENERAL_ENABLED,
41
            $scopeType,
42
            $scopeCode
43
        );
44
    }
45
46
    /**
47
     * @param string $scopeType
48
     * @param null|string $scopeCode
49
     *
50
     * @return string
51
     */
52
    public function getDisableAttribute(
53
        string $scopeType = ScopeInterface::SCOPE_WEBSITE,
54
        $scopeCode = null
55
    ): string {
56
        return $this->scopeConfig->getValue(
57
            self::XML_HRYVINSKYI_DEFER_JS_DISABLE_ATTRIBUTE,
58
            $scopeType,
59
            $scopeCode
60
        );
61
    }
62
63
    /**
64
     * @param string $scopeType
65
     * @param null|string $scopeCode
66
     *
67
     * @return bool
68
     */
69
    public function isMinifyBodyScript(
70
        string $scopeType = ScopeInterface::SCOPE_WEBSITE,
71
        $scopeCode = null
72
    ): bool {
73
        return $this->scopeConfig->isSetFlag(
74
            self::XML_HRYVINSKYI_DEFER_JS_MINIFY_BODY_SCRIPTS,
75
            $scopeType,
76
            $scopeCode
77
        );
78
    }
79
80
    /**
81
     * Return Excluded Controllers
82
     *
83
     * @param string $scopeType
84
     * @param null|string $scopeCode
85
     *
86
     * @return string
87
     */
88
    public function getExcludeControllers(
89
        string $scopeType = ScopeInterface::SCOPE_WEBSITE,
90
        $scopeCode = null
91
    ): string {
92
        return $this->scopeConfig->getValue(
93
            self::XML_HRYVINSKYI_DEFER_JS_EXCLUDE_CONTROLLERS,
94
            $scopeType,
95
            $scopeCode
96
        );
97
    }
98
99
    /**
100
     * Return Excluded Paths
101
     *
102
     * @param string $scopeType
103
     * @param null|string $scopeCode
104
     *
105
     * @return string
106
     */
107
    public function getExcludePaths(
108
        string $scopeType = ScopeInterface::SCOPE_WEBSITE,
109
        $scopeCode = null
110
    ): string {
111
        return $this->scopeConfig->getValue(
112
            self::XML_HRYVINSKYI_DEFER_JS_EXCLUDE_PATHS,
113
            $scopeType,
114
            $scopeCode
115
        );
116
    }
117
}
118