SettingsController::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
namespace OCA\Notes\Controller;
3
4
use OCP\AppFramework\Controller;
5
6
use OCP\IRequest;
7
use OCP\IUserSession;
8
use OCP\AppFramework\Http\JSONResponse;
9
use OCA\Notes\Service\SettingsService;
10
11
class SettingsController extends Controller {
12
13
	private $service;
14
	private $userSession;
15
16
	public function __construct(
17
		$appName,
18
		IRequest $request,
19
		SettingsService $service,
20
		IUserSession $userSession
21
	) {
22
		parent::__construct($appName, $request);
23
		$this->service = $service;
24
		$this->userSession = $userSession;
25
	}
26
27
	private function getUID() {
28
		return $this->userSession->getUser()->getUID();
29
	}
30
31
	/**
32
	 * @NoAdminRequired
33
	 * @throws \OCP\PreConditionNotMetException
34
	 */
35
	public function set() {
36
		$this->service->set(
37
			$this->getUID(),
38
			$this->request->getParams()
39
		);
40
		return $this->get();
41
	}
42
43
	/**
44
	 * @NoAdminRequired
45
	 */
46
	public function get() {
47
		return new JSONResponse($this->service->getAll($this->getUID()));
48
	}
49
}
50