diff --git a/src/Commands/LintCommand.php b/src/Commands/LintCommand.php index 22e29d8..528f349 100644 --- a/src/Commands/LintCommand.php +++ b/src/Commands/LintCommand.php @@ -11,6 +11,7 @@ class LintCommand extends Command { public $signature = 'rockero:lint {--json}'; + public $description = 'Run linter'; public function handle(): int @@ -19,7 +20,7 @@ public function handle(): int Linter::collect()->whenNotEmpty(function (Collection $errors) { $this->output->write($errors->toJson()); }); - + return self::SUCCESS; } @@ -34,7 +35,7 @@ public function handle(): int }); if ($errors > 0) { - $this->output->error($errors . ' ' . Str::plural('problem', $errors) . ' found'); + $this->output->error($errors.' '.Str::plural('problem', $errors).' found'); return self::INVALID; } else { diff --git a/src/Linting/LintError.php b/src/Linting/LintError.php index 1067432..cbafaa7 100644 --- a/src/Linting/LintError.php +++ b/src/Linting/LintError.php @@ -8,6 +8,6 @@ public function __construct( readonly public string $file, readonly public int $line, readonly public string $message, - ) { + ) { } } diff --git a/src/Linting/Linter.php b/src/Linting/Linter.php index abbbcfd..4243537 100644 --- a/src/Linting/Linter.php +++ b/src/Linting/Linter.php @@ -4,7 +4,6 @@ use Illuminate\Support\Collection; use Illuminate\Support\Str; -use Rockero\StarterKit\Linting\LintError; use RuntimeException; use Symfony\Component\Process\Process; @@ -12,7 +11,7 @@ class Linter { /** * Eager load all errors into a collection. - * + * * @return Collection */ public static function collect(): Collection @@ -26,35 +25,29 @@ public static function collect(): Collection /** * Lazily execute a callback over each error. - * - * @param callable(LintError) $callback + * + * @param callable(LintError) $callback */ public static function run($callback): void { /** * Parse tlint output similar to: - * + * * Lints for /User/rockero/www/laravel/app/Models/User.php * ======= * ! Imports should be ordered alphabetically. * 5 : `use Illuminate\Notifications\Notifiable;` * 6 : `use Illuminate\Foundation\Auth\User as Authenticatable;` - * */ - $file = ''; $message = ''; self::readOutput(function ($line) use (&$file, &$message, $callback) { if (Str::startsWith($line, 'Lints for')) { - $file = Str::after($line, 'Lints for ' . base_path() . '/'); - } - - elseif (Str::startsWith($line, '!')) { + $file = Str::after($line, 'Lints for '.base_path().'/'); + } elseif (Str::startsWith($line, '!')) { $message = Str::after($line, '! '); - } - - elseif ($line = Str::match('/^(\d+)/', $line)) { + } elseif ($line = Str::match('/^(\d+)/', $line)) { $callback(new LintError($file, (int) $line, $message)); } }); @@ -67,7 +60,7 @@ private static function readOutput(callable $callback): void { $process = Process::fromShellCommandline('./vendor/bin/tlint'); $output = ''; - + $process->setTimeout(null)->run(function ($type, $buffer) use ($callback, &$output) { $lines = explode("\n", $buffer); diff --git a/src/StarterKitServiceProvider.php b/src/StarterKitServiceProvider.php index 8299f2d..0268f58 100644 --- a/src/StarterKitServiceProvider.php +++ b/src/StarterKitServiceProvider.php @@ -22,9 +22,9 @@ public function boot() parent::boot(); $this->publishes([ - __DIR__ . '/../stubs/tlint.stub' => $this->app->basePath('tlint.json'), - __DIR__ . '/../stubs/pint.stub' => $this->app->basePath('pint.json'), - __DIR__ . '/../stubs/phpstan.stub' => $this->app->basePath('phpstan.neon'), + __DIR__.'/../stubs/tlint.stub' => $this->app->basePath('tlint.json'), + __DIR__.'/../stubs/pint.stub' => $this->app->basePath('pint.json'), + __DIR__.'/../stubs/phpstan.stub' => $this->app->basePath('phpstan.neon'), ], ); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index e97b3b4..efd4caf 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -13,7 +13,7 @@ protected function setUp(): void parent::setUp(); Factory::guessFactoryNamesUsing( - fn (string $modelName) => 'Rockero\\StarterKit\\Database\\Factories\\' . class_basename($modelName) . 'Factory' + fn (string $modelName) => 'Rockero\\StarterKit\\Database\\Factories\\'.class_basename($modelName).'Factory' ); }