Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
skalero01 committed Apr 29, 2024
2 parents 6346755 + 3ff532c commit b1754d1
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 106 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/fix-php-code-style-issues.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/phpstan.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
return (new PhpCsFixer\Config())
->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers())
->setRules([
PhpCsFixerCustomFixers\Fixer\ConstructorEmptyBracesFixer::name() => true,
PhpCsFixerCustomFixers\Fixer\EmptyFunctionBodyFixer::name() => true,
PhpCsFixerCustomFixers\Fixer\NoUselessParenthesisFixer::name() => true,
]);
39 changes: 3 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,19 @@
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/weblabormx/weblabor-cs/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/weblabormx/weblabor-cs/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/weblabormx/weblabor-cs.svg?style=flat-square)](https://packagist.org/packages/weblabormx/weblabor-cs)

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

## Support us

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/weblabor-cs.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/weblabor-cs)
Package to clean the code of projects

## Installation

You can install the package via composer:

```bash
composer require weblabormx/weblabor-cs
```

You can publish and run the migrations with:

```bash
php artisan vendor:publish --tag="weblabor-cs-migrations"
php artisan migrate
```

You can publish the config file with:

```bash
php artisan vendor:publish --tag="weblabor-cs-config"
```

This is the contents of the published config file:

```php
return [
];
```

Optionally, you can publish the views using

```bash
php artisan vendor:publish --tag="weblabor-cs-views"
composer require weblabormx/weblabor-cs --dev
```

## Usage

```php
$codeStandars = new Weblabor\CodeStandars();
echo $codeStandars->echoPhrase('Hello, Weblabor!');
```
Just execute `php artisan clean:code` to clean the code

## Testing

Expand Down
12 changes: 4 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
},
"require-dev": {
"nunomaduro/collision": "^8.1.1||^7.10.0",
"kubawerlos/php-cs-fixer-custom-fixers": "^3.21",
"larastan/larastan": "^2.9",
"laravel/pint": "^1.15",
"orchestra/testbench": "^9.0.0||^8.22.0",
"pestphp/pest": "^2.34",
"pestphp/pest-plugin-arch": "^2.7",
"pestphp/pest-plugin-laravel": "^2.3",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.3"
"pestphp/pest-plugin-laravel": "^2.3"
},
"autoload": {
"psr-4": {
Expand All @@ -56,16 +55,13 @@
"@composer run build",
"@php vendor/bin/testbench serve"
],
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
"test-coverage": "vendor/bin/pest --coverage"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
}
},
"extra": {
Expand Down
164 changes: 164 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"preset": "laravel",
"rules": {
"array_indentation": false,
"array_syntax": false,
"binary_operator_spaces": false,
"blank_line_after_namespace": true,
"blank_line_after_opening_tag": true,
"blank_line_before_statement": false,
"blank_line_between_import_groups": false,
"blank_lines_before_namespace": true,
"braces_position": false,
"cast_spaces": true,
"class_attributes_separation": false,
"class_definition":
{
"multi_line_extends_each_single_line": true,
"single_item_single_line": true,
"single_line": true
},
"clean_namespace": false,
"compact_nullable_type_declaration": false,
"concat_space": false,
"constant_case":
{
"case": "lower"
},
"control_structure_braces": false,
"control_structure_continuation_position": false,
"declare_equal_normalize": false,
"declare_parentheses": false,
"elseif": false,
"encoding": false,
"full_opening_tag": false,
"fully_qualified_strict_types": false,
"function_declaration": false,
"general_phpdoc_tag_rename": false,
"heredoc_to_nowdoc": false,
"include": false,
"increment_style": false,
"indentation_type": false,
"integer_literal_case": false,
"lambda_not_used_import": true,
"line_ending": false,
"linebreak_after_opening_tag": false,
"list_syntax": true,
"lowercase_cast": false,
"lowercase_keywords": false,
"lowercase_static_reference": false,
"magic_constant_casing": false,
"magic_method_casing": false,
"method_argument_space":
{
"on_multiline": "ignore"
},
"method_chaining_indentation": false,
"multiline_whitespace_before_semicolons": false,
"native_function_casing": true,
"native_type_declaration_casing": false,
"no_alias_functions": false,
"no_alias_language_construct_call": false,
"no_alternative_syntax": false,
"no_binary_string": false,
"no_blank_lines_after_class_opening": true,
"no_blank_lines_after_phpdoc": false,
"no_closing_tag": false,
"no_empty_phpdoc": false,
"no_empty_statement": true,
"no_extra_blank_lines":
{
"tokens": ["extra", "throw", "use"]
},
"no_leading_import_slash": false,
"no_leading_namespace_whitespace": false,
"no_mixed_echo_print": false,
"no_multiline_whitespace_around_double_arrow": true,
"no_multiple_statements_per_line": false,
"no_short_bool_cast": false,
"no_singleline_whitespace_before_semicolons": false,
"no_space_around_double_colon": false,
"no_spaces_after_function_name": false,
"no_spaces_around_offset": false,
"no_superfluous_phpdoc_tags": false,
"no_trailing_comma_in_singleline": true,
"no_trailing_whitespace": true,
"no_trailing_whitespace_in_comment": true,
"no_unneeded_control_parentheses":
{
"statements": ["break", "clone", "continue", "echo_print", "return", "switch_case", "yield"]
},
"no_unneeded_braces": true,
"no_unreachable_default_argument_value": false,
"no_unset_cast": false,
"no_unused_imports": true,
"no_useless_return": true,
"no_whitespace_before_comma_in_array": false,
"no_whitespace_in_blank_line": true,
"normalize_index_brace": true,
"not_operator_with_successor_space": true,
"nullable_type_declaration": false,
"nullable_type_declaration_for_default_null_value": false,
"object_operator_without_whitespace": false,
"ordered_imports":
{
"sort_algorithm": "alpha",
"imports_order": ["const", "class", "function"]
},
"ordered_interfaces": false,
"ordered_traits": false,
"phpdoc_align": false,
"phpdoc_indent": false,
"phpdoc_inline_tag_normalizer": false,
"phpdoc_no_access": false,
"phpdoc_no_package": false,
"phpdoc_no_useless_inheritdoc": false,
"phpdoc_order": false,
"phpdoc_scalar": false,
"phpdoc_separation": false,
"phpdoc_single_line_var_spacing": false,
"phpdoc_summary": false,
"phpdoc_tag_type": false,
"phpdoc_to_comment": false,
"phpdoc_trim": false,
"phpdoc_types": false,
"phpdoc_var_without_name": false,
"psr_autoloading": false,
"return_type_declaration":
{
"space_before": "none"
},
"self_accessor": false,
"self_static_accessor": false,
"short_scalar_cast": true,
"simplified_null_return": false,
"single_blank_line_at_eof": true,
"single_class_element_per_statement": false,
"single_import_per_statement": false,
"single_line_after_imports": false,
"single_line_comment_style":
{
"comment_types": ["hash"]
},
"single_quote": true,
"single_space_around_construct": false,
"space_after_semicolon": false,
"spaces_inside_parentheses": false,
"standardize_not_equals": false,
"statement_indentation": false,
"switch_case_semicolon_to_colon": false,
"switch_case_space": false,
"ternary_operator_spaces": true,
"trailing_comma_in_multiline": false,
"trim_array_spaces": false,
"type_declaration_spaces": false,
"types_spaces": false,
"unary_operator_spaces": false,
"visibility_required":
{
"elements": ["method", "property"]
},
"whitespace_after_comma_in_array": true,
"yoda_style": false
}
}
7 changes: 5 additions & 2 deletions src/CodeStandarsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Weblabor\CodeStandars\Commands\CodeStandarsCommand;

