1 | <?php |
||
22 | class CommitMessage |
||
23 | { |
||
24 | /** |
||
25 | * Commit Message content |
||
26 | * |
||
27 | * This includes lines that are comments |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $rawContent; |
||
32 | |||
33 | /** |
||
34 | * Content split lines |
||
35 | * |
||
36 | * This includes lines that are comments |
||
37 | * |
||
38 | * @var string[] |
||
39 | */ |
||
40 | private $rawLines; |
||
41 | |||
42 | /** |
||
43 | * Amount of lines |
||
44 | * |
||
45 | * This includes lines that are comments |
||
46 | * |
||
47 | * @var int |
||
48 | */ |
||
49 | private $rawLineCount; |
||
50 | |||
51 | /** |
||
52 | * The comment character |
||
53 | * |
||
54 | * Null would indicate the comment character is not set for this commit. A comment character might be null if this |
||
55 | * commit came from a message stored in the repository, it would be populated if it came from a commit-msg hook, |
||
56 | * where the commit message can still contain comments. |
||
57 | * |
||
58 | * @var string|null |
||
59 | */ |
||
60 | private $commentCharacter; |
||
61 | |||
62 | /** |
||
63 | * Get the lines |
||
64 | * |
||
65 | * This excludes the lines which are comments |
||
66 | * |
||
67 | * @var string[] |
||
68 | */ |
||
69 | private $lines; |
||
70 | |||
71 | /** |
||
72 | * Get the number of lines |
||
73 | * |
||
74 | * This excludes lines which are comments |
||
75 | * |
||
76 | * @var int |
||
77 | */ |
||
78 | private $lineCount; |
||
79 | |||
80 | /** |
||
81 | * CommitMessage constructor. |
||
82 | * |
||
83 | * @param string $content |
||
84 | * @param string|null $commentCharacter |
||
85 | */ |
||
86 | 12 | public function __construct(string $content, string $commentCharacter = null) |
|
96 | |||
97 | /** |
||
98 | * Is message empty. |
||
99 | * |
||
100 | * @return bool |
||
101 | */ |
||
102 | 1 | public function isEmpty() : bool |
|
106 | |||
107 | /** |
||
108 | * Get complete commit message content. |
||
109 | * |
||
110 | * This includes lines that are comments |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | 1 | public function getContent() : string |
|
118 | |||
119 | /** |
||
120 | * Return all lines. |
||
121 | * |
||
122 | * This includes lines that are comments |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | 1 | public function getLines() : array |
|
130 | |||
131 | /** |
||
132 | * Return line count. |
||
133 | * |
||
134 | * This includes lines that are comments |
||
135 | * |
||
136 | * @return int |
||
137 | */ |
||
138 | 2 | public function getLineCount() : int |
|
142 | |||
143 | /** |
||
144 | * Get a specific line. |
||
145 | * |
||
146 | * @param int $index |
||
147 | * @return string |
||
148 | */ |
||
149 | 1 | public function getLine(int $index) : string |
|
153 | |||
154 | /** |
||
155 | * Return first line. |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | 2 | public function getSubject() : string |
|
163 | |||
164 | /** |
||
165 | * Return content from line nr. 3 to the last line. |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | 2 | public function getBody() : string |
|
173 | |||
174 | /** |
||
175 | * Return lines from line nr. 3 to the last line. |
||
176 | * |
||
177 | * @return array |
||
178 | */ |
||
179 | 3 | public function getBodyLines() : array |
|
183 | |||
184 | /** |
||
185 | * Create CommitMessage from file. |
||
186 | * |
||
187 | * @param string $path |
||
188 | * @param string|null $commentCharacter |
||
189 | * @return \SebastianFeldmann\Git\CommitMessage |
||
190 | */ |
||
191 | 3 | public static function createFromFile(string $path, $commentCharacter = '#') : CommitMessage |
|
199 | |||
200 | /** |
||
201 | * Get the lines that are not comments |
||
202 | * |
||
203 | * Null comment character indicates no comment character. |
||
204 | * |
||
205 | * @param array $rawLines |
||
206 | * @param string|null $commentCharacter |
||
207 | * @return string[] |
||
208 | */ |
||
209 | 12 | private function getContentLines(array $rawLines, string $commentCharacter = null) : array { |
|
220 | |||
221 | /** |
||
222 | * Get the comment character |
||
223 | * |
||
224 | * Null would indicate the comment character is not set for this commit. A comment character might be null if this |
||
225 | * commit came from a message stored in the repository, it would be populated if it came from a commit-msg hook. |
||
226 | * |
||
227 | * @return null|string |
||
228 | */ |
||
229 | public function getCommentCharacter() |
||
233 | } |
||
234 |