|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Changelog keeper |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/chkipper |
|
7
|
|
|
* @package chkipper |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
* @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hiqdev\chkipper\history; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Commit class. |
|
16
|
|
|
* Holds commit properties: |
|
17
|
|
|
* - hash |
|
18
|
|
|
* - date |
|
19
|
|
|
* - author |
|
20
|
|
|
* - subject |
|
21
|
|
|
* - list of comments. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Andrii Vasyliev <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class Commit |
|
26
|
|
|
{ |
|
27
|
|
|
protected $_hash; |
|
28
|
|
|
protected $_label; |
|
29
|
|
|
protected $_comments = []; |
|
30
|
|
|
|
|
31
|
|
|
protected $_date; |
|
32
|
|
|
protected $_author; |
|
33
|
|
|
protected $_subject; |
|
34
|
|
|
|
|
35
|
2 |
|
public function __construct($hash, $label = null, array $comments = []) |
|
36
|
|
|
{ |
|
37
|
2 |
|
$this->setHash($hash); |
|
38
|
2 |
|
$this->setLabel($label); |
|
39
|
2 |
|
$this->setComments($comments); |
|
40
|
2 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function set(Commit $commit) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->setHash($commit->hashHash()); |
|
|
|
|
|
|
45
|
|
|
$this->setLabel($commit->getLabel()); |
|
46
|
|
|
$this->setComments($commit->getComments()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
2 |
|
public function setHash($hash) |
|
50
|
|
|
{ |
|
51
|
2 |
|
$this->_hash = $hash; |
|
52
|
2 |
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
public function getHash() |
|
55
|
|
|
{ |
|
56
|
1 |
|
return $this->_hash; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
2 |
|
public function setLabel($label) |
|
60
|
|
|
{ |
|
61
|
2 |
|
if ($label) { |
|
62
|
2 |
|
$this->_label = $label; |
|
63
|
2 |
|
if (preg_match('/^(\d{4}-\d{2}-\d{2})\s*(.*?)\s*[\(\[](.*?)[\)\]]$/', $label, $m)) { |
|
64
|
2 |
|
$this->setDate($m[1]); |
|
65
|
2 |
|
$this->setSubject($m[2]); |
|
66
|
2 |
|
$this->setAuthor($m[3]); |
|
67
|
2 |
|
} |
|
68
|
2 |
|
} |
|
69
|
2 |
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
public function getLabel() |
|
72
|
|
|
{ |
|
73
|
1 |
|
return $this->_subject || $this->_date || $this->_author |
|
74
|
1 |
|
? $this->getDate() . ' ' . $this->getSubject() . ' [' . $this->getAuthor() . ']' |
|
75
|
1 |
|
: $this->_label |
|
76
|
1 |
|
; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
2 |
|
public function addComment($comment) |
|
80
|
|
|
{ |
|
81
|
2 |
|
$this->_comments[$comment] = $comment; |
|
82
|
2 |
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
public function addComments(array $comments) |
|
85
|
|
|
{ |
|
86
|
2 |
|
foreach ($comments as $comment) { |
|
87
|
1 |
|
$this->addComment($comment); |
|
88
|
2 |
|
} |
|
89
|
2 |
|
} |
|
90
|
|
|
|
|
91
|
2 |
|
public function setComments($comments) |
|
92
|
|
|
{ |
|
93
|
2 |
|
$this->_comments = []; |
|
94
|
2 |
|
$this->addComments($comments); |
|
95
|
2 |
|
} |
|
96
|
|
|
|
|
97
|
1 |
|
public function getComments() |
|
98
|
|
|
{ |
|
99
|
1 |
|
return $this->_comments; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
2 |
View Code Duplication |
public function setDate($value) |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
2 |
|
$timestamp = strtotime($value); |
|
105
|
2 |
|
if ($timestamp !== false) { |
|
106
|
2 |
|
$this->_date = $timestamp; |
|
107
|
2 |
|
} |
|
108
|
|
|
return $this; |
|
109
|
2 |
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function getDate() |
|
112
|
1 |
|
{ |
|
113
|
|
|
return $this->_date ? date('Y-m-d', $this->_date) : null; |
|
114
|
1 |
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function setSubject($value) |
|
117
|
2 |
|
{ |
|
118
|
|
|
$this->_subject = $value; |
|
119
|
2 |
|
return $this; |
|
120
|
|
|
} |
|
121
|
2 |
|
|
|
122
|
|
|
public function getSubject() |
|
123
|
|
|
{ |
|
124
|
1 |
|
return $this->_subject; |
|
125
|
|
|
} |
|
126
|
1 |
|
|
|
127
|
|
|
public function setAuthor($value) |
|
128
|
|
|
{ |
|
129
|
2 |
|
$this->_author = $value; |
|
130
|
|
|
return $this; |
|
131
|
2 |
|
} |
|
132
|
|
|
|
|
133
|
2 |
|
public function getAuthor() |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->_author; |
|
136
|
1 |
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.