class CodeStandarsServiceProvider extends PackageServiceProvider
{
Expand All @@ -20,6 +19,10 @@ public function configurePackage(Package $package): void
->hasConfigFile()
->hasViews()
->hasMigration('create_weblabor-cs_table')
->hasCommand(CodeStandarsCommand::class);
->hasCommand(Commands\CleanCode::class)
->hasCommand(Commands\OptimizeFront::class)
->hasCommand(Commands\OptimizeRemovePhpDocs::class)
->hasCommand(Commands\OptimizeTraitsOnOneLine::class)
->hasCommand(Commands\OptimizeVariablesOnOneLine::class);
}
}
33 changes: 32 additions & 1 deletion src/Commands/CleanCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,39 @@ class CleanCode extends Command

public function handle(): int
{
$this->call('optimize:front');
$this->commit("Changes not saved");
$this->executeCsFixer();

// Execute commands
$this->executeCommand('optimize:front');
$this->executeCommand('optimize:remove-comments');
$this->executeCommand('optimize:traits-one-line');
$this->executeCommand('optimize:variables-one-line');

$this->executeCsFixer();
return self::SUCCESS;
}

private function executeCsFixer()
{
// Execute laravel Pint
exec("./vendor/bin/pint --config vendor/weblabormx/weblabor-cs/pint.json");
$this->commit("Laravel Pint");

// Execute CS Fixer
exec("php php-cs-fixer.phar fix . --config vendor/weblabormx/weblabor-cs/.php-cs-fixer.php");
$this->commit("PHP CS Fixer");
}

private function executeCommand(string $command): void
{
$this->commit($command);
$this->call($command);
}

private function commit($name)
{
exec('git add .');
exec('git commit -m "'.$name.'"');
}
}
2 changes: 1 addition & 1 deletion src/Commands/OptimizeRemovePhpDocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public function handle()
File::put($file->getPathname(), $content);
}

$this->info('Front classes optimized successfully.');
$this->info('PHP Docs removed successfully.');
}
}
Loading

0 comments on commit b1754d1

Please sign in to comment.