Skip to content

Commit 4b46b93

Browse files
committed
style: #16 use phpmd myself
1 parent a27a434 commit 4b46b93

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

.github/workflows/laravel-6.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ jobs:
2929
composer require orchestra/testbench:^v4 --dev
3030
./vendor/bin/phpunit --coverage-clover coverage.xml --coverage-filter src/ tests/
3131
- name: Lint
32-
run: ./vendor/bin/phpcs --standard=PSR12 src/ tests/
32+
run: |
33+
./vendor/bin/phpcs --standard=PSR12 src/ tests/
34+
./vendor/bin/phpmd src/ text src/stubs/phpmd.xml --exclude vendor
3335
- name: codecov
3436
uses: codecov/codecov-action@v1
3537
with:

.github/workflows/laravel-7.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ jobs:
2929
composer require orchestra/testbench:^v5 --dev
3030
./vendor/bin/phpunit --coverage-clover coverage.xml --coverage-filter src/ tests/
3131
- name: Lint
32-
run: ./vendor/bin/phpcs --standard=PSR12 src/ tests/
32+
run: |
33+
./vendor/bin/phpcs --standard=PSR12 src/ tests/
34+
./vendor/bin/phpmd src/ text src/stubs/phpmd.xml --exclude vendor
3335
- name: codecov
3436
uses: codecov/codecov-action@v1
3537
with:

.github/workflows/laravel-8.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ jobs:
2929
composer require orchestra/testbench:^v6 --dev
3030
./vendor/bin/phpunit --coverage-clover coverage.xml --coverage-filter src/ tests/
3131
- name: Lint
32-
run: ./vendor/bin/phpcs --standard=PSR12 src/ tests/
32+
run: |
33+
./vendor/bin/phpcs --standard=PSR12 src/ tests/
34+
./vendor/bin/phpmd src/ text src/stubs/phpmd.xml --exclude vendor
3335
- name: codecov
3436
uses: codecov/codecov-action@v1
3537
with:

src/LintRouteCommand.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,9 @@ class LintRouteCommand extends Command
2929
*
3030
* @return int
3131
*/
32-
public function handle()
32+
public function handle(): int
3333
{
34-
if ($this->option('file') == 'auto') {
35-
Artisan::call('route:list', ['--json' => true]);
36-
$json = Artisan::output();
37-
} else {
38-
$json = File::get($this->option('file'));
39-
}
34+
$json = $this->getRouteJson();
4035
$routes = json_decode($json, true);
4136
foreach ($routes as $route) {
4237
if ($route['uri'] == '/') {
@@ -51,10 +46,10 @@ public function handle()
5146
$tmp = explode('/', ltrim($route['uri'], '/'));
5247
foreach ($tmp as $piece) {
5348
// ignore variable
54-
if (preg_match('/^\{[^{]+\}$/', $piece)) {
49+
if (preg_match('/^{[^{]+}$/', $piece)) {
5550
continue;
5651
}
57-
if (!preg_match('/^[a-z0-9]+(\-[a-z0-9]+)*$/', $piece)) {
52+
if (!preg_match('/^[a-z0-9]+(-[a-z0-9]+)*$/', $piece)) {
5853
$this->error('user-friendly URL should follow domain rules: '
5954
. 'lowercase ASCII letters, digits, and hyphens (a-z, 0–9, -)');
6055
return 1;
@@ -64,4 +59,13 @@ public function handle()
6459

6560
return 0;
6661
}
62+
63+
private function getRouteJson(): string
64+
{
65+
if ($this->option('file') == 'auto') {
66+
Artisan::call('route:list', ['--json' => true]);
67+
return Artisan::output();
68+
}
69+
return File::get($this->option('file'));
70+
}
6771
}

0 commit comments

Comments
 (0)