DNBranch::DNBuildList()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
/**
4
 * Class DNBranch
5
 *
6
 * @method string getName()
7
 */
8
class DNBranch extends ViewableData {
0 ignored issues
show
Coding Style introduced by
The property $_lastUpdatedCache is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
9
10
	/**
11
	 * @var Gitonomy\Git\Reference\Branch
12
	 */
13
	protected $branch = null;
14
15
	/**
16
	 * @var DNProject
17
	 */
18
	protected $project = null;
19
20
	/**
21
	 * @var DNData
22
	 */
23
	protected $data = null;
24
25
	private static $casting = array(
0 ignored issues
show
Unused Code introduced by
The property $casting is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
26
		'Name' => 'Text',
27
		'SHA' => 'Text'
28
	);
29
30
	/**
31
	 * @var SS_Datetime
32
	 */
33
	protected $_lastUpdatedCache = '';
34
35
	/**
36
	 * @param DNProject $project
37
	 * @param DNData $data
38
	 */
39
	public function __construct(Gitonomy\Git\Reference\Branch $branch, DNProject $project, DNData $data) {
40
		$this->branch = $branch;
41
		$this->project = $project;
42
		$this->data = $data;
43
	}
44
45
	public function __toString() {
46
		return $this->Name();
47
	}
48
49
	/**
50
	 * @return string
51
	 */
52
	public function Name() {
53
		return (string)htmlentities($this->branch->getName());
54
	}
55
56
	public function Link() {
57
		// Use a get-var for branch so that it can handle unsafe chars better
58
		return Controller::join_links($this->project->Link(), 'branch?name=' . urlencode($this->Name()));
59
	}
60
61
	/**
62
	 * @return string
63
	 */
64
	public function SHA() {
65
		return (string)htmlentities($this->branch->getCommit()->getHash());
66
	}
67
68
	/**
69
	 * Provides a DNBuildList of builds found in this project.
70
	 */
71
	public function DNBuildList() {
72
		$blockBranch = $this->branch->getName() == 'master' ? null : 'master';
73
		return DNReferenceList::create($this->project, $this->data, $this->branch, $blockBranch);
74
	}
75
76
	/**
77
	 * @return SS_Datetime
78
	 */
79
	public function LastUpdated() {
80
81
		if($this->_lastUpdatedCache) {
82
			return $this->_lastUpdatedCache;
83
		}
84
		try {
85
			$created = $this->branch->getCommit()->getCommitterDate();
86
		} catch(Exception $e) {
87
			//occasionally parsing will fail this is a fallback to make it still work
88
			return new SS_Datetime();
89
		}
90
91
		$created->setTimezone(new DateTimeZone(date_default_timezone_get()));
92
93
		$date = SS_Datetime::create();
94
		$date->setValue($created->format('Y-m-d H:i:s'));
95
		$this->_lastUpdatedCache = $date;
96
		return $date;
97
	}
98
99
	/**
100
	 * @return string
101
	 */
102
	public function IsOpenByDefault() {
103
		if($this->Name() == 'master') {
104
			return " open";
105
		} else {
106
			return "";
107
		}
108
	}
109
110
}
111