Completed
Push — stable10 ( d896d4...713e20 )
by Joas
26:40 queued 16:05
created

RequestTime   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getTimezones() 0 17 3
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Joas Schilling <[email protected]>
4
 *
5
 * @license GNU AGPL version 3 or any later version
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as
9
 * published by the Free Software Foundation, either version 3 of the
10
 * License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 */
21
22
namespace OCA\WorkflowEngine\Controller;
23
24
use OCP\AppFramework\Controller;
25
use OCP\AppFramework\Http\JSONResponse;
26
27
class RequestTime extends Controller {
28
29
	/**
30
	 * @NoAdminRequired
31
	 *
32
	 * @param string $search
33
	 * @return JSONResponse
34
	 */
35
	public function getTimezones($search = '') {
36
		$timezones = \DateTimeZone::listIdentifiers();
37
38
		if ($search !== '') {
39
			$timezones = array_filter($timezones, function ($timezone) use ($search) {
40
				return strpos(strtolower($timezone), strtolower($search)) !== false;
41
			});
42
		}
43
44
		$timezones = array_slice($timezones, 0, 10);
45
46
		$response = [];
47
		foreach ($timezones as $timezone) {
48
			$response[$timezone] = $timezone;
49
		}
50
		return new JSONResponse($response);
51
	}
52
}
53