You've already forked Atomcms-edit
75 lines
2.2 KiB
PHP
Executable File
75 lines
2.2 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Symfony\Component\Process\Process;
|
|
|
|
class FixCodeCommand extends Command
|
|
{
|
|
#[\Override]
|
|
protected $signature = 'atom:fix-code {--dirty : Only fix changed files}';
|
|
|
|
#[\Override]
|
|
protected $description = 'Automatically fix code style and syntax errors in the project';
|
|
|
|
public function handle(): int
|
|
{
|
|
$this->info('🛠️ Starting Atom Code Fixer...');
|
|
|
|
// 1. Check if Laravel Pint is installed (Standard in Laravel 9+)
|
|
if (! file_exists(base_path('vendor/bin/pint'))) {
|
|
$this->warn('⚠️ Laravel Pint not found. Installing...');
|
|
$this->runProcess(['composer', 'require', 'laravel/pint', '--dev']);
|
|
}
|
|
|
|
// 2. Run Pint (Fixes styling, unused imports, spacing)
|
|
$this->info('🎨 Running Code Style Fixer (Pint)...');
|
|
|
|
$params = ['vendor/bin/pint'];
|
|
if ($this->option('dirty')) {
|
|
$params[] = '--dirty';
|
|
}
|
|
|
|
$process = new Process($params, base_path());
|
|
$process->setTimeout(300);
|
|
$process->run(function ($type, $buffer) {
|
|
$this->output->write($buffer);
|
|
});
|
|
|
|
if (! $process->isSuccessful()) {
|
|
$this->error('❌ Pint encountered some issues.');
|
|
} else {
|
|
$this->info('✅ Code style fixed!');
|
|
}
|
|
|
|
// 3. Optional: Run PHPStan/Larastan if available (For deep logic checks)
|
|
if (file_exists(base_path('vendor/bin/phpstan'))) {
|
|
$this->info("\n🧠 Running Static Analysis (PHPStan)...");
|
|
$analyze = new Process(['vendor/bin/phpstan', 'analyse', 'app'], base_path());
|
|
$analyze->setTimeout(300);
|
|
$analyze->run(function ($type, $buffer) {
|
|
$this->output->write($buffer);
|
|
});
|
|
}
|
|
|
|
$this->newLine();
|
|
$this->info('🚀 Code cleanup finished.');
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* @param array<int, string> $command
|
|
*/
|
|
private function runProcess(array $command): void
|
|
{
|
|
$process = new Process($command, base_path());
|
|
$process->run(function ($type, $buffer) {
|
|
$this->output->write($buffer);
|
|
});
|
|
}
|
|
}
|