Passed
Push — master ( e324c9...3ac048 )
by Roeland
19:27 queued 12s
created

JSDataService::jsonSerialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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