Skip to content

Instantly share code, notes, and snippets.

@viccherubini
Created December 13, 2009 13:53
Show Gist options
  • Save viccherubini/255421 to your computer and use it in GitHub Desktop.
Save viccherubini/255421 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
use strict;
my $found_error = 0;
sub msg {
my $msg = shift @_;
print $msg . "\n";
}
sub trim() {
my $string = shift @_;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
# Find all of the files
my @php_file_list = split(/\n/, `find . -name "*.php" -o -name "*.phtml" -o -name "*.php3" -o -name "*.php4" -o -name "*.php5"`);
foreach my $php_file ( @php_file_list ) {
$php_file = &trim($php_file);
my @php_output = split(/\n/, `php -l $php_file`);
my $po_len = scalar @php_output;
my $last_line = $php_output[$po_len-1];
if ( $last_line =~ m/^Errors parsing/i ) {
$found_error = 1;
shift @php_output; # Shift off first newline
pop @php_output; # Pop off the "Errors parsing" text
&msg("Failed to checkin \033[1;31m$php_file\033[m, PHP said: \033[1;33m@php_output\033[m");
}
}
if ( 0 == $found_error ) {
&msg("\033[1;32mAll syntax checks successful!\033[m");
}
exit $found_error;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment