4 use UnexpectedValueException;
21 private $validMsgParts = array(
61 private $originalMsg =
'';
75 private $lengthyLines;
82 private static $validTypes = array(
99 private $validComponents = array(
115 private $ignoreRegex =
'/^Merge |^Revert /i';
134 private $formatRegex =
"/^(\w*)\(([\w]+)\)\: ([^\n]*)(\n\n?(.*))?$/is";
140 private $maxLineLength = 160;
161 $this->originalMsg = $msg;
163 $msg = str_replace(array(
"\r",
"\n"),
"\n", $msg);
164 $this->msg = $this->removeComments($msg);
183 return $this->originalMsg;
192 return preg_match($this->ignoreRegex, $this->msg) === 1;
200 private function processMsg() {
203 preg_match($this->formatRegex, $this->msg, $matches);
204 foreach ($this->validMsgParts as $i => $part) {
205 $this->$part = isset($matches[$i]) ? $matches[$i] :
'';
208 $this->lengthyLines = $this->findLengthyLines($this->msg, $this->maxLineLength);
217 return $this->isValidFormat() &&
218 $this->isValidLineLength() &&
219 $this->isValidType();
228 return preg_match($this->formatRegex, $this->msg) === 1;
239 return count($this->lengthyLines) === 0;
248 return $this->lengthyLines;
257 return in_array($this->
type, self::$validTypes);
266 return self::$validTypes;
275 return $this->maxLineLength;
287 $this->maxLineLength = (int)$len;
299 if ($part && in_array($part, $this->validMsgParts)) {
303 throw new UnexpectedValueException(
"`$part` not a valid message part.");
315 foreach (explode(
"\n", rtrim($msg)) as $line) {
316 if (substr($line, 0, 1) !==
'#') {
321 return implode(
"\n", $msg_arr);
333 $lines = explode(
"\n", $msg);
334 $lengthy_lines = array();
336 foreach ($lines as $i => $line) {
337 if (strlen($line) > $max_len) {
338 $lengthy_lines[] = ++$i;
342 return $lengthy_lines;
348 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.