2 require_once 'Interface/CommitListener.php';
4 class MTrackCommitCheck_BlankLines implements IMTrackCommitListener
7 function vetoCommit($msg, $files, $actions, $checker)
9 // should only have a list of files which have been updated/added. (not deleted)
11 foreach ($files as $filename) {
12 $pi = pathinfo($filename);
13 switch($pi['extension']) {
16 $fp = $checker->bridge->getFileStream($filename);
18 $res = $this->checkBlanks($filename, $fp);
22 $fp = null; // remove stream.
26 return $ret ? implode("\n", $ret) : true;
29 function postCommit($msg, $files, $actions) {
32 function checkBlanks($filename, $fp)
35 $contents = stream_get_contents($fp);
36 $lines = explode("\n",$contents);
39 foreach($lines as $l) {
40 if (strlen(trim($l))) {
48 return "Remove all the extra blank lines from $filename before committing";
52 if (($total / count($lines)) > 0.2) {
53 return "More than 20% of $filename is blank lines";