Skip to content

Instantly share code, notes, and snippets.

@felipelavinz
Last active January 27, 2017 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipelavinz/1c553f0d52195d23cc84049fac81cc21 to your computer and use it in GitHub Desktop.
Save felipelavinz/1c553f0d52195d23cc84049fac81cc21 to your computer and use it in GitHub Desktop.
PHP Syntax check
image: ubuntu:12.04
before_script:
- apt-get update
- apt-get install -y php5-cli
test:
script:
- php syntax-check.php
<?php
$exit_code = 0;
$paths = array(
'htdocs/wp-content/themes/my-custom-theme',,
'htdocs/wp-content/plugins',
'htdocs/wp-content/mu-plugins',
);
$files = array();
$lint_output = array();
foreach ( $paths as $path ) {
$Directory = new RecursiveDirectoryIterator( $path );
$Iterator = new RecursiveIteratorIterator( $Directory );
$Regex = new RegexIterator($Iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);
foreach ( $Regex as $file ) {
$files[] = $file[0];
}
}
$i = 0;
foreach ( $files as $file ) {
$return = 0;
$output = array();
exec("php -l {$file}", $lint_output, $return);
if ( $return !== 0 ) {
$exit_code = 1;
}
++$i;
}
exit( $exit_code );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment