Skip to content

Commit a532bea

Browse files
committed
Update finder
1 parent 9ae1c1e commit a532bea

File tree

5 files changed

+37
-25
lines changed

5 files changed

+37
-25
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
];
99

1010
$finder = Finder::base()
11+
->in(__DIR__)
1112
->append(['.php-cs-fixer.dist.php', 'bin/relax']);
1213

1314
return Config::create('relax')

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ You can easily create your own rule set by extending the [`Realodix\Relax\RuleSe
3636
use Realodix\Relax\Config;
3737
use Vendor\Package\MyRuleSet;
3838

39-
return Config::create(new MyRuleSet)
40-
->setFinder(/* ... */);
39+
return Config::create(new MyRuleSet);
4140
```
4241

4342
Sometimes for big dirty projects, you want to implement some local rules without implementing a ruleset, why not.
@@ -48,8 +47,7 @@ $localRules = [
4847
];
4948

5049
Config::create()
51-
->setRules($localRules)
52-
->setFinder(/* ... */);
50+
->setRules($localRules);
5351
```
5452

5553
For advanced configuration, see the [docs/advanced_configuration.md](docs/advanced_configuration.md)
@@ -72,6 +70,20 @@ Preset defines a built-in set of rules that are ready to be used to fix code sty
7270
Config::create('laravel')
7371
```
7472

73+
#### Finder Sets
74+
75+
By default, Relax will inspect all `.php` files in your project except those in the `vendor` directory.
76+
77+
| Preset | Description |
78+
| -------- |-------------|
79+
| [`Finder::base()`][doc_f_base] | The basic finder setup should be perfect for most PHP projects |
80+
| [`Finder::laravel()`][doc_f_laravel] | Inherits `Finder::base()` with some specific tweaks to Laravel |
81+
82+
:bulb: By default, if finder is not set Relax will use `Finder::base()`.
83+
84+
[doc_f_base]: docs/finders.md#finderbase
85+
[doc_f_laravel]: docs/finders.md#finderlaravel
86+
7587

7688
## Troubleshooting
7789

docs/finders.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
## Finder Presets
22

33
#### **`Finder::base()`**
4-
- Inherits [`PhpCsFixer\Finder`][pcf/finder] (Inspect all `.php` files except those in the `vendor` directory.).
5-
- Includes PHP files in all folders.
4+
- Inherit [`PhpCsFixer\Finder`][pcf/finder] (Inspect all `.php` files except those in the `vendor` directory.).
65
- Ignores VCS files.
76
- Ignores dotfiles.
8-
- Excludes `_ide_helper_actions.php`, `_ide_helper_models.php`, `_ide_helper.php`, `.phpstorm.meta.php` files.
7+
- Excludes directories: `node_modules`.
8+
- Excludes files: `_ide_helper_actions.php`, `_ide_helper_models.php`, `_ide_helper.php`, `.phpstorm.meta.php`.
99

1010
#### **`Finder::laravel()`**
11-
- Inherits `Finder::base()` preset.
12-
- Excludes all files in the `bootstrap/cache`, `public`, `resources`, `storage` & `node_modules` directories.
13-
- Excludes `*.blade.php` files.
11+
- Inherit `Finder::base()`.
12+
- Excludes directories: `bootstrap/cache`, `public`, `resources`, & `storage`.
13+
- Excludes files: `*.blade.php`.
1414

1515
[pcf/finder]: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/src/Finder.php

src/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(?RuleSetInterface $ruleSet)
2020

2121
parent::__construct($name);
2222
$this->registerCustomFixers(new \PhpCsFixerCustomFixers\Fixers);
23-
$this->setFinder(Finder::base());
23+
$this->setFinder(Finder::base()->in(getcwd()));
2424
$this->setRiskyAllowed(true);
2525
$this->setRules();
2626
}

src/Finder.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22

33
namespace Realodix\Relax;
44

5-
use PhpCsFixer\Finder as PhpCsFixerFinder;
5+
use PhpCsFixer\Finder as BaseFinder;
66

7-
class Finder extends PhpCsFixerFinder
7+
/**
8+
* {@inheritDoc}
9+
*
10+
* @see https://symfony.com/doc/current/components/finder.html
11+
* @see https://github.com/symfony/finder/blob/7.1/Finder.php
12+
* @see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/src/Finder.php
13+
*/
14+
class Finder extends BaseFinder
815
{
916
/**
10-
* @param null|string|list<string> $baseDir
1117
* @return \PhpCsFixer\Finder
1218
*/
13-
public static function base($baseDir = null)
19+
public static function base()
1420
{
15-
if ($baseDir === null) {
16-
$baseDir = getcwd() === false ? '' : getcwd();
17-
}
18-
19-
return PhpCsFixerFinder::create()
20-
->in($baseDir)
21+
return self::create()
2122
->ignoreVCS(true)
2223
->ignoreDotFiles(true)
2324
->notName([
@@ -26,18 +27,16 @@ public static function base($baseDir = null)
2627
'_ide_helper.php',
2728
'.phpstorm.meta.php',
2829
])->exclude([
29-
'build',
3030
'node_modules',
3131
]);
3232
}
3333

3434
/**
35-
* @param null|string|list<string> $baseDir
3635
* @return \PhpCsFixer\Finder
3736
*/
38-
public static function laravel($baseDir = null)
37+
public static function laravel()
3938
{
40-
return self::base($baseDir)
39+
return self::base()
4140
->exclude([
4241
'bootstrap/cache',
4342
'public',

0 commit comments

Comments
 (0)