Skip to content

Commit 29ce529

Browse files
committed
Refactor code
1 parent da4d44f commit 29ce529

4 files changed

Lines changed: 46 additions & 37 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Laravel GIT Commit Checker
22

3-
[![Latest Version](https://img.shields.io/github/release/botble/git-commit-checker.svg?style=flat-square)](https://github.com/botble/git-commit-checker/releases)
4-
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
3+
[![Latest Version](https://img.shields.io/packagist/v/botble/git-commit-checker.svg?style=flat-square)](https://github.com/botble/git-commit-checker/releases)
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
55
[![Total Downloads](https://img.shields.io/packagist/dt/botble/git-commit-checker.svg?style=flat-square)](https://packagist.org/packages/botble/git-commit-checker)
66
[![Maintainability](https://api.codeclimate.com/v1/badges/a6e4612307e3b3bf8252/maintainability)](https://codeclimate.com/github/botble/git-commit-checker/maintainability)
77

config/git-commit-checker.php

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,43 @@
99
'pre-commit' => PreCommitHookCommand::class,
1010
],
1111

12-
'recommended_preset' => [
13-
'preset' => 'psr12',
14-
'rules' => [
15-
'array_syntax' => ['syntax' => 'short'],
16-
'binary_operator_spaces' => [
17-
'default' => 'single_space',
18-
'operators' => [
19-
'=' => null,
12+
'pint' => [
13+
'presets' => [
14+
'laravel' => 'Laravel (Default)',
15+
'symfony' => 'Symfony',
16+
'psr12' => 'PSR-12',
17+
'recommended' => 'Recommended (PSR-12 Extended)',
18+
],
19+
20+
'recommended_preset' => [
21+
'preset' => 'psr12',
22+
'rules' => [
23+
'array_syntax' => ['syntax' => 'short'],
24+
'binary_operator_spaces' => [
25+
'default' => 'single_space',
26+
'operators' => [
27+
'=' => null,
28+
],
2029
],
30+
'blank_line_before_statement' => [
31+
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
32+
],
33+
'concat_space' => [
34+
'spacing' => 'one',
35+
],
36+
'function_typehint_space' => true,
37+
'native_function_casing' => true,
38+
'no_extra_blank_lines' => true,
39+
'no_leading_namespace_whitespace' => true,
40+
'no_spaces_around_offset' => true,
41+
'no_unused_imports' => true,
42+
'not_operator_with_successor_space' => true,
43+
'object_operator_without_whitespace' => true,
44+
'single_quote' => true,
45+
'trailing_comma_in_multiline' => true,
46+
'unary_operator_spaces' => true,
47+
'whitespace_after_comma_in_array' => true,
2148
],
22-
'blank_line_before_statement' => [
23-
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
24-
],
25-
'concat_space' => [
26-
'spacing' => 'one',
27-
],
28-
'function_typehint_space' => true,
29-
'native_function_casing' => true,
30-
'no_extra_blank_lines' => true,
31-
'no_leading_namespace_whitespace' => true,
32-
'no_spaces_around_offset' => true,
33-
'no_unused_imports' => true,
34-
'not_operator_with_successor_space' => true,
35-
'object_operator_without_whitespace' => true,
36-
'single_quote' => true,
37-
'trailing_comma_in_multiline' => true,
38-
'unary_operator_spaces' => true,
39-
'whitespace_after_comma_in_array' => true,
4049
],
4150
],
4251
];

src/Commands/InstallCommand.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,23 @@ protected function generateHookScript(string $signature): string
8686

8787
protected function generatePintConfiguration(string $path): void
8888
{
89-
$presets = [
90-
'laravel' => 'Laravel',
91-
'symfony' => 'Symfony',
92-
'psr12' => 'PSR-12',
93-
'psr2' => 'PSR-2',
94-
'recommended' => 'Recommended (PSR-12 Extended)',
95-
];
89+
$presets = $this->laravel['config']->get('git-commit-checker.pint.presets', []);
90+
91+
if (empty($presets)) {
92+
$this->components->error('Do not found a list of supported presets');
93+
abort(1);
94+
}
9695

9796
$standard = $this->components->choice('Which standard you want to use?', array_values($presets), 0);
97+
9898
$preset = array_flip($presets)[$standard];
9999

100100
if (! $this->laravel['files']->put(
101101
$path,
102102
json_encode(
103103
$standard !== 'recommended'
104104
? ['preset' => $preset]
105-
: $this->laravel['config']->get('git-commit-checker.recommended_preset'),
105+
: $this->laravel['config']->get('git-commit-checker.pint.recommended_preset'),
106106
JSON_PRETTY_PRINT
107107
)
108108
)) {

src/Commands/PreCommitHookCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public function handle(): int
3131
$command = [
3232
$this->laravel->basePath('vendor/bin/pint'),
3333
'--test',
34-
'-v',
3534
];
3635

3736
$command = array_merge($command, $uncommittedFiles);
@@ -43,6 +42,7 @@ public function handle(): int
4342
$process->run();
4443

4544
if (! $process->isSuccessful()) {
45+
$this->components->warn('Run <comment>./vendor/bin/pint --dirty --test -v</comment> to see coding standard detail issues');
4646
$this->components->warn('Run <comment>./vendor/bin/pint --dirty</comment> to fix coding standard issues');
4747

4848
return self::FAILURE;

0 commit comments

Comments
 (0)