AppConfig   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 0
dl 14
loc 70
ccs 0
cts 21
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isConverterEnabled() 0 3 1
A setAppValue() 0 3 1
A setUserValue() 0 3 1
A getAppValue() 7 7 2
A getUserValue() 7 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * ownCloud - Documents App
4
 *
5
 * @author Victor Dubiniuk
6
 * @copyright 2015 Victor Dubiniuk [email protected]
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later.
10
 */
11
 
12
namespace OCA\Documents;
13
14
use \OCP\IConfig;
15
16
 class AppConfig{
17
 	private $appName = 'documents';
18
	private $defaults = [
19
		'converter' => 'off',
20
		'converter_url' => 'http://localhost:16080',
21
		'unstable' => 'false'
22
	];
23
	
24
	private $config;
25
	
26
	public function __construct(IConfig $config) {
27
		$this->config = $config;
28
	}
29
	
30
	/**
31
	 * Can we convert anything to odt?
32
	 * @return bool
33
	 */
34
	public function isConverterEnabled(){
35
		return $this->getAppValue('converter') !== 'off';
36
	}
37
	
38
	/**
39
	 * Get a value by key
40
	 * @param string $key
41
	 * @return string
42
	 */
43 View Code Duplication
	public function getAppValue($key) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
		$defaultValue = null;
45
		if (array_key_exists($key, $this->defaults)){
46
			$defaultValue = $this->defaults[$key];
47
		}
48
		return $this->config->getAppValue($this->appName, $key, $defaultValue);
49
	}
50
51
	/**
52
	 * Set a value by key
53
	 * @param string $key
54
	 * @param string $value
55
	 * @return string
56
	 */
57
	public function setAppValue($key, $value) {
58
		return $this->config->setAppValue($this->appName, $key, $value);
59
	}
60
	
61
	/**
62
	 * Get a value by key for a user
63
	 * @param string $userId
64
	 * @param string $key
65
	 * @return string
66
	 */
67 View Code Duplication
	public function getUserValue($userId, $key) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
		$defaultValue = null;
69
		if (array_key_exists($key, $this->defaults)){
70
			$defaultValue = $this->defaults[$key];
71
		}
72
		return $this->config->getUserValue($userId, $this->appName, $key, $defaultValue);
73
	}
74
75
	/**
76
	 * Set a value by key for a user
77
	 * @param string $userId
78
	 * @param string $key
79
	 * @param string $value
80
	 * @return string
81
	 */
82
	public function setUserValue($userId, $key, $value) {
83
		return $this->config->setUserValue($userId, $this->appName, $key, $value);
84
	}
85
 }
86