Passed
Push — master ( 12da69...b976cd )
by Roeland
20:03 queued 05:06
created

JSDataService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 32
c 1
b 0
f 0
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 14 2
A __construct() 0 6 1
A getKey() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright Copyright (c) 2020, Roeland Jago Douma <[email protected]>
7
 *
8
 * @author Roeland Jago Douma <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Accessibility\Service;
28
29
use OCA\Accessibility\AppInfo\Application;
30
use OCP\AppFramework\Services\InitialStateProvider;
31
use OCP\IConfig;
32
use OCP\IUserSession;
33
34
class JSDataService extends InitialStateProvider {
35
	/** @var IUserSession */
36
	private $userSession;
37
	/** @var IConfig */
38
	private $config;
39
40
	public function __construct(
41
		IUserSession $userSession,
42
		IConfig $config
43
	) {
44
		$this->userSession = $userSession;
45
		$this->config = $config;
46
	}
47
48
	public function getKey(): string {
49
		return 'data';
50
	}
51
52
	public function getData() {
53
		$user = $this->userSession->getUser();
54
55
		if ($user === null) {
56
			$theme = false;
57
			$highcontrast = false;
58
		} else {
59
			$theme = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'theme', false);
60
			$highcontrast = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'highcontrast', false) !== false;
61
		}
62
63
		return [
64
			'theme' => $theme,
65
			'highcontrast' => $highcontrast,
66
		];
67
	}
68
}
69