1 | <?php |
||
20 | class CommitMessage |
||
21 | { |
||
22 | /** |
||
23 | * Commit Message content |
||
24 | * |
||
25 | * This includes lines that are comments |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | private $rawContent; |
||
30 | |||
31 | /** |
||
32 | * Content split lines |
||
33 | * |
||
34 | * This includes lines that are comments |
||
35 | * |
||
36 | * @var string[] |
||
37 | */ |
||
38 | private $rawLines; |
||
39 | |||
40 | /** |
||
41 | * Amount of lines |
||
42 | * |
||
43 | * This includes lines that are comments |
||
44 | * |
||
45 | * @var int |
||
46 | */ |
||
47 | private $rawLineCount; |
||
48 | |||
49 | /** |
||
50 | * The comment character |
||
51 | * |
||
52 | * Null would indicate the comment character is not set for this commit. A comment character might be null if this |
||
53 | * commit came from a message stored in the repository, it would be populated if it came from a commit-msg hook, |
||
54 | * where the commit message can still contain comments. |
||
55 | * |
||
56 | * @var string|null |
||
57 | */ |
||
58 | private $commentCharacter; |
||
59 | |||
60 | /** |
||
61 | * Get the lines |
||
62 | * |
||
63 | * This excludes the lines which are comments |
||
64 | * |
||
65 | * @var string[] |
||
66 | */ |
||
67 | private $lines; |
||
68 | |||
69 | /** |
||
70 | * Get the number of lines |
||
71 | * |
||
72 | * This excludes lines which are comments |
||
73 | * |
||
74 | * @var int |
||
75 | */ |
||
76 | private $lineCount; |
||
77 | |||
78 | /** |
||
79 | * Commit Message content |
||
80 | * |
||
81 | * This excludes lines that are comments |
||
82 | * |
||
83 | * @var string |
||
84 | */ |
||
85 | private $content; |
||
86 | |||
87 | /** |
||
88 | * CommitMessage constructor. |
||
89 | * |
||
90 | * @param string $content |
||
91 | * @param string|null $commentCharacter |
||
92 | */ |
||
93 | 21 | public function __construct(string $content, string $commentCharacter = null) |
|
104 | |||
105 | /** |
||
106 | * Is message empty. |
||
107 | * |
||
108 | * @return bool |
||
109 | */ |
||
110 | 2 | public function isEmpty() : bool |
|
114 | |||
115 | /** |
||
116 | * Get complete commit message content. |
||
117 | * |
||
118 | * This includes lines that are comments |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | 2 | public function getContent() : string |
|
126 | |||
127 | /** |
||
128 | * Return all lines. |
||
129 | * |
||
130 | * This includes lines that are comments |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | 2 | public function getLines() : array |
|
138 | |||
139 | /** |
||
140 | * Return line count. |
||
141 | * |
||
142 | * This includes lines that are comments |
||
143 | * |
||
144 | * @return int |
||
145 | */ |
||
146 | 3 | public function getLineCount() : int |
|
150 | |||
151 | /** |
||
152 | * Get a specific line. |
||
153 | * |
||
154 | * @param int $index |
||
155 | * @return string |
||
156 | */ |
||
157 | 2 | public function getLine(int $index) : string |
|
161 | |||
162 | /** |
||
163 | * Return first line. |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | 3 | public function getSubject() : string |
|
171 | |||
172 | /** |
||
173 | * Return content from line nr. 3 to the last line. |
||
174 | * |
||
175 | * @return string |
||
176 | */ |
||
177 | 3 | public function getBody() : string |
|
181 | |||
182 | /** |
||
183 | * Return lines from line nr. 3 to the last line. |
||
184 | * |
||
185 | * @return array |
||
186 | */ |
||
187 | 5 | public function getBodyLines() : array |
|
191 | |||
192 | /** |
||
193 | * Get the comment character |
||
194 | * |
||
195 | * Null would indicate the comment character is not set for this commit. A comment character might be null if this |
||
196 | * commit came from a message stored in the repository, it would be populated if it came from a commit-msg hook. |
||
197 | * |
||
198 | * @return null|string |
||
199 | */ |
||
200 | 1 | public function getCommentCharacter() |
|
204 | |||
205 | /** |
||
206 | * Get the lines that are not comments |
||
207 | * |
||
208 | * Null comment character indicates no comment character. |
||
209 | * |
||
210 | * @param array $rawLines |
||
211 | * @param string|null $commentCharacter |
||
212 | * @return string[] |
||
213 | */ |
||
214 | 21 | private function getContentLines(array $rawLines, string $commentCharacter = null) : array { |
|
225 | |||
226 | /** |
||
227 | * Create CommitMessage from file. |
||
228 | * |
||
229 | * @param string $path |
||
230 | * @param string|null $commentCharacter |
||
231 | * @return \SebastianFeldmann\Git\CommitMessage |
||
232 | */ |
||
233 | 3 | public static function createFromFile(string $path, $commentCharacter = '#') : CommitMessage |
|
241 | } |
||
242 |