Last active
August 29, 2015 14:13
-
-
Save erunion/9ae01c39652950ad4be1 to your computer and use it in GitHub Desktop.
PHP linter command for Laravel 4.2.*
This file contains hidden or 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 | |
class Lint extends \Illuminate\Console\Command { | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'command:lint'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'PHP code linter.'; | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function fire() | |
{ | |
$this->check_php(dirname(dirname(dirname(__FILE__)))); | |
} | |
/** | |
* Checks syntax of PHP scripts. | |
* @param $directory The directory of files to recursively process. | |
* @return void | |
*/ | |
private function check_php($directory) | |
{ | |
$dir = opendir($directory); | |
while (false !== ($file = readdir($dir))) { | |
if (in_array($file, array('.', '..', 'public', 'vendor')) || substr($file, 0, 1) == '.') { | |
continue; | |
} | |
$filename = $directory . '/' . $file; | |
if (!is_dir($filename) && strtolower(substr($file, -4)) == ".php") { | |
$result = shell_exec('php -l ' . $filename); | |
if (strpos($result, 'No syntax errors detected in ' . $filename) === false) { | |
echo $result; | |
exit(2); | |
} | |
} | |
if (is_dir($filename)) { | |
$this->check_php($filename); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LintCommand
into yourapp/commands
folder.Artisan::add(new LintCommand);
toapp/start/artisan.php
.php artisan command:lint
.