23 private $validMsgParts = array(
63 private $originalMsg =
'';
77 private $lengthyLines;
84 private static $validTypes = array(
107 private $validComponents = array(
123 private $ignoreRegex =
'/^Merge |^Revert /i';
142 private $formatRegex =
"/^(\w*)\(([\w]+)\)\: ([^\n]*)(\n\n?(.*))?$/is";
148 private $maxLineLength = 160;
169 $this->originalMsg = $msg;
171 $msg = str_replace(array(
"\r",
"\n"),
"\n", $msg);
172 $this->msg = $this->removeComments($msg);
191 return $this->originalMsg;
200 return preg_match($this->ignoreRegex, $this->msg) === 1;
208 private function processMsg() {
211 preg_match($this->formatRegex, $this->msg, $matches);
212 foreach ($this->validMsgParts as $i => $part) {
213 $this->$part = isset($matches[$i]) ? $matches[$i] :
'';
216 $this->lengthyLines = $this->findLengthyLines($this->msg, $this->maxLineLength);
225 return $this->isValidFormat() &&
226 $this->isValidLineLength() &&
227 $this->isValidType();
236 return preg_match($this->formatRegex, $this->msg) === 1;
247 return count($this->lengthyLines) === 0;
256 return $this->lengthyLines;
265 return in_array($this->
type, self::$validTypes);
274 return self::$validTypes;
283 return $this->maxLineLength;
295 $this->maxLineLength = (int)$len;
307 if ($part && in_array($part, $this->validMsgParts)) {
323 foreach (explode(
"\n", rtrim($msg)) as $line) {
324 if (substr($line, 0, 1) !==
'#') {
329 return implode(
"\n", $msg_arr);
341 $lines = explode(
"\n", $msg);
342 $lengthy_lines = array();
344 foreach ($lines as $i => $line) {
345 if (strlen($line) > $max_len) {
346 $lengthy_lines[] = ++$i;
350 return $lengthy_lines;
356 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.
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
getMaxLineLength()
Return the max line length.