for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/**
* This file is part of Laravel Code Analyse.
*
* (c) Nuno Maduro <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NunoMaduro\LaravelCodeAnalyse\Console;
use function substr;
use function implode;
use function strtoupper;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Illuminate\Console\Application as Artisan;
final class CodeAnalyseCommand extends Command
{
* @var \Illuminate\Foundation\Application
protected $laravel;
* {@inheritdoc}
protected $signature = 'code:analyse {--level=1}';
protected $description = 'Analyses source code';
public function handle(): void
$level = is_string($this->option('level')) ? $this->option('level') : 'max';
is_string($this->option('level'))
false
$params = [
static::phpstanBinary(),
'analyse',
'--level='.$level,
'--autoload-file='.$this->laravel->basePath('vendor/autoload.php'),
'--configuration='.__DIR__.'/../../extension.neon',
$this->laravel['path'],
];
$process = new Process(implode(' ', $params), $this->laravel->basePath('vendor/bin'));
if (Process::isTtySupported()) {
$process->setTty(true);
}
$process->setTimeout(null);
$process->start();
foreach ($process as $type => $data) {
$this->output->writeln($data);
* @return string
private static function phpstanBinary(): string
return sprintf('%s %s', Artisan::phpBinary(), 'phpstan');