Skip to content

Expose the default Finder as Config::finder() - #50

Closed
alies-dev wants to merge 1 commit into
mainfrom
0-expose-default-finder
Closed

alies-dev wants to merge 1 commit into
mainfrom
0-expose-default-finder

Conversation

@alies-dev

Copy link
Copy Markdown
Member

Context

A project that needs one extra exclude has to replace the default Finder, and with it every default exclude:

$finder = Finder::create()->in(__DIR__)->exclude(['tools']);

return Config::create(__DIR__, finder: $finder);

PhpCsFixer\Finder does not skip gitignored files, so this Finder goes into .cache/, node_modules/ and storage/. In IxDF-web the search alone took about 60s (.cache/ holds 1.7M files). It also picked up generated PHPStan cache files in storage/, one of them 1.5MB, and php-cs-fixer workers ran out of memory on them at the default 128M (Allowed memory size of 134217728 bytes exhausted). Every composer cs failed after about a minute of no output. The README's customization example showed exactly this pattern, and this package's own .php-cs-fixer.dist.php followed it.

Solution

The default Finder is now public as Config::finder(), so projects extend it instead of replacing it:

$finder = Config::finder(__DIR__)->exclude(['tools']);

The README example and this package's own config now use it. On IxDF-web, the same exclusion rules cut a php-cs-fixer run with a warm cache from about 60s to 2s, with no out-of-memory crash.

public/ is no longer excluded by default: it holds tracked code such as Laravel's public/index.php, and gitignored build output in it is still skipped by ignoreVCSIgnored(). Projects that want it out can add ->exclude(['public']).

Config::create() does not patch a Finder you pass in. Adding ignoreVCSIgnored() alone would not fix the speed (Symfony filters ignored files only after walking into them; only exclude() stops the walk), and changing a caller's object would leave no way to opt out.

Projects passing a custom Finder lost the default excludes: PhpCsFixer\Finder
lints gitignored files and walks .cache/node_modules, which made IxDF-web
runs take ~60s and OOM workers on generated PHP in storage/.

- Make the default Finder public so projects extend instead of replace it
- Stop excluding public/: it holds tracked code like public/index.php
@alies-dev alies-dev self-assigned this Nov 24, 2026
@alies-dev alies-dev closed this Nov 24, 2026
@alies-dev
alies-dev deleted the 0-expose-default-finder branch November 24, 2026 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant