|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Changelog keeper |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/hiqdev/chkipper |
|
6
|
|
|
* @package chkipper |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hiqdev\chkipper\lib; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Commit class. |
|
15
|
|
|
* |
|
16
|
|
|
* @property string $hash |
|
17
|
|
|
* @property string $label |
|
18
|
|
|
* @property array $comments: comment => comment |
|
19
|
|
|
* @property string $date |
|
20
|
|
|
* @property string $author |
|
21
|
|
|
* @property string $hash |
|
22
|
|
|
* |
|
23
|
|
|
* @author Andrii Vasyliev <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class Commit |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var string 7 characters commit hash |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $_hash; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string string representation of commit |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $_label; |
|
36
|
|
|
protected $_comments = []; |
|
37
|
|
|
|
|
38
|
|
|
protected $_date; |
|
39
|
|
|
protected $_author; |
|
40
|
|
|
protected $_subject; |
|
41
|
|
|
|
|
42
|
3 |
|
public function __construct($hash, $label = null, array $comments = []) |
|
43
|
|
|
{ |
|
44
|
3 |
|
$this->setHash($hash); |
|
45
|
3 |
|
$this->setLabel($label); |
|
46
|
3 |
|
$this->setComments($comments); |
|
47
|
3 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function set(Commit $commit) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->setHash($commit->hashHash()); |
|
|
|
|
|
|
52
|
|
|
$this->setLabel($commit->getLabel()); |
|
53
|
|
|
$this->setComments($commit->getComments()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
3 |
|
public function setHash($hash) |
|
57
|
|
|
{ |
|
58
|
3 |
|
$this->_hash = $hash; |
|
59
|
3 |
|
} |
|
60
|
|
|
|
|
61
|
3 |
|
public function getHash() |
|
62
|
|
|
{ |
|
63
|
3 |
|
return $this->_hash; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
3 |
|
public function setLabel($label) |
|
67
|
|
|
{ |
|
68
|
3 |
|
if ($label) { |
|
69
|
3 |
|
$this->_label = $label; |
|
70
|
3 |
|
if (preg_match('/^(\d{4}-\d{2}-\d{2})\s*(.*?)\s*\[(\S*?)\]$/', $label, $m) || |
|
71
|
3 |
|
preg_match('/^(\d{4}-\d{2}-\d{2})\s*(.*?)\s*\((\S*?)\)$/', $label, $m)) { |
|
72
|
3 |
|
$this->setDate($m[1]); |
|
73
|
3 |
|
$this->setSubject($m[2]); |
|
74
|
3 |
|
$this->setAuthor($m[3]); |
|
75
|
3 |
|
} |
|
76
|
3 |
|
} |
|
77
|
3 |
|
} |
|
78
|
|
|
|
|
79
|
3 |
|
public function getLabel() |
|
80
|
|
|
{ |
|
81
|
3 |
|
return $this->_subject || $this->_date || $this->_author |
|
82
|
3 |
|
? $this->getDate() . ' ' . $this->getSubject() . ' [' . $this->getAuthor() . ']' |
|
83
|
3 |
|
: $this->_label; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
2 |
|
public function addComment($comment) |
|
87
|
|
|
{ |
|
88
|
2 |
|
$this->_comments[$comment] = $comment; |
|
89
|
2 |
|
} |
|
90
|
|
|
|
|
91
|
3 |
|
public function addComments(array $comments) |
|
92
|
|
|
{ |
|
93
|
3 |
|
foreach ($comments as $comment) { |
|
94
|
1 |
|
$this->addComment($comment); |
|
95
|
3 |
|
} |
|
96
|
3 |
|
} |
|
97
|
|
|
|
|
98
|
3 |
|
public function setComments($comments) |
|
99
|
|
|
{ |
|
100
|
3 |
|
$this->_comments = []; |
|
101
|
3 |
|
$this->addComments($comments); |
|
102
|
3 |
|
} |
|
103
|
|
|
|
|
104
|
3 |
|
public function getComments() |
|
105
|
|
|
{ |
|
106
|
3 |
|
return $this->_comments; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
3 |
|
public function setDate($value) |
|
110
|
|
|
{ |
|
111
|
3 |
|
$timestamp = strtotime($value); |
|
112
|
3 |
|
if ($timestamp !== false) { |
|
113
|
3 |
|
$this->_date = $timestamp; |
|
114
|
3 |
|
} |
|
115
|
|
|
|
|
116
|
3 |
|
return $this; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
3 |
|
public function getDate() |
|
120
|
|
|
{ |
|
121
|
3 |
|
return $this->_date ? date('Y-m-d', $this->_date) : null; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
3 |
|
public function setSubject($value) |
|
125
|
|
|
{ |
|
126
|
3 |
|
$this->_subject = $value; |
|
127
|
|
|
|
|
128
|
3 |
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
3 |
|
public function getSubject() |
|
132
|
|
|
{ |
|
133
|
3 |
|
return $this->_subject; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
3 |
|
public function setAuthor($value) |
|
137
|
|
|
{ |
|
138
|
3 |
|
$this->_author = $value; |
|
139
|
|
|
|
|
140
|
3 |
|
return $this; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
3 |
|
public function getAuthor() |
|
144
|
|
|
{ |
|
145
|
3 |
|
return $this->_author; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
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.