From 6a4f669fafaa37be1db201cee386c92f5c102409 Mon Sep 17 00:00:00 2001 From: Sink Date: Tue, 19 Nov 2024 09:52:16 +0800 Subject: [PATCH] feat: #33 php artisan lint --- README.md | 11 +++++++-- src/LintCodeCommand.php | 8 ++++--- src/LintCommand.php | 47 +++++++++++++++++++++++++++++++++++++ src/LintServiceProvider.php | 1 + 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 src/LintCommand.php diff --git a/README.md b/README.md index 35c67eb..d683623 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,17 @@ composer require --dev laravel-fans/lint php artisan lint:publish ``` +You will find `phpcs.xml` and `phpmd.xml` in your project, feel free to change it. + ## usage +### lint all + +``` +php artisan lint +php artisan lint --fix +``` + ### lint code ```shell @@ -31,8 +40,6 @@ php artisan lint:pmd php artisan lint:staged ``` -The default standard is `phpcs.xml`, feel free to change it. - ### lint route URI ```shell diff --git a/src/LintCodeCommand.php b/src/LintCodeCommand.php index 4e4aa26..7c98539 100644 --- a/src/LintCodeCommand.php +++ b/src/LintCodeCommand.php @@ -34,9 +34,11 @@ public function handle() $code = $this->call('lint:phpcs', [ 'files' => $this->argument('files'), '--fix' => $this->option('fix') ]); - $code += $this->call('lint:pmd', [ - 'files' => $this->argument('files') - ]); + if (!$this->option('fix')) { + $code += $this->call('lint:pmd', [ + 'files' => $this->argument('files') + ]); + } return $code; } } diff --git a/src/LintCommand.php b/src/LintCommand.php new file mode 100644 index 0000000..9ab4973 --- /dev/null +++ b/src/LintCommand.php @@ -0,0 +1,47 @@ +call('lint:phpcs', [ + 'files' => $this->argument('files'), '--fix' => $this->option('fix') + ]); + if (!$this->option('fix')) { + $code += $this->call('lint:pmd', [ + 'files' => $this->argument('files') + ]); + $code += $this->call('lint:route', [ + 'files' => $this->argument('files') + ]); + } + return $code; + } +} diff --git a/src/LintServiceProvider.php b/src/LintServiceProvider.php index ba3dad7..274bd9f 100644 --- a/src/LintServiceProvider.php +++ b/src/LintServiceProvider.php @@ -15,6 +15,7 @@ public function boot() { if ($this->app->runningInConsole()) { $this->commands([ + LintCommand::class, LintCodeCommand::class, LintPmdCommand::class, LintPhpcsCommand::class,