Skip to content

Commit 910bbd1

Browse files
committed
feat: add --only option to toolbox:install command
1 parent abb664b commit 910bbd1

File tree

4 files changed

+83
-48
lines changed

4 files changed

+83
-48
lines changed

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
All notable changes to `toolbox` will be documented in this file.
44

5-
## 1.2.1 - 2021-05-08
5+
## 2.1.0 - 2021-05-08
66

7-
- fix github workflows
7+
- add --only option to toolbox:install command
88

9-
## 1.2.0 - 2021-05-08
9+
## 2.0.0 - 2021-05-08
1010

1111
- update php-cs-fixer
1212
- update phpunit-speedtrap

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
- Pest
1313
- Dusk
1414
- Larastan
15-
- Php Cs Fixer
15+
- [Php Cs Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer)
1616

1717
## Support Me
1818

1919
Hey folks,
2020

21-
Do you like this package? Do you find it useful and it fits well in your project?
21+
Do you like this package? Do you find it useful, and it fits well in your project?
2222

2323
I am glad to help you, and I would be so grateful if you considered supporting my work.
2424

@@ -32,7 +32,7 @@ You can even choose 😃:
3232

3333
Install the package via composer:
3434
```
35-
composer require lemaur/toolbox
35+
composer require --dev lemaur/toolbox
3636
```
3737

3838
Launch the installation:

src/Commands/PublishCommand.php

