AbstractBackend   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 54
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isEnabled() 0 3 1
A hasProtocol() 0 7 2
A toArray() 0 10 1
A getConfig() 0 10 2
1
<?php
2
3
namespace OCA\Chat;
4
5
use \OCP\IConfig;
6
use \OCA\Chat\Db\ConfigMapper;
7
8
abstract class AbstractBackend implements IBackend {
9
10
	protected static $initConvs = array();
11
12
	/**
13
	 * @var \OCP\IConfig
14
	 */
15
	private $config;
16
17
	/**
18
	 * @var \OCA\Chat\Db\ConfigMapper
19
	 */
20
	private $configMapper;
21
22
	public function __construct(ConfigMapper $configMapper, IConfig $config){
23
		$this->configMapper = $configMapper;
24
		$this->config = $config;
25
	}
26
27
	public function hasProtocol($protocol){
28
		if(in_array($protocol, $this->getProtocols())){
29
			return true;
30
		} else {
31
			return false;
32
		}
33
	}
34
35
	public function toArray(){
36
		$result = array();
37
		$result['id'] = $this->getId();
38
		$result['enabled'] = $this->isEnabled();
39
		$result['displayname'] = $this->getDisplayName();
40
		$result['protocols'] = $this->getProtocols();
41
		$result['config'] = $this->getConfig();
42
		$result['connected'] = false;
43
		return $result;
44
	}
45
46
	public function isEnabled(){
47
		return $this->config->getAppValue('chat', 'backend_' . $this->getId() .  '_enabled', true);
48
	}
49
50
	public function getConfig(){
51
		$config = $this->configMapper->getByBackend($this->getId());
52
		$defaultConfig = $this->getDefaultConfig();
53
54
		$configNotInDB = array_diff_key($defaultConfig, $config);
55
		foreach ($configNotInDB as $key=>$value){
56
			$config[$key] = $value;
57
		}
58
		return $config;
59
	}
60
61
}