Completed
Pull Request — master (#460)
by
unknown
06:08 queued 02:57
created

Feed   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 84%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 96
ccs 21
cts 25
cp 0.84
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getDownloadedFileName() 0 4 1
A isValid() 0 3 1
A getVersion() 0 3 1
A getVersionString() 0 3 1
A getUrl() 0 3 1
A getChecksumUrl() 0 3 1
B __construct() 0 17 5
1
<?php
2
/**
3
 * @author Victor Dubiniuk <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2015, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace Owncloud\Updater\Utils;
23
24
/**
25
 * Class Feed
26
 *
27
 * @package Owncloud\Updater\Utils
28
 */
29
class Feed {
30
31
	/** string $version */
32
	protected $version;
33
34
	/** string $versionString */
35
	protected $versionString;
36
37
	/** string $url */
38
	protected $url;
39
40
	/** string $web */
41
	protected $web;
42
43
	/** array $requiredFeedEntries */
44
	protected $requiredFeedEntries = [
45
		'version',
46
		'versionstring',
47
		'url'
48
	];
49
50
	/** bool $isValid */
51
	protected $isValid = true;
52
53
	/**
54
	 *
55
	 * @param array $data
56
	 */
57 12
	public function __construct($data){
58 12
		$missingEntries = [];
59 12
		foreach ($this->requiredFeedEntries as $index){
60 12
			if (!isset($data[$index]) || empty($data[$index])){
61 5
				$missingEntries[] = $index;
62 12
				$data[$index] = '';
63
			}
64
		}
65
66 12
		if (count($missingEntries)){
67 5
			$this->isValid = false;
68
			//'Got missing or empty fileds for: ' . implode(',', $missingEntries) . '. No updates found.';
69
		}
70 12
		$this->version = $data['version'];
71 12
		$this->versionString = $data['versionstring'];
72 12
		$this->url = $data['url'];
73 12
	}
74
75
	/**
76
	 * Build filename to download as a.b.c.d.zip
77
	 * @return string
78
	 */
79 2
	public function getDownloadedFileName(){
80 2
		$extension = preg_replace('|.*?((\.tar)?\.[^.]*)$|s', '\1', $this->getUrl());
81 2
		return $this->getVersion() . $extension;
82
	}
83
84
	/**
85
	 * Does feed contain all the data required?
86
	 * @return bool
87
	 */
88 7
	public function isValid(){
89 7
		return $this->isValid;
90
	}
91
92
	/**
93
	 *
94
	 * @return string
95
	 */
96 3
	public function getVersion(){
97 3
		return $this->version;
98
	}
99
100
	/**
101
	 *
102
	 * @return string
103
	 */
104
	public function getVersionString(){
105
		return $this->versionString;
106
	}
107
108
	/**
109
	 * Get url to download a new version from
110
	 * @return string
111
	 */
112 2
	public function getUrl(){
113 2
		return $this->url;
114
	}
115
116
	/**
117
	 * Get url to download a checksum from
118
	 * @return string
119
	 */
120
	public function getChecksumUrl(){
121
		return $this->url . '.md5';
122
	}
123
124
}
125