Completed
Push — feature/ss4-upgrade ( f41a3f )
by
unknown
10:12
created

AddonLink::Link()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
rs 9.2
cc 4
eloc 6
nc 3
nop 0
1
<?php
2
3
namespace SilverStripe\Addons\Model;
4
5
/**
6
 * A link from one add-ons to another, such as a requirement dependency.
7
 */
8
class AddonLink extends DataObject 
9
{
10
11
	public static $db = [
12
		'Name' => 'Varchar(100)',
13
		'Type' => 'Enum(array("require", "require-dev", "suggest", "provide", "conflict", "replace"))',
14
		'Constraint' => 'Varchar(100)',
15
		'Description' => 'Varchar(255)'
16
	];
17
18
	public static $has_one = [
19
		'Source' => 'SilverStripe\Addons\Model\AddonVersion',
20
		'Target' => 'SilverStripe\Addons\Model\Addon'
21
	];
22
23
	public function Link() 
24
	{
25
		if ($this->TargetID) {
26
			return $this->Target()->Link();
27
		}
28
29
		if ($this->Name == 'php' || strpos($this->Name, 'ext-') === 0) {
30
			return '';
31
		}
32
33
		return "https://packagist.org/packages/$this->Name";
34
	}
35
36
}
37