-
-
Save gooh/5856488 to your computer and use it in GitHub Desktop.
A simple linter for code snippets. Writes the snippet to a temp file and then captures and returns the output of php's commandline lint
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 | |
function lint($code) | |
{ | |
$code = strpos($code, '<?php') === 0 ? $code : "<?php $code"; | |
$filename = tempnam(sys_get_temp_dir(), 'lnt'); | |
file_put_contents($filename, $code); | |
exec(PHP_BINARY . " -l $filename", $errors); | |
unlink($filename); | |
return $errors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment