Completed
Push — master ( 3dc31e...e27817 )
by Morris
46:06 queued 20:49
created
lib/private/App/InfoParser.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -33,233 +33,233 @@
 block discarded – undo
33 33
 use OCP\ICache;
34 34
 
35 35
 class InfoParser {
36
-	/** @var \OCP\ICache|null */
37
-	private $cache;
36
+    /** @var \OCP\ICache|null */
37
+    private $cache;
38 38
 
39
-	/**
40
-	 * @param ICache|null $cache
41
-	 */
42
-	public function __construct(ICache $cache = null) {
43
-		$this->cache = $cache;
44
-	}
39
+    /**
40
+     * @param ICache|null $cache
41
+     */
42
+    public function __construct(ICache $cache = null) {
43
+        $this->cache = $cache;
44
+    }
45 45
 
46
-	/**
47
-	 * @param string $file the xml file to be loaded
48
-	 * @return null|array where null is an indicator for an error
49
-	 */
50
-	public function parse($file) {
51
-		if (!file_exists($file)) {
52
-			return null;
53
-		}
46
+    /**
47
+     * @param string $file the xml file to be loaded
48
+     * @return null|array where null is an indicator for an error
49
+     */
50
+    public function parse($file) {
51
+        if (!file_exists($file)) {
52
+            return null;
53
+        }
54 54
 
55
-		if(!is_null($this->cache)) {
56
-			$fileCacheKey = $file . filemtime($file);
57
-			if ($cachedValue = $this->cache->get($fileCacheKey)) {
58
-				return json_decode($cachedValue, true);
59
-			}
60
-		}
55
+        if(!is_null($this->cache)) {
56
+            $fileCacheKey = $file . filemtime($file);
57
+            if ($cachedValue = $this->cache->get($fileCacheKey)) {
58
+                return json_decode($cachedValue, true);
59
+            }
60
+        }
61 61
 
62
-		libxml_use_internal_errors(true);
63
-		$loadEntities = libxml_disable_entity_loader(false);
64
-		$xml = simplexml_load_file($file);
62
+        libxml_use_internal_errors(true);
63
+        $loadEntities = libxml_disable_entity_loader(false);
64
+        $xml = simplexml_load_file($file);
65 65
 
66
-		libxml_disable_entity_loader($loadEntities);
67
-		if ($xml === false) {
68
-			libxml_clear_errors();
69
-			return null;
70
-		}
71
-		$array = $this->xmlToArray($xml);
66
+        libxml_disable_entity_loader($loadEntities);
67
+        if ($xml === false) {
68
+            libxml_clear_errors();
69
+            return null;
70
+        }
71
+        $array = $this->xmlToArray($xml);
72 72
 
73
-		if (is_null($array)) {
74
-			return null;
75
-		}
73
+        if (is_null($array)) {
74
+            return null;
75
+        }
76 76
 
77
-		if (!array_key_exists('info', $array)) {
78
-			$array['info'] = [];
79
-		}
80
-		if (!array_key_exists('remote', $array)) {
81
-			$array['remote'] = [];
82
-		}
83
-		if (!array_key_exists('public', $array)) {
84
-			$array['public'] = [];
85
-		}
86
-		if (!array_key_exists('types', $array)) {
87
-			$array['types'] = [];
88
-		}
89
-		if (!array_key_exists('repair-steps', $array)) {
90
-			$array['repair-steps'] = [];
91
-		}
92
-		if (!array_key_exists('install', $array['repair-steps'])) {
93
-			$array['repair-steps']['install'] = [];
94
-		}
95
-		if (!array_key_exists('pre-migration', $array['repair-steps'])) {
96
-			$array['repair-steps']['pre-migration'] = [];
97
-		}
98
-		if (!array_key_exists('post-migration', $array['repair-steps'])) {
99
-			$array['repair-steps']['post-migration'] = [];
100
-		}
101
-		if (!array_key_exists('live-migration', $array['repair-steps'])) {
102
-			$array['repair-steps']['live-migration'] = [];
103
-		}
104
-		if (!array_key_exists('uninstall', $array['repair-steps'])) {
105
-			$array['repair-steps']['uninstall'] = [];
106
-		}
107
-		if (!array_key_exists('background-jobs', $array)) {
108
-			$array['background-jobs'] = [];
109
-		}
110
-		if (!array_key_exists('two-factor-providers', $array)) {
111
-			$array['two-factor-providers'] = [];
112
-		}
113
-		if (!array_key_exists('commands', $array)) {
114
-			$array['commands'] = [];
115
-		}
116
-		if (!array_key_exists('activity', $array)) {
117
-			$array['activity'] = [];
118
-		}
119
-		if (!array_key_exists('filters', $array['activity'])) {
120
-			$array['activity']['filters'] = [];
121
-		}
122
-		if (!array_key_exists('settings', $array['activity'])) {
123
-			$array['activity']['settings'] = [];
124
-		}
125
-		if (!array_key_exists('providers', $array['activity'])) {
126
-			$array['activity']['providers'] = [];
127
-		}
128
-		if (!array_key_exists('settings', $array)) {
129
-			$array['settings'] = [];
130
-		}
131
-		if (!array_key_exists('admin', $array['settings'])) {
132
-			$array['settings']['admin'] = [];
133
-		}
134
-		if (!array_key_exists('admin-section', $array['settings'])) {
135
-			$array['settings']['admin-section'] = [];
136
-		}
137
-		if (!array_key_exists('personal', $array['settings'])) {
138
-			$array['settings']['personal'] = [];
139
-		}
140
-		if (!array_key_exists('personal-section', $array['settings'])) {
141
-			$array['settings']['personal-section'] = [];
142
-		}
77
+        if (!array_key_exists('info', $array)) {
78
+            $array['info'] = [];
79
+        }
80
+        if (!array_key_exists('remote', $array)) {
81
+            $array['remote'] = [];
82
+        }
83
+        if (!array_key_exists('public', $array)) {
84
+            $array['public'] = [];
85
+        }
86
+        if (!array_key_exists('types', $array)) {
87
+            $array['types'] = [];
88
+        }
89
+        if (!array_key_exists('repair-steps', $array)) {
90
+            $array['repair-steps'] = [];
91
+        }
92
+        if (!array_key_exists('install', $array['repair-steps'])) {
93
+            $array['repair-steps']['install'] = [];
94
+        }
95
+        if (!array_key_exists('pre-migration', $array['repair-steps'])) {
96
+            $array['repair-steps']['pre-migration'] = [];
97
+        }
98
+        if (!array_key_exists('post-migration', $array['repair-steps'])) {
99
+            $array['repair-steps']['post-migration'] = [];
100
+        }
101
+        if (!array_key_exists('live-migration', $array['repair-steps'])) {
102
+            $array['repair-steps']['live-migration'] = [];
103
+        }
104
+        if (!array_key_exists('uninstall', $array['repair-steps'])) {
105
+            $array['repair-steps']['uninstall'] = [];
106
+        }
107
+        if (!array_key_exists('background-jobs', $array)) {
108
+            $array['background-jobs'] = [];
109
+        }
110
+        if (!array_key_exists('two-factor-providers', $array)) {
111
+            $array['two-factor-providers'] = [];
112
+        }
113
+        if (!array_key_exists('commands', $array)) {
114
+            $array['commands'] = [];
115
+        }
116
+        if (!array_key_exists('activity', $array)) {
117
+            $array['activity'] = [];
118
+        }
119
+        if (!array_key_exists('filters', $array['activity'])) {
120
+            $array['activity']['filters'] = [];
121
+        }
122
+        if (!array_key_exists('settings', $array['activity'])) {
123
+            $array['activity']['settings'] = [];
124
+        }
125
+        if (!array_key_exists('providers', $array['activity'])) {
126
+            $array['activity']['providers'] = [];
127
+        }
128
+        if (!array_key_exists('settings', $array)) {
129
+            $array['settings'] = [];
130
+        }
131
+        if (!array_key_exists('admin', $array['settings'])) {
132
+            $array['settings']['admin'] = [];
133
+        }
134
+        if (!array_key_exists('admin-section', $array['settings'])) {
135
+            $array['settings']['admin-section'] = [];
136
+        }
137
+        if (!array_key_exists('personal', $array['settings'])) {
138
+            $array['settings']['personal'] = [];
139
+        }
140
+        if (!array_key_exists('personal-section', $array['settings'])) {
141
+            $array['settings']['personal-section'] = [];
142
+        }
143 143
 
144
-		if (array_key_exists('types', $array)) {
145
-			if (is_array($array['types'])) {
146
-				foreach ($array['types'] as $type => $v) {
147
-					unset($array['types'][$type]);
148
-					if (is_string($type)) {
149
-						$array['types'][] = $type;
150
-					}
151
-				}
152
-			} else {
153
-				$array['types'] = [];
154
-			}
155
-		}
156
-		if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) {
157
-			$array['repair-steps']['install'] = $array['repair-steps']['install']['step'];
158
-		}
159
-		if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) {
160
-			$array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step'];
161
-		}
162
-		if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) {
163
-			$array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step'];
164
-		}
165
-		if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) {
166
-			$array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step'];
167
-		}
168
-		if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) {
169
-			$array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step'];
170
-		}
171
-		if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) {
172
-			$array['background-jobs'] = $array['background-jobs']['job'];
173
-		}
174
-		if (isset($array['commands']['command']) && is_array($array['commands']['command'])) {
175
-			$array['commands'] = $array['commands']['command'];
176
-		}
177
-		if (isset($array['two-factor-providers']['provider']) && is_array($array['two-factor-providers']['provider'])) {
178
-			$array['two-factor-providers'] = $array['two-factor-providers']['provider'];
179
-		}
180
-		if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) {
181
-			$array['activity']['filters'] = $array['activity']['filters']['filter'];
182
-		}
183
-		if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) {
184
-			$array['activity']['settings'] = $array['activity']['settings']['setting'];
185
-		}
186
-		if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) {
187
-			$array['activity']['providers'] = $array['activity']['providers']['provider'];
188
-		}
189
-		if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])
190
-			&& is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])
191
-			&& !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class'])
192
-		) {
193
-			$array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin'];
194
-		}
195
-		if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) {
196
-			$array['settings']['admin'] = [$array['settings']['admin']];
197
-		}
198
-		if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) {
199
-			$array['settings']['admin-section'] = [$array['settings']['admin-section']];
200
-		}
201
-		if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) {
202
-			$array['settings']['personal'] = [$array['settings']['personal']];
203
-		}
204
-		if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) {
205
-			$array['settings']['personal-section'] = [$array['settings']['personal-section']];
206
-		}
144
+        if (array_key_exists('types', $array)) {
145
+            if (is_array($array['types'])) {
146
+                foreach ($array['types'] as $type => $v) {
147
+                    unset($array['types'][$type]);
148
+                    if (is_string($type)) {
149
+                        $array['types'][] = $type;
150
+                    }
151
+                }
152
+            } else {
153
+                $array['types'] = [];
154
+            }
155
+        }
156
+        if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) {
157
+            $array['repair-steps']['install'] = $array['repair-steps']['install']['step'];
158
+        }
159
+        if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) {
160
+            $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step'];
161
+        }
162
+        if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) {
163
+            $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step'];
164
+        }
165
+        if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) {
166
+            $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step'];
167
+        }
168
+        if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) {
169
+            $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step'];
170
+        }
171
+        if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) {
172
+            $array['background-jobs'] = $array['background-jobs']['job'];
173
+        }
174
+        if (isset($array['commands']['command']) && is_array($array['commands']['command'])) {
175
+            $array['commands'] = $array['commands']['command'];
176
+        }
177
+        if (isset($array['two-factor-providers']['provider']) && is_array($array['two-factor-providers']['provider'])) {
178
+            $array['two-factor-providers'] = $array['two-factor-providers']['provider'];
179
+        }
180
+        if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) {
181
+            $array['activity']['filters'] = $array['activity']['filters']['filter'];
182
+        }
183
+        if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) {
184
+            $array['activity']['settings'] = $array['activity']['settings']['setting'];
185
+        }
186
+        if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) {
187
+            $array['activity']['providers'] = $array['activity']['providers']['provider'];
188
+        }
189
+        if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])
190
+            && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])
191
+            && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class'])
192
+        ) {
193
+            $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin'];
194
+        }
195
+        if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) {
196
+            $array['settings']['admin'] = [$array['settings']['admin']];
197
+        }
198
+        if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) {
199
+            $array['settings']['admin-section'] = [$array['settings']['admin-section']];
200
+        }
201
+        if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) {
202
+            $array['settings']['personal'] = [$array['settings']['personal']];
203
+        }
204
+        if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) {
205
+            $array['settings']['personal-section'] = [$array['settings']['personal-section']];
206
+        }
207 207
 
