Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Recurses each directory and runs PHP's lint function against each file
  5. * to test for parse errors.
  6. *
  7. * @param string $dir the directory you would like to start from
  8. * @return array the files that did not pass the test
  9. */
  10. function lint( $dir = 'C:\dev\\' )
  11. {
  12. static $failed = array();
  13.  
  14. foreach ( new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS) as $path => $objSplFileInfo )
  15. {
  16. // recurse if dir
  17. if ( $objSplFileInfo->isDir() )
  18. {
  19. if ( stristr( $objSplFileInfo->getFileName(), '.svn' ) !== false )
  20. {
  21. continue;
  22. }
  23.  
  24. lint( $objSplFileInfo->getPathName() );
  25.  
  26. continue;
  27. }
  28.  
  29. // are there any non-dirs that aren't files?
  30. if ( !$objSplFileInfo->isFile() )
  31. {
  32. throw new UnexpectedValueException( 'Not a dir and not a file?' );
  33. }
  34.  
  35. // skip non-php files
  36. if ( preg_match( '#\.php$#', $objSplFileInfo->getFileName() ) !== 1 )
  37. {
  38. continue;
  39. }
  40.  
  41. // perform the lint check
  42. $result = exec( 'php -l '. escapeshellarg($objSplFileInfo) );
  43. if ( preg_match( '#^No syntax errors detected in#', $result ) !== 1 )
  44. {
  45. $failed[ $objSplFileInfo->getPathName() ] = $result;
  46. echo $failed, ' = ', $result;
  47. }
  48.  
  49. }
  50.  
  51. return $failed;
  52. }
  53.  
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement