Skip to content

Commit

Permalink
feat: add --only option to toolbox:install command
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaur committed May 8, 2021
1 parent abb664b commit 910bbd1
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 48 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

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

## 1.2.1 - 2021-05-08
## 2.1.0 - 2021-05-08

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

## 1.2.0 - 2021-05-08
## 2.0.0 - 2021-05-08

- update php-cs-fixer
- update phpunit-speedtrap
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
- Pest
- Dusk
- Larastan
- Php Cs Fixer
- [Php Cs Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer)

## Support Me

Hey folks,

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

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

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

Install the package via composer:
```
composer require lemaur/toolbox
composer require --dev lemaur/toolbox
```

Launch the installation:
Expand Down
78 changes: 57 additions & 21 deletions src/Commands/PublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
class PublishCommand extends Command
{
protected $signature = 'toolbox:install
{--F|force}';
{--only= : Specify which group of files do you want to copy. Possible values are: `static-analysis`, `code-style`, `rector`, `tests`, `common`}
{--F|force : Specify if you want overwrite you existing files}';

protected $description = '';
protected $description = 'Install Toolbox\'s files and tests resources';

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

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

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

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

// 'rector'
__DIR__.'/../Commands/stubs/rector.php.stub' => base_path('rector.php'),

// 'tests'
__DIR__.'/../Commands/stubs/phpunit.xml.stub' => base_path('phpunit.xml'),
__DIR__.'/../Commands/stubs/tests/Pest.php.stub' => base_path('tests/Pest.php'),

// 'commons'
__DIR__.'/../Commands/stubs/.editorconfig.stub' => base_path('.editorconfig'),
__DIR__.'/../Commands/stubs/.gitignore.stub' => base_path('.gitignore'),
__DIR__.'/../Commands/stubs/.env.dusk' => base_path('.env.dusk'),
return 0;
}

]);
private function files(?string $key = null): array
{
$files = [

'static-analysis' => [
[
__DIR__.'/../Commands/stubs/phpstan.neon.stub' => base_path('phpstan.neon'),
__DIR__.'/../Commands/stubs/tests/Analysis/AnalysisTest.php.stub' => base_path('tests/Analysis/AnalysisTest.php'),
],
],

'code-style' => [
[
__DIR__ . '/../Commands/stubs/.php-cs-fixer.php.stub' => base_path('.php-cs-fixer.php'),
],
],

'rector' => [
[
__DIR__.'/../Commands/stubs/rector.php.stub' => base_path('rector.php'),
],
],

'tests' => [
[
__DIR__.'/../Commands/stubs/phpunit.xml.stub' => base_path('phpunit.xml'),
__DIR__.'/../Commands/stubs/tests/Pest.php.stub' => base_path('tests/Pest.php'),
],
],

'commons' => [
[
__DIR__.'/../Commands/stubs/.editorconfig.stub' => base_path('.editorconfig'),
__DIR__.'/../Commands/stubs/.gitignore.stub' => base_path('.gitignore'),
__DIR__.'/../Commands/stubs/.env.dusk' => base_path('.env.dusk'),
],
],

];

return $key ? $files[$key] : $files;
}

return 0;
private function copy(Filesystem $filesystem, array $keys): void
{
foreach ($keys as $key) {
$this->copyFiles($filesystem, $this->files($key));
}
}

private function copyFiles(Filesystem $filesystem, array $files): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
declare(strict_types=1);

/**
* Rules taken from [Laravel Shift](https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200)
* with some adjustments.
* List of available rules: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/3.0/doc/rules/index.rst
*/
$rules = [
'array_syntax' => ['syntax' => 'short'],
Expand Down Expand Up @@ -37,13 +36,13 @@ $rules = [
'concat_space' => ['spacing' => 'none'],
'constant_case' => ['case' => 'lower'],
'declare_equal_normalize' => true,
'declare_strict_types' => true, // added by Lemaur
'declare_strict_types' => true,
'echo_tag_syntax' => ['format' => 'long'],
'elseif' => true,
'encoding' => true,
'final_internal_class' => true, // added by Lemaur
'final_internal_class' => true,
'full_opening_tag' => true,
'fully_qualified_strict_types' => true, // added by Shift
'fully_qualified_strict_types' => true,
'function_declaration' => true,
'function_typehint_space' => true,
'heredoc_to_nowdoc' => true,
Expand All @@ -54,13 +53,13 @@ $rules = [
'line_ending' => true,
'lowercase_cast' => true,
'lowercase_keywords' => true,
'lowercase_static_reference' => true, // added from Symfony
'magic_method_casing' => true, // added from Symfony
'lowercase_static_reference' => true,
'magic_method_casing' => true,
'magic_constant_casing' => true,
'method_argument_space' => true,
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
'native_function_casing' => true,
'new_with_braces' => true, // added by Lemaur
'new_with_braces' => true,
'no_alias_functions' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
Expand Down Expand Up @@ -102,25 +101,25 @@ $rules = [
],
],
'no_unreachable_default_argument_value' => true,
'no_unused_imports' => true, // added by Lemaur
'no_useless_else' => true, // added by Lemaur
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'not_operator_with_successor_space' => true,
'object_operator_without_whitespace' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'php_unit_strict' => true, // added by Lemaur
'php_unit_test_class_requires_covers' => true, // added by Lemaur
'phpdoc_add_missing_param_annotation' => true, // added by Lemaur
'phpdoc_align' => false, // added by Lemaur
'php_unit_strict' => true,
'php_unit_test_class_requires_covers' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_align' => false,
'phpdoc_indent' => true,
'phpdoc_inline_tag_normalizer',
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_no_access' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true, // added by Lemaur
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_summary' => true,
Expand All @@ -132,7 +131,7 @@ $rules = [
'self_accessor' => true,
'semicolon_after_instruction' => true,
'short_scalar_cast' => true,
'simplified_null_return' => true, // added by Lemaur
'simplified_null_return' => true,
'single_blank_line_at_eof' => true,
'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => [
Expand All @@ -150,13 +149,13 @@ $rules = [
'single_trait_insert_per_statement' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'strict_comparison' => true, // added by Lemaur
'strict_param' => true, // added by Lemaur
'strict_comparison' => true,
'strict_param' => true,
'switch_case_semicolon_to_colon' => true,
'switch_case_space' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => [
'elements' => 'arrays',
'elements' => ['arrays'],
],
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
Expand All @@ -166,7 +165,7 @@ $rules = [
'method',
'const',
],
], // added by Lemaur
],
'whitespace_after_comma_in_array' => true,
];

Expand Down

0 comments on commit 910bbd1

Please sign in to comment.