208
-		if(!is_null($this->cache)) {
209
-			$this->cache->set($fileCacheKey, json_encode($array));
210
-		}
211
-		return $array;
212
-	}
208
+        if(!is_null($this->cache)) {
209
+            $this->cache->set($fileCacheKey, json_encode($array));
210
+        }
211
+        return $array;
212
+    }
213 213
 
214
-	/**
215
-	 * @param \SimpleXMLElement $xml
216
-	 * @return array
217
-	 */
218
-	public function xmlToArray($xml) {
219
-		if (!$xml->children()) {
220
-			return (string)$xml;
221
-		}
214
+    /**
215
+     * @param \SimpleXMLElement $xml
216
+     * @return array
217
+     */
218
+    public function xmlToArray($xml) {
219
+        if (!$xml->children()) {
220
+            return (string)$xml;
221
+        }
222 222
 
223
-		$array = [];
224
-		foreach ($xml->children() as $element => $node) {
225
-			$totalElement = count($xml->{$element});
223
+        $array = [];
224
+        foreach ($xml->children() as $element => $node) {
225
+            $totalElement = count($xml->{$element});
226 226
 
227
-			if (!isset($array[$element])) {
228
-				$array[$element] = $totalElement > 1 ? [] : "";
229
-			}
230
-			/** @var \SimpleXMLElement $node */
231
-			// Has attributes
232
-			if ($attributes = $node->attributes()) {
233
-				$data = [
234
-					'@attributes' => [],
235
-				];
236
-				if (!count($node->children())){
237
-					$value = (string)$node;
238
-					if (!empty($value)) {
239
-						$data['@value'] = (string)$node;
240
-					}
241
-				} else {
242
-					$data = array_merge($data, $this->xmlToArray($node));
243
-				}
244
-				foreach ($attributes as $attr => $value) {
245
-					$data['@attributes'][$attr] = (string)$value;
246
-				}
227
+            if (!isset($array[$element])) {
228
+                $array[$element] = $totalElement > 1 ? [] : "";
229
+            }
230
+            /** @var \SimpleXMLElement $node */
231
+            // Has attributes
232
+            if ($attributes = $node->attributes()) {
233
+                $data = [
234
+                    '@attributes' => [],
235
+                ];
236
+                if (!count($node->children())){
237
+                    $value = (string)$node;
238
+                    if (!empty($value)) {
239
+                        $data['@value'] = (string)$node;
240
+                    }
241
+                } else {
242
+                    $data = array_merge($data, $this->xmlToArray($node));
243
+                }
244
+                foreach ($attributes as $attr => $value) {
245
+                    $data['@attributes'][$attr] = (string)$value;
246
+                }
247 247
 
248
-				if ($totalElement > 1) {
249
-					$array[$element][] = $data;
250
-				} else {
251
-					$array[$element] = $data;
252
-				}
253
-				// Just a value
254
-			} else {
255
-				if ($totalElement > 1) {
256
-					$array[$element][] = $this->xmlToArray($node);
257
-				} else {
258
-					$array[$element] = $this->xmlToArray($node);
259
-				}
260
-			}
261
-		}
248
+                if ($totalElement > 1) {
249
+                    $array[$element][] = $data;
250
+                } else {
251
+                    $array[$element] = $data;
252
+                }
253
+                // Just a value
254
+            } else {
255
+                if ($totalElement > 1) {
256
+                    $array[$element][] = $this->xmlToArray($node);
257
+                } else {
258
+                    $array[$element] = $this->xmlToArray($node);
259
+                }
260
+            }
261
+        }
262 262
 
263
-		return $array;
264
-	}
263
+        return $array;
264
+    }
265 265
 }
Please login to merge, or discard this patch.