Skip to content

Commit 6a4f669

Browse files
committed
feat: #33 php artisan lint
1 parent d88ea4e commit 6a4f669

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ composer require --dev laravel-fans/lint
1717
php artisan lint:publish
1818
```
1919

20+
You will find `phpcs.xml` and `phpmd.xml` in your project, feel free to change it.
21+
2022
## usage
2123

24+
### lint all
25+
26+
```
27+
php artisan lint
28+
php artisan lint --fix
29+
```
30+
2231
### lint code
2332

2433
```shell
@@ -31,8 +40,6 @@ php artisan lint:pmd
3140
php artisan lint:staged
3241
```
3342

34-
The default standard is `phpcs.xml`, feel free to change it.
35-
3643
### lint route URI
3744

3845
```shell

src/LintCodeCommand.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ public function handle()
3434
$code = $this->call('lint:phpcs', [
3535
'files' => $this->argument('files'), '--fix' => $this->option('fix')
3636
]);
37-
$code += $this->call('lint:pmd', [
38-
'files' => $this->argument('files')
39-
]);
37+
if (!$this->option('fix')) {
38+
$code += $this->call('lint:pmd', [
39+
'files' => $this->argument('files')
40+
]);
41+
}
4042
return $code;
4143
}
4244
}

src/LintCommand.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace LaravelFans\Lint;
4+
5+
use FilesystemIterator;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\File;
8+
9+
class LintCommand extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'lint
17+
{files?*}
18+
{--fix : automatic fix}';
19+
20+
/**
21+
* The console command description.
22+
*
23+
* @var string
24+
*/
25+
protected $description = 'Check code style of code(including tests and routes)';
26+
27+
/**
28+
* Execute the console command.
29+
*
30+
* @return void
31+
*/
32+
public function handle()
33+
{
34+
$code = $this->call('lint:phpcs', [
35+
'files' => $this->argument('files'), '--fix' => $this->option('fix')
36+
]);
37+
if (!$this->option('fix')) {
38+
$code += $this->call('lint:pmd', [
39+
'files' => $this->argument('files')
40+
]);
41+
$code += $this->call('lint:route', [
42+
'files' => $this->argument('files')
43+
]);
44+
}
45+
return $code;
46+
}
47+
}

src/LintServiceProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function boot()
1515
{
1616
if ($this->app->runningInConsole()) {
1717
$this->commands([
18+
LintCommand::class,
1819
LintCodeCommand::class,
1920
LintPmdCommand::class,
2021
LintPhpcsCommand::class,

0 commit comments

Comments
 (0)