SettingsController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 49
ccs 19
cts 19
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 20 4
A __construct() 0 8 1
1
<?php
2
/**
3
 * @author Thomas Tanghus
4
 * @copyright 2013-2014 Thomas Tanghus ([email protected])
5
 * @copyright 2015 Lukas Reschke [email protected]
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later.
9
 * See the COPYING-README file.
10
 */
11
12
namespace OCA\Contacts\Controller;
13
14
use OCP\AppFramework\Http\JSONResponse;
15
use OCP\AppFramework\Controller;
16
use OCP\AppFramework\Http;
17
use OCP\IConfig;
18
use OCP\IRequest;
19
20
/**
21
 * Controller class for groups/categories
22
 */
23
class SettingsController extends Controller {
24
	/** @var IConfig */
25
	private $config;
26
	/** @var string */
27
	private $userId;
28
29
	/**
30
	 * @param string $AppName
31
	 * @param IRequest $request
32
	 * @param IConfig $config
33
	 * @param string $UserId
34
	 */
35 3
	public function __construct($AppName,
0 ignored issues
show
Coding Style Naming introduced by
The parameter $AppName is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style Naming introduced by
The parameter $UserId is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style Naming introduced by
The variable $AppName is not named in camelCase.

This check marks variable names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style Naming introduced by
The variable $UserId is not named in camelCase.

This check marks variable names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
36
								IRequest $request,
37
								IConfig $config,
38
								$UserId){
39 3
		parent::__construct($AppName, $request);
40 3
		$this->config = $config;
41 3
		$this->userId = $UserId;
42 3
	}
43
44
	/**
45
	 * @NoAdminRequired
46
	 *
47
	 * @param string $key
48
	 * @param string $value
49
	 * @return JSONResponse
50
	 */
51 3
	public function set($key = '', $value = '') {
52 3
		$response = new JSONResponse();
53
54 3
		if($key === '' || $value === '') {
55 1
			$response->setStatus(Http::STATUS_PRECONDITION_FAILED);
56 1
			return $response;
57
		}
58
59
		try {
60 2
			$this->config->setUserValue($this->userId, $this->appName, $key, $value);
61 1
			$response->setData([
62 1
				'key' => $key,
63 1
				'value' => $value,
64 1
			]);
65 1
			return $response;
66 1
		} catch (\Exception $e) {
67 1
			$response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR);
68 1
			return $response;
69
		}
70
	}
71
}
72