Skip to content

Commit 462db8d

Browse files
committed
feat: #32 pint
1 parent 150a6a8 commit 462db8d

17 files changed

+103
-17
lines changed

.github/workflows/laravel-11.yml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
run: |
3131
./vendor/bin/phpcs --standard=PSR12 src/ tests/
3232
./vendor/bin/phpmd . text src/stubs/phpmd.xml
33+
./vendor/bin/pint --test --config src/stubs/pint.json
3334
-
3435
name: Upload coverage to Codecov
3536
uses: codecov/codecov-action@v4

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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.
20+
You will find `pint.json`, `phpcs.xml` and `phpmd.xml` in your project, feel free to change it.
2121

2222
## usage
2323

@@ -35,15 +35,16 @@ php artisan lint:code
3535
php artisan lint:code --fix
3636
php artisan lint:code app/ tests/
3737
php artisan lint:code app/ tests/ --fix
38+
php artisan lint:pint
3839
php artisan lint:phpcs
3940
php artisan lint:pmd
4041
php artisan lint:staged
4142
```
4243

43-
### lint route URI
44+
### lint route
4445

4546
```shell
4647
php artisan lint:route
4748
```
4849

49-
Slug(kebab-case) standard: lowercase ASCII letters, digits, and hyphens (a-z, 0–9, -)
50+
Slug(kebab-case) URI standard: lowercase ASCII letters, digits, and hyphens (a-z, 0–9, -)

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"require": {
3232
"ext-json": "*",
3333
"illuminate/support": ">=v9",
34+
"laravel/pint": ">=v1",
3435
"phpmd/phpmd": ">=2.10",
3536
"squizlabs/php_codesniffer": ">=3.5"
3637
},

src/LintCodeCommand.php

-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace LaravelFans\Lint;
44

5-
use FilesystemIterator;
65
use Illuminate\Console\Command;
7-
use Illuminate\Support\Facades\File;
86

97
class LintCodeCommand extends Command
108
{

src/LintCommand.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace LaravelFans\Lint;
44

5-
use FilesystemIterator;
65
use Illuminate\Console\Command;
7-
use Illuminate\Support\Facades\File;
86

97
class LintCommand extends Command
108
{
@@ -34,7 +32,15 @@ public function handle()
3432
$code = $this->call('lint:phpcs', [
3533
'files' => $this->argument('files'), '--fix' => $this->option('fix')
3634
]);
35+
if ($this->option('fix')) {
36+
$code = $this->call('lint:pint', [
37+
'files' => $this->argument('files'), '--repair' => true
38+
]);
39+
}
3740
if (!$this->option('fix')) {
41+
$code = $this->call('lint:pint', [
42+
'files' => $this->argument('files'), '--test' => true
43+
]);
3844
$code += $this->call('lint:pmd', [
3945
'files' => $this->argument('files')
4046
]);

src/LintPhpcsCommand.php

-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace LaravelFans\Lint;
44

5-
use FilesystemIterator;
65
use Illuminate\Console\Command;
7-
use Illuminate\Support\Facades\File;
86

97
class LintPhpcsCommand extends Command
108
{

src/LintPintCommand.php

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace LaravelFans\Lint;
4+
5+
use Illuminate\Console\Command;
6+
7+
class LintPintCommand extends Command
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'lint:pint
15+
{--test}
16+
{--repair}
17+
{--config=pint.json}
18+
{files?*}';
19+
20+
/**
21+
* The console command description.
22+
*
23+
* @var string
24+
*/
25+
protected $description = 'Lint by pint';
26+
27+
/**
28+
* Execute the console command.
29+
*
30+
* @return void
31+
*/
32+
public function handle()
33+
{
34+
$files = empty($this->argument('files')) ? ['.'] : $this->argument('files');
35+
$command = "vendor" . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "pint";
36+
$command .= " --config=" . $this->option('config');
37+
if ($this->option('test')) {
38+
$command .= ' --test';
39+
}
40+
if ($this->option('repair')) {
41+
$command .= ' --repair';
42+
}
43+
exec(
44+
$command . ' ' . implode(' ', $files),
45+
$output,
46+
$code
47+
);
48+
foreach ($output as $line) {
49+
$this->line($line);
50+
}
51+
return $code;
52+
}
53+
}

src/LintPmdCommand.php

-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace LaravelFans\Lint;
44

5-
use FilesystemIterator;
65
use Illuminate\Console\Command;
7-
use Illuminate\Support\Facades\File;
86

97
class LintPmdCommand extends Command
108
{

src/LintPublishCommand.php

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public function handle()
3030
{
3131
$basePath = $this->laravel->basePath();
3232

33+
if (!File::exists($basePath . '/pint.json')) {
34+
File::copy(__DIR__ . '/stubs/pint.json', $basePath . '/pint.json');
35+
}
3336
if (!File::exists($basePath . '/phpcs.xml')) {
3437
File::copy(__DIR__ . '/stubs/phpcs.xml', $basePath . '/phpcs.xml');
3538
}

src/LintServiceProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function boot()
1717
$this->commands([
1818
LintCommand::class,
1919
LintCodeCommand::class,
20+
LintPintCommand::class,
2021
LintPmdCommand::class,
2122
LintPhpcsCommand::class,
2223
LintPublishCommand::class,

src/LintStagedCommand.php

-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace LaravelFans\Lint;
44

5-
use FilesystemIterator;
65
use Illuminate\Console\Command;
7-
use Illuminate\Support\Facades\File;
86

97
class LintStagedCommand extends Command
108
{

src/stubs/git-pre-commit

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
FILES=$(git diff --diff-filter=d --name-only HEAD | { grep '.php$' || true; })
44
for file in $FILES; do
5+
./vendor/bin/phpcs --config=pint.json --repair "$file"
6+
./vendor/bin/phpcbf --extensions=php --standard=phpcs.xml "$file"
57
./vendor/bin/phpcs --extensions=php --standard=phpcs.xml "$file"
68
./vendor/bin/phpmd "$file" text phpmd.xml
79
done

src/stubs/pint.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"preset": "psr12"
3+
}

tests/LintPhpcsCommandTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace LaravelFans\Lint\Tests;
44

5-
use Illuminate\Support\Facades\File;
65
use phpmock\MockBuilder;
7-
use phpmock\functions\FixedValueFunction;
86

97
class LintPhpcsCommandTest extends TestCase
108
{

tests/LintPintCommandTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace LaravelFans\Lint\Tests;
4+
5+
use phpmock\MockBuilder;
6+
7+
class LintPintCommandTest extends TestCase
8+
{
9+
public function testLintPintWithoutArgs()
10+
{
11+
$builder = new MockBuilder();
12+
$builder->setNamespace('\\LaravelFans\\Lint')
13+
->setName("exec")
14+
->setFunction(
15+
function ($command, &$output, &$code) {
16+
$this->assertEquals("vendor/bin/pint --config=pint.json .", $command);
17+
$output = [];
18+
$code = 0;
19+
}
20+
);
21+
$mock = $builder->build();
22+
$mock->enable();
23+
$this->artisan('lint:pint')->assertExitCode(0);
24+
$mock->disable();
25+
}
26+
}

tests/LintPmdCommandTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace LaravelFans\Lint\Tests;
44

5-
use Illuminate\Support\Facades\File;
65
use phpmock\MockBuilder;
7-
use phpmock\functions\FixedValueFunction;
86

97
class LintPmdCommandTest extends TestCase
108
{

tests/LintPublishCommandTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function testGitExists()
2121
$laravelPath = __DIR__ . '/../vendor/orchestra/testbench-core/laravel';
2222
File::makeDirectory($laravelPath . '/.git/hooks/', 0755, true);
2323
$this->artisan('lint:publish')->run();
24+
$this->assertFileExists($laravelPath . '/pint.json');
2425
$this->assertFileExists($laravelPath . '/phpcs.xml');
2526
$this->assertFileExists($laravelPath . '/phpmd.xml');
2627
$this->assertFileExists($laravelPath . '/.git/hooks/pre-commit');

0 commit comments

Comments
 (0)