Xml   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 96
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getXmlContent() 0 4 1
A writeToXml() 0 7 2
A writeNode() 0 4 1
A writeConfigNode() 0 5 1
1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2016 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Model\Export;
28
29
/**
30
 * Generator class for the config export
31
 *
32
 * @category  Payone
33
 * @package   Payone_Magento2_Plugin
34
 * @author    FATCHIP GmbH <[email protected]>
35
 * @copyright 2003 - 2016 Payone GmbH
36
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
37
 * @link      http://www.payone.de
38
 */
39
class Xml
40
{
41
    /**
42
     * String where the config export xml is written into
43
     *
44
     * @var string
45
     */
46
    protected $sXmlContent = '';
47
48
    /**
49
     * Tab content
50
     *
51
     * @var string
52
     */
53
    protected $sTab = "    ";
54
55
    /**
56
     * Line end sign
57
     *
58
     * @var string
59
     */
60
    protected $sLineEnd = "\n";
61
62
    /**
63
     * PAYONE shop helper
64
     *
65
     * @var \Payone\Core\Helper\Shop
66
     */
67
    protected $shopHelper;
68
69
    /**
70
     * Constructor
71
     *
72
     * @param \Payone\Core\Helper\Shop $shopHelper
73
     */
74
    public function __construct(\Payone\Core\Helper\Shop $shopHelper)
75
    {
76
        $this->shopHelper = $shopHelper;
77
    }
78
79
    /**
80
     * Return xml content property
81
     *
82
     * @return string
83
     */
84
    protected function getXmlContent()
85
    {
86
        return rtrim($this->sXmlContent, $this->sLineEnd);
87
    }
88
89
    /**
90
     * Add content to the xml content property
91
     *
92
     * @param  string $sContent
93
     * @param  int    $iTabCount
94
     * @return void
95
     */
96
    protected function writeToXml($sContent, $iTabCount = 0)
97
    {
98
        for ($i = 0; $i < $iTabCount; $i++) {
99
            $sContent = $this->sTab.$sContent;
100
        }
101
        $this->sXmlContent .= $sContent.$this->sLineEnd;
102
    }
103
104
    /**
105
     * Write xml node to xml
106
     *
107
     * @param  string $sNode
108
     * @param  string $sContent
109
     * @param  int    $iTabCount
110
     * @return void
111
     */
112
    protected function writeNode($sNode, $sContent, $iTabCount = 0)
113
    {
114
        $this->writeToXml("<{$sNode}>$sContent</{$sNode}>", $iTabCount);
115
    }
116
117
    /**
118
     * Helper method to get parameter from the config
119
     * divided by the config path elements
120
     *
121
     * @param  string $sNode
122
     * @param  int    $iTabCount
123
     * @param  string $sStoreCode
124
     * @param  string $sKey
125
     * @param  string $sGroup
126
     * @param  string $sSection
127
     * @return void
128
     */
129
    protected function writeConfigNode($sNode, $iTabCount, $sStoreCode, $sKey, $sGroup = 'global', $sSection = 'payone_general')
130
    {
131
        $sContent = $this->shopHelper->getConfigParam($sKey, $sGroup, $sSection, $sStoreCode);
132
        $this->writeNode($sNode, $sContent, $iTabCount);
133
    }
134
}
135