Skip to content

Commit

Permalink
Update finder
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix committed Jul 11, 2024
1 parent 9ae1c1e commit a532bea
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
];

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

return Config::create('relax')
Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ You can easily create your own rule set by extending the [`Realodix\Relax\RuleSe
use Realodix\Relax\Config;
use Vendor\Package\MyRuleSet;

return Config::create(new MyRuleSet)
->setFinder(/* ... */);
return Config::create(new MyRuleSet);
```

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

Config::create()
->setRules($localRules)
->setFinder(/* ... */);
->setRules($localRules);
```

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

#### Finder Sets

By default, Relax will inspect all `.php` files in your project except those in the `vendor` directory.

| Preset | Description |
| -------- |-------------|
| [`Finder::base()`][doc_f_base] | The basic finder setup should be perfect for most PHP projects |
| [`Finder::laravel()`][doc_f_laravel] | Inherits `Finder::base()` with some specific tweaks to Laravel |

:bulb: By default, if finder is not set Relax will use `Finder::base()`.

[doc_f_base]: docs/finders.md#finderbase
[doc_f_laravel]: docs/finders.md#finderlaravel


## Troubleshooting

Expand Down
12 changes: 6 additions & 6 deletions docs/finders.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
## Finder Presets

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

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

[pcf/finder]: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/src/Finder.php
2 changes: 1 addition & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(?RuleSetInterface $ruleSet)

parent::__construct($name);
$this->registerCustomFixers(new \PhpCsFixerCustomFixers\Fixers);
$this->setFinder(Finder::base());
$this->setFinder(Finder::base()->in(getcwd()));
$this->setRiskyAllowed(true);
$this->setRules();
}
Expand Down
27 changes: 13 additions & 14 deletions src/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

namespace Realodix\Relax;

use PhpCsFixer\Finder as PhpCsFixerFinder;
use PhpCsFixer\Finder as BaseFinder;

class Finder extends PhpCsFixerFinder
/**
* {@inheritDoc}
*
* @see https://symfony.com/doc/current/components/finder.html
* @see https://github.com/symfony/finder/blob/7.1/Finder.php
* @see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/src/Finder.php
*/
class Finder extends BaseFinder
{
/**
* @param null|string|list<string> $baseDir
* @return \PhpCsFixer\Finder
*/
public static function base($baseDir = null)
public static function base()
{
if ($baseDir === null) {
$baseDir = getcwd() === false ? '' : getcwd();
}

return PhpCsFixerFinder::create()
->in($baseDir)
return self::create()
->ignoreVCS(true)
->ignoreDotFiles(true)
->notName([
Expand All @@ -26,18 +27,16 @@ public static function base($baseDir = null)
'_ide_helper.php',
'.phpstorm.meta.php',
])->exclude([
'build',
'node_modules',
]);
}

/**
* @param null|string|list<string> $baseDir
* @return \PhpCsFixer\Finder
*/
public static function laravel($baseDir = null)
public static function laravel()
{
return self::base($baseDir)
return self::base()
->exclude([
'bootstrap/cache',
'public',
Expand Down

0 comments on commit a532bea

Please sign in to comment.