4 use UnexpectedValueException;
21 private $validMsgParts = array(
61 private $originalMsg =
'';
75 private $lengthyLines;
82 private static $validTypes = array(
105 private $validComponents = array(
121 private $ignoreRegex =
'/^Merge |^Revert /i';
140 private $formatRegex =
"/^(\w*)\(([\w]+)\)\: ([^\n]*)(\n\n?(.*))?$/is";
146 private $maxLineLength = 160;
167 $this->originalMsg = $msg;
169 $msg = str_replace(array(
"\r",
"\n"),
"\n", $msg);
170 $this->msg = $this->removeComments($msg);
189 return $this->originalMsg;
198 return preg_match($this->ignoreRegex, $this->msg) === 1;
206 private function processMsg() {
209 preg_match($this->formatRegex, $this->msg, $matches);
210 foreach ($this->validMsgParts as $i => $part) {
211 $this->$part = isset($matches[$i]) ? $matches[$i] :
'';
214 $this->lengthyLines = $this->findLengthyLines($this->msg, $this->maxLineLength);
223 return $this->isValidFormat() &&
224 $this->isValidLineLength() &&
225 $this->isValidType();
234 return preg_match($this->formatRegex, $this->msg) === 1;
245 return count($this->lengthyLines) === 0;
254 return $this->lengthyLines;
263 return in_array($this->
type, self::$validTypes);
272 return self::$validTypes;
281 return $this->maxLineLength;
293 $this->maxLineLength = (int)$len;
305 if ($part && in_array($part, $this->validMsgParts)) {
309 throw new UnexpectedValueException(
"`$part` not a valid message part.");
321 foreach (explode(
"\n", rtrim($msg)) as $line) {
322 if (substr($line, 0, 1) !==
'#') {
327 return implode(
"\n", $msg_arr);
339 $lines = explode(
"\n", $msg);
340 $lengthy_lines = array();
342 foreach ($lines as $i => $line) {
343 if (strlen($line) > $max_len) {
344 $lengthy_lines[] = ++$i;
348 return $lengthy_lines;
354 return $this->getMsg();
setMaxLineLength($len)
Sets the max line length allowed.
getOriginalMsg()
Return the original message.
getPart($part)
Get part of the message.
shouldIgnore()
Should this msg be ignored for formatting?
static removeComments($msg)
Removes all lines that start with #.
static getValidTypes()
Return all valid types.
isValidLineLength()
Are any of the lines too long?
setMsg($msg)
Sets the active message.
isValid()
Are all parts of the message valid.
static findLengthyLines($msg, $max_len)
Returns an array of line numbers > $max_len.
getLengthyLines()
Get the line number of lines that are too long.
getMaxLineLength()
Return the max line length.
__construct($msg=null)
Checks if a commit message is in the correct format.
getMsg()
Return the processed message.
isValidType()
Is the type valid.
isValidFormat()
Whether the message format conforms to our standards.