Completed
Push — master ( 50458e...8060b0 )
by
unknown
02:27
created

Channel   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 22.58%

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 10
c 5
b 1
f 1
lcom 1
cbo 0
dl 0
loc 67
ccs 7
cts 31
cp 0.2258
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getChannels() 0 8 1
A getCurrentChannel() 0 3 1
A setCurrentChannel() 0 5 1
A getLastCheckedAt() 0 5 1
A flushCache() 0 3 1
A getFeed() 0 11 4
1
<?php
2
3
/**
4
 * ownCloud - Updater plugin
5
 *
6
 * @author Victor Dubiniuk
7
 * @copyright 2015 Victor Dubiniuk [email protected]
8
 *
9
 * This file is licensed under the Affero General Public License version 3 or
10
 * later.
11
 */
12
13
14
namespace OCA\Updater;
15
16
use \OCP\IL10N;
17
18
class Channel {
19
	const CHANNEL_DAILY = 'daily';
20
	const CHANNEL_BETA = 'beta';
21
	const CHANNEL_STABLE = 'stable';
22
	const CHANNEL_PRODUCTION ='production';
23
	const CHANNEL_NONE ='none';
24
	
25
	/** @var IL10N */
26
	private $l10n;
27
	
28 1
	public function __construct(IL10N $l10n){
29 1
		$this->l10n = $l10n;
30 1
	}
31
	
32
	/**
33
	 * All available values
34
	 * @return array
35
	 */
36
	public function getChannels(){
37
		return [
38
			self::CHANNEL_PRODUCTION => $this->l10n->t('Production'),
39
			self::CHANNEL_STABLE => $this->l10n->t('Stable'),
40
			self::CHANNEL_BETA => $this->l10n->t('Beta'),
41
			self::CHANNEL_DAILY => $this->l10n->t('Daily'),
42
		];
43
	}
44
	
45
	/**
46
	 * Get current value
47
	 * @return string
48
	 */
49
	public function getCurrentChannel(){
50
		return \OCP\Util::getChannel();
51
	}
52
53
	/**
54
	 * Set a new value
55
	 * @return string
56
	 */
57
	public function setCurrentChannel($newChannel){
58
		$cleanValue = preg_replace('/[^A-Za-z0-9]/', '', $newChannel);
59
		\OCP\Util::setChannel($cleanValue);
60
		return $cleanValue;
61
	}
62
	
63
	public function getLastCheckedAt(){
64
		return \OC::$server->getDateTimeFormatter()->formatDateTime(
65
			\OC::$server->getConfig()->getAppValue('core', 'lastupdatedat')
66
		);
67
	}
68
	
69
	public function flushCache(){
70
		\OC::$server->getConfig()->setAppValue('core', 'lastupdatedat', 0);
71
	}
72
	
73 1
	public function getFeed($helper = null, $config = null){
74 1
		$helper = is_null($helper) ? \OC::$server->getHTTPHelper() : $helper;
75 1
		$config = is_null($config) ? \OC::$server->getConfig() : $config;
76 1
		$updater = new \OC\Updater($helper, $config);
77
		
78
		$data = $updater->check('https://updates.owncloud.com/server/');
79
		if (!is_array($data)){
80
			$data = [];
81
		}
82
		return $data;
83
	}
84
}
85