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