Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix committed Jul 9, 2024
1 parent d36c7d2 commit 692c40f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 61 deletions.
76 changes: 16 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

**Realodix Relax** is built on top of [`PHP-CS-Fixer`][php-cs-fixer] and makes it simple to to sharing identical PHP CS Fixer rules across all of your projects without copy-and-pasting configuration files.


## Installation

You can install this package by using [composer](https://getcomposer.org/):
Expand All @@ -14,6 +15,7 @@ You can install this package by using [composer](https://getcomposer.org/):
composer require --dev realodix/relax
```


## Running Relax

```sh
Expand All @@ -22,6 +24,7 @@ composer require --dev realodix/relax

For more details, see PHP-CS-Fixer [documentation](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/usage.rst).


## Configuring Relax

In your PHP CS Fixer configuration file, use the following contents:
Expand Down Expand Up @@ -49,14 +52,17 @@ A ruleset is a named list of rules that can be used to fix code style issues in
| [`relax`][rs_relax] | Inherits `laravel` with some tweaks |
| [`spatie`][rs_spatie] | The rule set used by Spatie |

[rs_laravel]: src/RuleSet/Sets/Laravel.php
[rs_relax]: src/RuleSet/Sets/Realodix.php
[rs_spatie]: src/RuleSet/Sets/Spatie.php

#### Custom Fixers

- [kubawerlos/php-cs-fixer-custom-fixers](https://github.com/kubawerlos/php-cs-fixer-custom-fixers)

:bulb: They're all registered, so you don't need to re-register via `registerCustomFixers()`.

#### Finder Sets
<!-- #### Finder Sets
By default, Relax will inspect all `.php` files in your project except those in the `vendor` directory.
Expand All @@ -67,68 +73,12 @@ By default, Relax will inspect all `.php` files in your project except those in
:bulb: By default, if finder is not set Relax will use `Finder::base()`.
[rs_laravel]: src/RuleSet/Sets/Laravel.php
[rs_relax]: src/RuleSet/Sets/Realodix.php
[rs_spatie]: src/RuleSet/Sets/Spatie.php
[doc_f_base]: docs/finders.md#finderbase
[doc_f_laravel]: docs/finders.md#finderlaravel
[doc_f_laravel]: docs/finders.md#finderlaravel -->

## Advanced Configuration
See [docs/advanced_configuration.md](docs/advanced_configuration.md) for more details.

Relax is built on top of [`PHP-CS-Fixer`][php-cs-fixer]. Therefore, you can make configurations just like you can do in PHP-CS-Fixer. For more details, see [PHP-CS-Fixer: Config](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/config.rst) documentation and [MLocati: PHP-CS-Fixer Configurator](https://mlocati.github.io/php-cs-fixer-configurator).

```php
<?php

use Realodix\Relax\Config;
use Realodix\Relax\Finder;

// You can add or override rule set
$localRules = [
// Add rule
'array_syntax' => true,

// Add rule or override predefined rule
'visibility_required' => true,

// Override predefined rule
'braces' => false,

// Add custom fixers
'CustomFixer/rule_1' => true,
'CustomFixer/rule_2' => true,
];

$finder = Finder::create()
->in(__DIR__)
->ignoreDotFiles(false)
->exclude(['Bar'])
->notName('*.foo.php')
->append(['.php-cs-fixer.dist.php']);

return Config::create('laravel')
->setRules($localRules)
->setFinder($finder)
->setRiskyAllowed(false)
->registerCustomFixers(new \PhpCsFixerCustomFixers\CustomFixer());
```

If you wish to completely define rules locally without using existing rule sets, you can do that:

```php
<?php

use Realodix\Relax\Config;

$localRules = [
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
];

return Config::create()
->setRules($localRules);
```

## Custom Rule Set

Expand Down Expand Up @@ -163,15 +113,21 @@ And use it!
use Realodix\Relax\Config;
use Vendor\Package\MyRuleSet;

return Config::create(new MyRuleSet());
$finder = (new PhpCsFixer\Finder())
->in(__DIR__);

return Config::create(new MyRuleSet())
->setFinder($finder);
```


## Troubleshooting

For general help and support join our [GitHub Discussions](../../discussions).

Please report bugs to the [GitHub Issue Tracker](../../issues).


## License

This package is licensed under the [MIT License](/LICENSE).
Expand Down
60 changes: 60 additions & 0 deletions docs/advanced_configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## Advanced Configuration

You can find the full documentation on this page:
- [PHP-CS-Fixer: Config](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/config.rst)
- [PHP-CS-Fixer: Rules](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/rules/index.rst)
- [MLocati: PHP-CS-Fixer Configurator](https://mlocati.github.io/php-cs-fixer-configurator)


```php
<?php

use PhpCsFixer\Finder;
use Realodix\Relax\Config;

// You can add or override rule set
$localRules = [
// Add rule
'array_syntax' => true,

// Add rule or override predefined rule
'visibility_required' => true,

// Override predefined rule
'braces' => false,

// Add custom fixers
'CustomFixer/rule_1' => true,
'CustomFixer/rule_2' => true,
];

$finder = Finder::create()
->in(__DIR__)
->ignoreDotFiles(false)
->exclude(['Bar'])
->notName('*.foo.php')
->append(['.php-cs-fixer.dist.php']);

return Config::create('laravel')
->setRules($localRules)
->setFinder($finder)
->setRiskyAllowed(false)
->registerCustomFixers(new \PhpCsFixerCustomFixers\CustomFixer());
```

If you wish to completely define rules locally without using existing rule sets, you can do that:

```php
<?php

use Realodix\Relax\Config;

$localRules = [
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
];

return Config::create()
->setRules($localRules);
```
7 changes: 6 additions & 1 deletion src/Commands/GenerateConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ protected function generateAndSaveCode($output): bool
$code = <<<'CODE'
<?php
use Realodix\Relax\Config;
use Realodix\Relax\Finder;
$localRules = [
// ...
];
$finder = Finder::create()
->in(__DIR__)
return Config::create('relax')
->setRules($localRules);
->setRules($localRules)
->setFinder($finder);
CODE;

if (file_put_contents($this->getOutputFilename(), $code) === false) {
Expand Down

0 comments on commit 692c40f

Please sign in to comment.