faults = array(); $this->blame = array(); } function fault( $object, $level, $reason = '' ) { $this->faults[] = array( 'object' => $object, 'level' => $level, 'reason' => $reason, 'svn' => $this->blame[$object['line']] ); } function parserCallback( $object ) { } function preScan( $filename ) { $this->blame = array(); $output = array(); exec( "svn blame '$filename' 2>/dev/null", $output, $result ); if( $result == 0 ) { foreach( $output as $line => $text ) { $matches = array(); preg_match( '/^\s*(\d+)\s+([^\s]+)/', $text, $matches ); $this->blame[$line + 1] = array( 'author' => $matches[2], 'revision' => $matches[1] ); } } } function postScan( $filename ) { } } function _callback( $object ) { global $modules; foreach( $modules as $module ) { $module->parserCallback( $object ); } } // Dig into the modules folder and load up what we find $module_files = scandir( 'modules' ); foreach( $module_files as $module_file ) { if( strtolower( substr( $module_file, -4 ) ) == '.php' ) { require_once( "modules/{$module_file}" ); } } $parser = new PHPParser( PHPPARSER_FETCH_EXPRESSIONS | PHPPARSER_FETCH_CALLS | PHPPARSER_FETCH_INTERNAL | PHPPARSER_FETCH_CONSTRUCTS ); $parser->registerCallback( '_callback' ); $files = array(); for( $i = 1; $i < $argc; $i++ ) { if( file_exists( $argv[$i] ) && strtolower( substr( $argv[$i], -4 ) ) == '.php' ) { $files[] = $argv[$i]; } } if( count( $files ) == 0 ) { die( "No files were specified.\n" ); } foreach( $files as $file ) { foreach( $modules as $module ) { $module->preScan( $file ); } $parser->parseFile( $file ); } foreach( $modules as $module ) { foreach( $module->faults as $fault ) { $svn = serialize( $fault['svn'] ); printf( "%s %s - %s\n -- %s:%d, %s r%d\n", get_class( $module ), $fault['level'], $fault['reason'], $fault['object']['file'], $fault['object']['line'], isset( $fault['svn']['author'] ) ? $fault['svn']['author'] : '?', isset( $fault['svn']['revision'] ) ? $fault['svn']['revision'] : '?' ); } } ?>