20 private $validMsgParts = [
60 private $originalMsg =
'';
74 private $lengthyLines;
81 private static $validTypes = [
102 private $ignoreRegex =
'/^Merge |^Revert /i';
121 private $formatRegex =
"/^(\w*)\(([\w]+)\)\: ([^\n]*)(\n\n?(.*))?$/is";
127 private $maxLineLength = 160;
148 $this->originalMsg = $msg;
150 $msg = str_replace([
"\r\n",
"\r"],
"\n", $msg);
151 $this->msg = $this->removeComments($msg);
170 return $this->originalMsg;
179 return preg_match($this->ignoreRegex, $this->msg) === 1;
187 private function processMsg() {
190 preg_match($this->formatRegex, $this->msg, $matches);
191 foreach ($this->validMsgParts as $i => $part) {
192 $this->$part = isset($matches[$i]) ? $matches[$i] :
'';
195 $this->lengthyLines = $this->findLengthyLines($this->msg, $this->maxLineLength);
204 return $this->isValidFormat() &&
205 $this->isValidLineLength() &&
206 $this->isValidType();
215 return preg_match($this->formatRegex, $this->msg) === 1;
226 return count($this->lengthyLines) === 0;
235 return $this->lengthyLines;
244 return in_array($this->type, self::$validTypes);
253 return self::$validTypes;
262 return $this->maxLineLength;
274 $this->maxLineLength = (int) $len;
286 if ($part && in_array($part, $this->validMsgParts)) {
302 foreach (explode(
"\n", rtrim($msg)) as $line) {
303 if (substr($line, 0, 1) !==
'#') {
308 return implode(
"\n", $msg_arr);
320 $lines = explode(
"\n", $msg);
323 foreach ($lines as $i => $line) {
324 if (strlen($line) > $max_len) {
325 $lengthy_lines[] = ++$i;
329 return $lengthy_lines;
336 return $this->getMsg();
static removeComments($msg)
Removes all lines that start with #.
getLengthyLines()
Get the line number of lines that are too long.
static getValidTypes()
Return all valid types.
isValid()
Are all parts of the message valid.
isValidType()
Is the type valid.
getOriginalMsg()
Return the original message.
getMsg()
Return the processed message.
isValidFormat()
Whether the message format conforms to our standards.
static findLengthyLines($msg, $max_len)
Returns an array of line numbers > $max_len.
isValidLineLength()
Are any of the lines too long?
setMsg($msg)
Sets the active message.
getPart($part)
Get part of the message.
shouldIgnore()
Should this msg be ignored for formatting?
__construct($msg=null)
Checks if a commit message is in the correct format.
setMaxLineLength($len)
Sets the max line length allowed.
getMaxLineLength()
Return the max line length.