+57-21
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
class PublishCommand extends Command
1212
{
1313
protected $signature = 'toolbox:install
14-
{--F|force}';
14+
{--only= : Specify which group of files do you want to copy. Possible values are: `static-analysis`, `code-style`, `rector`, `tests`, `common`}
15+
{--F|force : Specify if you want overwrite you existing files}';
1516

16-
protected $description = '';
17+
protected $description = 'Install Toolbox\'s files and tests resources';
1718

1819
public function handle(Filesystem $filesystem): int
1920
{
@@ -23,30 +24,65 @@ public function handle(Filesystem $filesystem): int
2324
// Install Dusk
2425
$this->call('dusk:install', ['--quiet']);
2526

26-
$this->copyFiles($filesystem, [
27+
if ($this->option('only') && array_key_exists($this->option('only'), $this->files())) {
28+
$this->copy($filesystem, $this->option('only'));
2729

28-
// 'static-analysis'
29-
__DIR__.'/../Commands/stubs/phpstan.neon.stub' => base_path('phpstan.neon'),
30-
__DIR__.'/../Commands/stubs/tests/Analysis/AnalysisTest.php.stub' => base_path('tests/Analysis/AnalysisTest.php'),
30+
return 0;
31+
}
3132

32-
// 'code-style'
33-
__DIR__ . '/../Commands/stubs/.php-cs-fixer.stub' => base_path('.php-cs-fixer'),
33+
$this->copy($filesystem, array_keys($this->files()));
3434

35-
// 'rector'
36-
__DIR__.'/../Commands/stubs/rector.php.stub' => base_path('rector.php'),
37-
38-
// 'tests'
39-
__DIR__.'/../Commands/stubs/phpunit.xml.stub' => base_path('phpunit.xml'),
40-
__DIR__.'/../Commands/stubs/tests/Pest.php.stub' => base_path('tests/Pest.php'),
41-
42-
// 'commons'
43-
__DIR__.'/../Commands/stubs/.editorconfig.stub' => base_path('.editorconfig'),
44-
__DIR__.'/../Commands/stubs/.gitignore.stub' => base_path('.gitignore'),
45-
__DIR__.'/../Commands/stubs/.env.dusk' => base_path('.env.dusk'),
35+
return 0;
36+
}
4637

47-
]);
38+
private function files(?string $key = null): array
39+
{
40+
$files = [
41+
42+
'static-analysis' => [
43+
[
44+
__DIR__.'/../Commands/stubs/phpstan.neon.stub' => base_path('phpstan.neon'),
45+
__DIR__.'/../Commands/stubs/tests/Analysis/AnalysisTest.php.stub' => base_path('tests/Analysis/AnalysisTest.php'),
46+
],
47+
],
48+
49+
'code-style' => [
50+
[
51+
__DIR__ . '/../Commands/stubs/.php-cs-fixer.php.stub' => base_path('.php-cs-fixer.php'),
52+
],
53+
],
54+
55+
'rector' => [
56+
[
57+
__DIR__.'/../Commands/stubs/rector.php.stub' => base_path('rector.php'),
58+
],
59+
],
60+
61+
'tests' => [
62+
[
63+
__DIR__.'/../Commands/stubs/phpunit.xml.stub' => base_path('phpunit.xml'),
64+
__DIR__.'/../Commands/stubs/tests/Pest.php.stub' => base_path('tests/Pest.php'),
65+
],
66+
],
67+
68+
'commons' => [
69+
[
70+
__DIR__.'/../Commands/stubs/.editorconfig.stub' => base_path('.editorconfig'),
71+
__DIR__.'/../Commands/stubs/.gitignore.stub' => base_path('.gitignore'),
72+
__DIR__.'/../Commands/stubs/.env.dusk' => base_path('.env.dusk'),
73+
],
74+
],
75+
76+
];
77+
78+
return $key ? $files[$key] : $files;
79+
}
4880

49-
return 0;
81+
private function copy(Filesystem $filesystem, array $keys): void
82+
{
83+
foreach ($keys as $key) {
84+
$this->copyFiles($filesystem, $this->files($key));
85+
}
5086
}
5187

5288
private function copyFiles(Filesystem $filesystem, array $files): void

src/Commands/stubs/.php-cs-fixer.stub src/Commands/stubs/.php-cs-fixer.php.stub

+20-21
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
declare(strict_types=1);
44

55
/**
6-
* Rules taken from [Laravel Shift](https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200)
7-
* with some adjustments.
6+
* List of available rules: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/3.0/doc/rules/index.rst
87
*/
98
$rules = [
109
'array_syntax' => ['syntax' => 'short'],
@@ -37,13 +36,13 @@ $rules = [
3736
'concat_space' => ['spacing' => 'none'],
3837
'constant_case' => ['case' => 'lower'],
3938
'declare_equal_normalize' => true,
40-
'declare_strict_types' => true, // added by Lemaur
39+
'declare_strict_types' => true,
4140
'echo_tag_syntax' => ['format' => 'long'],
4241
'elseif' => true,
4342
'encoding' => true,
44-
'final_internal_class' => true, // added by Lemaur
43+
'final_internal_class' => true,
4544
'full_opening_tag' => true,
46-
'fully_qualified_strict_types' => true, // added by Shift
45+
'fully_qualified_strict_types' => true,
4746
'function_declaration' => true,
4847
'function_typehint_space' => true,
4948
'heredoc_to_nowdoc' => true,
@@ -54,13 +53,13 @@ $rules = [
5453
'line_ending' => true,
5554
'lowercase_cast' => true,
5655
'lowercase_keywords' => true,
57-
'lowercase_static_reference' => true, // added from Symfony
58-
'magic_method_casing' => true, // added from Symfony
56+
'lowercase_static_reference' => true,
57+
'magic_method_casing' => true,
5958
'magic_constant_casing' => true,
6059
'method_argument_space' => true,
6160
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
6261
'native_function_casing' => true,
63-
'new_with_braces' => true, // added by Lemaur
62+
'new_with_braces' => true,
6463
'no_alias_functions' => true,
6564
'no_blank_lines_after_class_opening' => true,
6665
'no_blank_lines_after_phpdoc' => true,
@@ -102,25 +101,25 @@ $rules = [
102101
],
103102
],
104103
'no_unreachable_default_argument_value' => true,
105-
'no_unused_imports' => true, // added by Lemaur
106-
'no_useless_else' => true, // added by Lemaur
104+
'no_unused_imports' => true,
105+
'no_useless_else' => true,
107106
'no_useless_return' => true,
108107
'no_whitespace_before_comma_in_array' => true,
109108
'no_whitespace_in_blank_line' => true,
110109
'normalize_index_brace' => true,
111110
'not_operator_with_successor_space' => true,
112111
'object_operator_without_whitespace' => true,
113112
'ordered_imports' => ['sort_algorithm' => 'alpha'],
114-
'php_unit_strict' => true, // added by Lemaur
115-
'php_unit_test_class_requires_covers' => true, // added by Lemaur
116-
'phpdoc_add_missing_param_annotation' => true, // added by Lemaur
117-
'phpdoc_align' => false, // added by Lemaur
113+
'php_unit_strict' => true,
114+
'php_unit_test_class_requires_covers' => true,
115+
'phpdoc_add_missing_param_annotation' => true,
116+
'phpdoc_align' => false,
118117
'phpdoc_indent' => true,
119-
'phpdoc_inline_tag_normalizer',
118+
'phpdoc_inline_tag_normalizer' => true,
120119
'phpdoc_no_access' => true,
121120
'phpdoc_no_package' => true,
122121
'phpdoc_no_useless_inheritdoc' => true,
123-
'phpdoc_order' => true, // added by Lemaur
122+
'phpdoc_order' => true,
124123
'phpdoc_scalar' => true,
125124
'phpdoc_single_line_var_spacing' => true,
126125
'phpdoc_summary' => true,
@@ -132,7 +131,7 @@ $rules = [
132131
'self_accessor' => true,
133132
'semicolon_after_instruction' => true,
134133
'short_scalar_cast' => true,
135-
'simplified_null_return' => true, // added by Lemaur
134+
'simplified_null_return' => true,
136135
'single_blank_line_at_eof' => true,
137136
'single_blank_line_before_namespace' => true,
138137
'single_class_element_per_statement' => [
@@ -150,13 +149,13 @@ $rules = [
150149
'single_trait_insert_per_statement' => true,
151150
'space_after_semicolon' => true,
152151
'standardize_not_equals' => true,
153-
'strict_comparison' => true, // added by Lemaur
154-
'strict_param' => true, // added by Lemaur
152+
'strict_comparison' => true,
153+
'strict_param' => true,
155154
'switch_case_semicolon_to_colon' => true,
156155
'switch_case_space' => true,
157156
'ternary_operator_spaces' => true,
158157
'trailing_comma_in_multiline' => [
159-
'elements' => 'arrays',
158+
'elements' => ['arrays'],
160159
],
161160
'trim_array_spaces' => true,
162161
'unary_operator_spaces' => true,
@@ -166,7 +165,7 @@ $rules = [
166165
'method',
167166
'const',
168167
],
169-
], // added by Lemaur
168+
],
170169
'whitespace_after_comma_in_array' => true,
171170
];
172171

0 commit comments

Comments
 (0)