Driver_Changelog   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 114
rs 10
c 0
b 0
f 0
wmc 11
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A file() 0 18 3
B change() 0 24 3
B _update() 0 41 5
1
<?php
2
3
/**
4
 * Provides XML file handling for changelog schemas
5
 *
6
 * PHP Version 5
7
 *
8
 * @category  Core
9
 * @package   XML
10
 * @author    Hans-Joachim Piepereit <[email protected]>
11
 * @copyright 2013 cSphere Team
12
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
13
 * @link      http://www.csphere.eu
14
 **/
15
16
namespace csphere\core\xml;
17
18
/**
19
 * Provides XML file handling for changelog schemas
20
 *
21
 * @category  Core
22
 * @package   XML
23
 * @author    Hans-Joachim Piepereit <[email protected]>
24
 * @copyright 2013 cSphere Team
25
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
26
 * @link      http://www.csphere.eu
27
 **/
28
29
class Driver_Changelog extends Base
30
{
31
    /**
32
     * Determine the driver specific source file
33
     *
34
     * @param string $type Type of target, e.g. plugin
35
     * @param string $name Directory name of the target
36
     * @param string $lang Language if more than one is possible
37
     *
38
     * @return string
39
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
40
41
    protected function file($type, $name, $lang)
42
    {
43
        unset($lang);
44
45
        $file = '';
46
47
        // Changelog file can be part of a theme or plugin
48
        if ($type == 'plugin') {
49
50
            $file = 'csphere/plugins/' . $name . '/changelog.xml';
51
52
        } elseif ($type == 'theme') {
53
54
            $file = 'csphere/themes/' . $name . '/changelog.xml';
55
        }
56
57
        return $file;
58
    }
59
60
    /**
61
     * Change data array for easier usage
62
     *
63
     * @param array $array Formated array generated earlier
64
     *
65
     * @return array
66
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
67
68
    protected function change(array $array)
69
    {
70
        // Shorten array depth for simple elements
71
        $array['history'] = $array['history'][0];
72
73
        if (isset($array['updates'])) {
74
75
            // Shorten array depth for array elements
76
            $array['updates'] = $array['updates'][0]['update'];
77
78
            // Shorten updates as good as possible
79
            $updates_c = count($array['updates']);
80
81
            for ($i = 0; $i < $updates_c; $i++) {
82
83
                $array['updates'][$i] = $this->_update($array['updates'][$i]);
84
            }
85
        }
86
87
        // Move attr content to main array
88
        $array['updates'] = $this->loopattr($array['updates']);
89
90
        return $array;
91
    }
92
93
    /**
94
     * Change data updates sub-array for easier usage
95
     *
96
     * @param array $update One update out of the data array
97
     *
98
     * @return array
99
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
100
101
    private function _update(array $update)
102
    {
103
        // Shorten info and instructions
104
        $update['information']  = $update['information'][0]['value'];
105
        $update['instructions'] = $update['instructions'][0]['value'];
106
107
        // Shorten optional data: added, reworked, fixed, removed
108
        if (isset($update['added'][0]['item'])) {
109
110
            $update['added'] = $update['added'][0]['item'];
111
        } else {
112
113
            $update['added'] = [];
114
        }
115
116
        if (isset($update['reworked'][0]['item'])) {
117
118
            $update['reworked'] = $update['reworked'][0]['item'];
119
        } else {
120
121
            $update['reworked'] = [];
122
        }
123
124
        if (isset($update['fixed'][0]['item'])) {
125
126
            $update['fixed'] = $update['fixed'][0]['item'];
127
        } else {
128
129
            $update['fixed'] = [];
130
        }
131
132
        if (isset($update['removed'][0]['item'])) {
133
134
            $update['removed'] = $update['removed'][0]['item'];
135
        } else {
136
137
            $update['removed'] = [];
138
        }
139
140
        return $update;
141
    }
142
}
143