Completed
Push — master ( 092ec7...c255e1 )
by Victor
9s
created

Feed::__construct()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 12
cts 12
cp 1
rs 8.8571
cc 5
eloc 11
nc 6
nop 1
crap 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
class Feed {
25
26
	/** string $version */
27
	protected $version;
28
29
	/** string $versionString */
30
	protected $versionString;
31
32
	/** string $url */
33
	protected $url;
34
35
	/** string $web */
36
	protected $web;
37
38
	/** array $requiredFeedEntries */
39
	protected $requiredFeedEntries = [
40
		'version',
41
		'versionstring',
42
		'url'
43
	];
44
45
	/** bool $isValid */
46
	protected $isValid = true;
47
48
	/**
49
	 *
50
	 * @param array $data
51
	 */
52 12
	public function __construct($data){
53 12
		$missingEntries = [];
54 12
		foreach ($this->requiredFeedEntries as $index){
55 12
			if (!isset($data[$index]) || empty($data[$index])){
56 5
				$missingEntries[] = $index;
57 12
				$data[$index] = '';
58
			}
59
		}
60
61 12
		if (count($missingEntries)){
62 5
			$this->isValid = false;
63
			//'Got missing or empty fileds for: ' . implode(',', $missingEntries) . '. No updates found.';
64
		}
65 12
		$this->version = $data['version'];
66 12
		$this->versionString = $data['versionstring'];
67 12
		$this->url = $data['url'];
68 12
	}
69
70
	/**
71
	 * Build filename to download as a.b.c.d.zip
72
	 * @return string
73
	 */
74 2
	public function getDownloadedFileName(){
75 2
		$extension = preg_replace('|.*?((\.tar)?\.[^.]*)$|s', '\1', $this->getUrl());
76 2
		return $this->getVersion() . $extension;
77
	}
78
79
	/**
80
	 * Does feed contain all the data required?
81
	 * @return bool
82
	 */
83 7
	public function isValid(){
84 7
		return $this->isValid;
85
	}
86
87
	/**
88
	 *
89
	 * @return string
90
	 */
91 3
	public function getVersion(){
92 3
		return $this->version;
93
	}
94
95
	/**
96
	 *
97
	 * @return string
98
	 */
99
	public function getVersionString(){
100
		return $this->versionString;
101
	}
102
103
	/**
104
	 * Get url to download a new version from
105
	 * @return string
106
	 */
107 2
	public function getUrl(){
108 2
		return $this->url;
109
	}
110
111
	/**
112
	 * Get url to download a checksum from
113
	 * @return string
114
	 */
115
	public function getChecksumUrl(){
116
		return $this->url . '.md5';
117
	}
118
119
}
120