Skip to content

Commit 9ae1c1e

Browse files
committed
Update docs
1 parent 11acdf5 commit 9ae1c1e

File tree

3 files changed

+67
-89
lines changed

3 files changed

+67
-89
lines changed

README.md

Lines changed: 20 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# Realodix Relax
1+
# Relax - Centralized PHP-CS-Fixer Rule Config
22

33
![PHPVersion](https://img.shields.io/badge/PHP-7.4%20|%20%5E8.0-777BB4.svg?style=flat-square)
44
![Packagist Version (custom server)](https://img.shields.io/packagist/v/realodix/relax)
55
![Build Status](../../actions/workflows/ci.yml/badge.svg)
66

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.
7+
**Relax** is built on top of [`PHP-CS-Fixer`](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) and makes it easy to provide a standardized way to apply coding standards across multiple projects, ensuring consistency and adherence to best practices.
88

9+
By using predefined rulesets, it simplifies the setup process and allows teams to quickly integrate PHP-CS-Fixer into their development workflow.
910

1011
## Installation
1112

@@ -27,24 +28,35 @@ For more details, see PHP-CS-Fixer [documentation](https://github.com/PHP-CS-Fix
2728

2829
## Configuring Relax
2930

30-
In your PHP CS Fixer configuration file, use the following contents:
31+
You can easily create your own rule set by extending the [`Realodix\Relax\RuleSet\AbstractRuleSet`](src/RuleSet/AbstractRuleSet.php) class and use it! See [docs/example_ruleset.md](docs/example_ruleset.md) for an example of how to create your own rule set.
3132

3233
```php
3334
<?php
3435

3536
use Realodix\Relax\Config;
37+
use Vendor\Package\MyRuleSet;
38+
39+
return Config::create(new MyRuleSet)
40+
->setFinder(/* ... */);
41+
```
42+
43+
Sometimes for big dirty projects, you want to implement some local rules without implementing a ruleset, why not.
3644

45+
```php
3746
$localRules = [
3847
// ...
3948
];
4049

41-
return Config::create('laravel')
42-
->setRules($localRules);
50+
Config::create()
51+
->setRules($localRules)
52+
->setFinder(/* ... */);
4353
```
4454

45-
#### Rulesets
55+
For advanced configuration, see the [docs/advanced_configuration.md](docs/advanced_configuration.md)
56+
57+
### Presets
4658

47-
A ruleset is a named list of rules that can be used to fix code style issues in your code. To use ruleset in your PHP code, you need to use the `Realodix\Relax\RuleSet\Sets\` namespace.
59+
Preset defines a built-in set of rules that are ready to be used to fix code style issues in your code.
4860

4961
| Ruleset | Description |
5062
| ------------------------- |-------------|
@@ -56,68 +68,8 @@ A ruleset is a named list of rules that can be used to fix code style issues in
5668
[rs_relax]: src/RuleSet/Sets/Realodix.php
5769
[rs_spatie]: src/RuleSet/Sets/Spatie.php
5870

59-
#### Custom Fixers
60-
61-
- [kubawerlos/php-cs-fixer-custom-fixers](https://github.com/kubawerlos/php-cs-fixer-custom-fixers)
62-
63-
:bulb: They're all registered, so you don't need to re-register via `registerCustomFixers()`.
64-
65-
<!-- #### Finder Sets
66-
67-
By default, Relax will inspect all `.php` files in your project except those in the `vendor` directory.
68-
69-
| Preset | Description |
70-
| -------- |-------------|
71-
| [`Finder::base()`][doc_f_base] | The basic finder setup should be perfect for most PHP projects |
72-
| [`Finder::laravel()`][doc_f_laravel] | Inherits `Finder::base()` with some specific tweaks to Laravel |
73-
74-
:bulb: By default, if finder is not set Relax will use `Finder::base()`.
75-
76-
[doc_f_base]: docs/finders.md#finderbase
77-
[doc_f_laravel]: docs/finders.md#finderlaravel -->
78-
79-
## Advanced Configuration
80-
See [docs/advanced_configuration.md](docs/advanced_configuration.md) for more details.
81-
82-
83-
## Custom Rule Set
84-
85-
You can easily create your own rule set by extending the [`AbstractRuleSet`](src/RuleSet/AbstractRuleSet.php): class.
86-
8771
```php
88-
<?php
89-
90-
use Realodix\Relax\RuleSet\AbstractRuleSet;
91-
92-
class MyRuleSet extends AbstractRuleSet
93-
{
94-
// This method is optional. If not implemented, Relax will use
95-
// the class name itself as the ruleset name.
96-
public function name(): string
97-
{
98-
// ...
99-
}
100-
101-
public function rules(): array
102-
{
103-
// ...
104-
}
105-
}
106-
```
107-
108-
And use it!
109-
110-
```php
111-
<?php
112-
113-
use Realodix\Relax\Config;
114-
use Vendor\Package\MyRuleSet;
115-
116-
$finder = (new PhpCsFixer\Finder())
117-
->in(__DIR__);
118-
119-
return Config::create(new MyRuleSet())
120-
->setFinder($finder);
72+
Config::create('laravel')
12173
```
12274

12375

@@ -131,5 +83,3 @@ Please report bugs to the [GitHub Issue Tracker](../../issues).
13183
## License
13284

13385
This package is licensed under the [MIT License](/LICENSE).
134-
135-
[php-cs-fixer]: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer

docs/advanced_configuration.md

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ You can find the full documentation on this page:
1111

1212
use PhpCsFixer\Finder;
1313
use Realodix\Relax\Config;
14+
use Vendor\Package\MyRuleSet;
1415

1516
// You can add or override rule set
1617
$localRules = [
@@ -35,26 +36,9 @@ $finder = Finder::create()
3536
->notName('*.foo.php')
3637
->append(['.php-cs-fixer.dist.php']);
3738

38-
return Config::create('laravel')
39+
return Config::create(new MyRuleSet)
3940
->setRules($localRules)
4041
->setFinder($finder)
4142
->setRiskyAllowed(false)
42-
->registerCustomFixers(new \PhpCsFixerCustomFixers\CustomFixer());
43-
```
44-
45-
If you wish to completely define rules locally without using existing rule sets, you can do that:
46-
47-
```php
48-
<?php
49-
50-
use Realodix\Relax\Config;
51-
52-
$localRules = [
53-
'@PSR2' => true,
54-
'array_syntax' => ['syntax' => 'short'],
55-
'ordered_imports' => ['sort_algorithm' => 'alpha'],
56-
];
57-
58-
return Config::create()
59-
->setRules($localRules);
43+
->registerCustomFixers(/* ... */);
6044
```

docs/example_ruleset.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
1. **`name`**
2+
3+
This method is optional. If not implemented, Relax will use the class name itself as the ruleset name.
4+
5+
2. **`rules`**
6+
7+
Define the PHP-CS-Fixer rules you want to use.
8+
9+
🧱 Resources:
10+
- https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/rules/index.rst
11+
- https://github.com/kubawerlos/php-cs-fixer-custom-fixers
12+
13+
<br> <br>
14+
15+
```php
16+
<?php
17+
18+
use PhpCsFixerCustomFixers\Fixer;
19+
use Realodix\Relax\RuleSet\AbstractRuleSet;
20+
21+
class MyRuleSet extends AbstractRuleSet
22+
{
23+
public function name(): string
24+
{
25+
// ...
26+
}
27+
28+
public function rules(): array
29+
{
30+
return [
31+
'@PSR2' => true,
32+
'array_syntax' => [
33+
'syntax' => 'short'
34+
],
35+
'blank_line_after_opening_tag' => true,
36+
Fixer\NoImportFromGlobalNamespaceFixer::name() => true,
37+
Fixer\NoLeadingSlashInGlobalNamespaceFixer::name() => true,
38+
+ Fixer\PhpdocNoSuperfluousParamFixer::name() => true,
39+
40+
// ...
41+
];
42+
}
43+
}
44+
```

0 commit comments

Comments
 (0)