4 use UnexpectedValueException;
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)) {
311 throw new UnexpectedValueException(
"`$part` not a valid message part.");
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();
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.
if(! $display_name) $type