scanner/modules/scanner_lint.php

37 lines
1.1 KiB
PHP
Raw Normal View History

<?php
class LintModule extends ScannerModule {
function LintModule() {
$this->ScannerModule();
}
function preScan( $file ) {
parent::preScan( $file );
$output = array();
if( $file['revision'] > 0 ) {
global $svn_root, $svn_base;
exec( "svn cat -r {$file['revision']} {$svn_root}{$svn_base}/{$file['filename']} 2>/dev/null | php -l 2>/dev/null", $output, $result );
$file_contents = isset( $file['contents'] ) ? $file['contents'] : shell_exec( "svn cat -r {$file['revision']} {$svn_root}{$svn_base}/{$file['filename']} 2>/dev/null" );
} else {
exec( "php -l '{$file['filename']}' 2>/dev/null", $output, $result );
$file_contents = file( $file['filename'] );
}
if( $result != 0 ) {
foreach( $output as $linterror ) {
$matches = array();
if( preg_match( '/error:.*?on line (\d+)$/i', $linterror, $matches ) == 0 ) { continue; }
$this->fault(
array(
'file' => $file['filename'],
'line' => $matches[1],
'context' => $file_contents[$matches[1] - 1]
),
FAULT_MAJOR,
$linterror
);
}
}
}
}
addModule( new LintModule() );
?>