-
-
Save nfreear/4216921 to your computer and use it in GitHub Desktop.
Applies PHP's lint check to all PHP files in a directory.
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 // https://gist.github.com/1846220 | |
define('LINT', '\xampp\php\php -l'); | |
/** | |
* Recurses each directory and runs PHP's lint function against each file | |
* to test for parse errors. | |
* | |
* @param string $dir the directory you would like to start from | |
* @return array the files that did not pass the test | |
*/ | |
function lint( $dir = 'C:\dev\\' ) | |
{ | |
static $failed = array(); | |
foreach ( new RecursiveDirectoryIterator($dir) as $path => $objSplFileInfo ) | |
{ | |
// recurse if dir | |
if ( $objSplFileInfo->isDir() ) | |
{ | |
if ( stristr( $objSplFileInfo->getFileName(), '.svn' ) !== false ) | |
{ | |
continue; | |
} | |
lint( $objSplFileInfo->getPathName() ); | |
continue; | |
} | |
// are there any non-dirs that aren't files? | |
if ( !$objSplFileInfo->isFile() ) | |
{ | |
throw new UnexpectedValueException( 'Not a dir and not a file?' ); | |
} | |
// skip non-php files | |
if ( preg_match( '#\.php$#', $objSplFileInfo->getFileName() ) !== 1 ) | |
{ | |
continue; | |
} | |
// perform the lint check | |
$result = exec( LINT .' '. escapeshellarg($objSplFileInfo) ); | |
if ( preg_match( '#^No syntax errors detected in#', $result ) !== 1 ) | |
{ | |
$failed[ $objSplFileInfo->getPathName() ] = $result; | |
echo $failed, ' = ', $result; | |
} | |
} | |
return $failed; | |
} | |
if ($argc < 2) die('Error. Sorry expecting CLI mode and an input path.'); | |
$result = lint($argv[1]); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment