Completed
Pull Request — master (#331)
by John
04:37
created

TimezoneController::getTimezoneWithSubRegion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 3
rs 10
c 1
b 0
f 0
ccs 0
cts 0
cp 0
crap 2
1
<?php
2
/**
3
 * Calendar App
4
 *
5
 * @author Georg Ehrke
6
 * @copyright 2017 Georg Ehrke <[email protected]>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
namespace OCA\Calendar\Controller;
23
24
use OCP\AppFramework\Controller;
25
use OCP\AppFramework\Http;
26
use OCP\AppFramework\Http\DataDisplayResponse;
27
use OCP\AppFramework\Http\NotFoundResponse;
28
29
class TimezoneController extends Controller {
30
31
	/**
32
	 * @NoAdminRequired
33
	 *
34
	 * @param string $id
35
	 * @return NotFoundResponse|DataDisplayResponse
36
	 */
37 4
	public function getTimezone($id) {
38 4
		if (!in_array($id, $this->getTimezoneList())) {
39 2
			return new NotFoundResponse();
40
		}
41
42 2
		$tzData = file_get_contents(__DIR__ . '/../timezones/' . $id);
43
44 2
		return new DataDisplayResponse($tzData, Http::STATUS_OK, [
45 2
			'content-type' => 'text/calendar',
46
		]);
47
	}
48
49
	/**
50
	 * @NoAdminRequired
51
	 * @NoCSRFRequired
52
	 * @PublicPage
53
	 *
54
	 * @param $region
55
	 * @param $city
56
	 * @return DataDisplayResponse
57
	 */
58 2
	public function getTimezoneWithRegion($region, $city) {
59 2
		return $this->getTimezone($region . '-' . $city);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->getTimezone($region . '-' . $city); of type OCP\AppFramework\Http\No...ttp\DataDisplayResponse adds the type OCP\AppFramework\Http\NotFoundResponse to the return on line 59 which is incompatible with the return type documented by OCA\Calendar\Controller\...::getTimezoneWithRegion of type OCP\AppFramework\Http\DataDisplayResponse.
Loading history...
60
	}
61
62
	/**
63
	 * @NoAdminRequired
64
	 * @NoCSRFRequired
65
	 * @PublicPage
66
	 *
67
	 * @param $region
68
	 * @param $subRegion
69
	 * @param $city
70
	 * @return DataDisplayResponse
71
	 */
72
	public function getTimezoneWithSubRegion($region, $subRegion, $city) {
73
		return $this->getTimezone($region . '-' . $subRegion . '-' . $city);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->getTimezone($regi...bRegion . '-' . $city); of type OCP\AppFramework\Http\No...ttp\DataDisplayResponse adds the type OCP\AppFramework\Http\NotFoundResponse to the return on line 73 which is incompatible with the return type documented by OCA\Calendar\Controller\...etTimezoneWithSubRegion of type OCP\AppFramework\Http\DataDisplayResponse.
Loading history...
74
	}
75
76
	/**
77
	 * get a list of default timezones
78
	 *
79
	 * @return array
80
	 */
81 4
	private function getTimezoneList() {
82 4
		$allFiles = scandir(__DIR__ . '/../timezones/');
83
84 4
		return array_values(array_filter($allFiles, function($file) {
85 4
			return (substr($file, -4) === '.ics');
86 4
		}));
87
	}
88
}
89