Last active
January 27, 2017 13:06
-
-
Save felipelavinz/1c553f0d52195d23cc84049fac81cc21 to your computer and use it in GitHub Desktop.
PHP Syntax check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: ubuntu:12.04 | |
before_script: | |
- apt-get update | |
- apt-get install -y php5-cli | |
test: | |
script: | |
- php syntax-check.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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