Fixed a bug with module loading. Fixed a bug that prevented a file's local function definitions not to be picked up. Added the base path and quiet options. Mantis: 2691
git-svn-id: file:///srv/svn/scanner/trunk@4 a0501263-5b7a-4423-a8ba-1edf086583e7
This commit is contained in:
parent
5531fb7a24
commit
d0714c149b
2 changed files with 29 additions and 8 deletions
|
@ -16,7 +16,7 @@ function FunctionsModule_callback_local( $object ) {
|
|||
if( !isset( $FunctionsModule_local_functions[$file] ) ) {
|
||||
$FunctionsModule_local_functions[$file] = array();
|
||||
}
|
||||
$FunctionsModule_local_functions[$file][] = array(
|
||||
$FunctionsModule_local_functions[$file][strtolower( $object['name'] )] = array(
|
||||
'used' => 0,
|
||||
'file' => $object['file']
|
||||
);
|
||||
|
@ -39,7 +39,7 @@ class FunctionsModule extends ScannerModule {
|
|||
global $base_path;
|
||||
$parser = new PHPParser( PHPPARSER_FETCH_FUNCTIONS );
|
||||
$parser->registerCallback( 'FunctionsModule_callback_global' );
|
||||
$parser->registerCallback( 'FunctionsModule_callback_local' );
|
||||
//$parser->registerCallback( 'FunctionsModule_callback_local' );
|
||||
$this->include_paths = array();
|
||||
$paths = array();
|
||||
$path = realpath( $base_path );
|
||||
|
@ -99,7 +99,7 @@ class FunctionsModule extends ScannerModule {
|
|||
if( !in_array( $object['name'], array_keys( $FunctionsModule_functions ) ) ) {
|
||||
if(
|
||||
!in_array( $object['name'], $this->internal_functions )
|
||||
&& !in_array( $object['name'], $FunctionsModule_local_functions[filename( $object['file'] )] )
|
||||
&& !in_array( $object['name'], array_keys( $FunctionsModule_local_functions[filename( $object['file'] )] ) )
|
||||
) {
|
||||
$this->fault( $object, FAULT_MAJOR, "Undefined function '{$object['name']}'" );
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ class FunctionsModule extends ScannerModule {
|
|||
$FunctionsModule_local_functions[filename( $filename)] = array();
|
||||
$parser = new PHPParser( PHPPARSER_FETCH_FUNCTIONS );
|
||||
$parser->registerCallback( 'FunctionsModule_callback_local' );
|
||||
$parser->parse( $filename );
|
||||
$parser->parseFile( $filename );
|
||||
$this->included_files = array();
|
||||
}
|
||||
}
|
||||
|
|
29
scanner.php
29
scanner.php
|
@ -10,9 +10,14 @@ $stderr = fopen( 'php://stderr', 'w' );
|
|||
$config = array(
|
||||
'svn' => false,
|
||||
'modules' => array(),
|
||||
'quiet' => false,
|
||||
);
|
||||
$help = "Usage: {$argv[0]} [options] file|path [file|path ...]
|
||||
Options:
|
||||
-b Set the base path for the scan. Useful if you want
|
||||
--base-path to scan individual files in a code base that don't
|
||||
live in the project's base directory.
|
||||
|
||||
-h Display this usage information
|
||||
--help
|
||||
|
||||
|
@ -20,6 +25,9 @@ Options:
|
|||
--module modulename parameter is not specified, all available modules
|
||||
will be loaded.
|
||||
|
||||
-q Suppresses all progress output
|
||||
--quiet
|
||||
|
||||
--svn Enables SVN integration
|
||||
";
|
||||
|
||||
|
@ -81,8 +89,10 @@ function filename( $filename ) {
|
|||
return $filename;
|
||||
}
|
||||
function err( $string ) {
|
||||
global $stderr;
|
||||
fputs( $stderr, $string );
|
||||
global $stderr, $config;
|
||||
if( $config['quiet'] === false ) {
|
||||
fputs( $stderr, $string );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -91,6 +101,13 @@ $files = array();
|
|||
$base_path = false;
|
||||
for( $i = 1; $i < $argc; $i++ ) {
|
||||
switch( $argv[$i] ) {
|
||||
case '-b':
|
||||
case '--base-path':
|
||||
$new_base = $argv[++$i];
|
||||
if( is_dir( $new_base ) ) {
|
||||
$base_path = realpath( $new_base ) . '/';
|
||||
}
|
||||
break;
|
||||
case '-h':
|
||||
case '--help':
|
||||
die( $help );
|
||||
|
@ -99,6 +116,10 @@ for( $i = 1; $i < $argc; $i++ ) {
|
|||
case '--module':
|
||||
$config['modules'][] = $argv[++$i];
|
||||
break;
|
||||
case '-q':
|
||||
case '--quiet':
|
||||
$config['quiet'] = true;
|
||||
break;
|
||||
case '--svn':
|
||||
$config['svn'] = true;
|
||||
break;
|
||||
|
@ -108,7 +129,7 @@ for( $i = 1; $i < $argc; $i++ ) {
|
|||
$files[] = $argv[$i];
|
||||
} else if( is_dir( $argv[$i] ) ) {
|
||||
$base_path = ( $base_path === false ) ? realpath( $argv[$i] ) . '/' : $base_path;
|
||||
exec( "find $base_path -iname '*.php' 2>/dev/null", $output, $result );
|
||||
exec( "find {$argv[$i]} -iname '*.php' 2>/dev/null", $output, $result );
|
||||
$files = array_merge( $files, $output );
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +145,7 @@ foreach( $module_files as $module_file ) {
|
|||
if( strtolower( substr( $module_file, -4 ) ) == '.php' ) {
|
||||
$module = substr( $module_file, 0, strlen( $module_file ) - 4 );
|
||||
if(
|
||||
count( $modules ) == 0
|
||||
count( $config['modules'] ) == 0
|
||||
|| ( in_array( $module, $config['modules'] ) )
|
||||
) {
|
||||
require_once( "modules/{$module_file}" );
|
||||
|
|
Loading…
Reference in a new issue