Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: config file - provide better link to Finder docs #6992

Merged
merged 9 commits into from
Oct 29, 2023
21 changes: 17 additions & 4 deletions doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,27 @@ With the ``--config`` option you can specify the path to the

The example below will add two rules to the default list of PSR12 set rules:

Consider your codebase as follow:

```
├── .php-cs-fixer.php
└── src
├── foo.php
├── bar.php
├── somedir
└── maindir
├── subdir
└── baz.php
```

keradus marked this conversation as resolved.
Show resolved Hide resolved
.. code-block:: php

<?php

$finder = PhpCsFixer\Finder::create()
->exclude('somedir')
->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php')
->in(__DIR__)
->in(__DIR__) // 'src'
keradus marked this conversation as resolved.
Show resolved Hide resolved
keradus marked this conversation as resolved.
Show resolved Hide resolved
->exclude(['somedir', 'foo.php'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
->exclude(['somedir', 'foo.php'])
->exclude('somedir')

As you can see below:

NOTE: exclude will work only for directories, so if you need to exclude file, try notPath.

keradus marked this conversation as resolved.
Show resolved Hide resolved
->notPath('bar.php')
keradus marked this conversation as resolved.
Show resolved Hide resolved
;

$config = new PhpCsFixer\Config();
Expand All @@ -36,7 +49,7 @@ The example below will add two rules to the default list of PSR12 set rules:
**NOTE**: ``exclude`` will work only for directories, so if you need to exclude file, try ``notPath``.
keradus marked this conversation as resolved.
Show resolved Hide resolved
Both ``exclude`` and ``notPath`` methods accept only relative paths to the ones defined with the ``in`` method.
keradus marked this conversation as resolved.
Show resolved Hide resolved

See `Symfony\\Finder <https://symfony.com/doc/current/components/finder.html>`_
See `Symfony\\Finder <https://symfony.com/doc/current/components/finder.html#location>`_
online documentation for other `Finder` methods.

You may also use an exclude list for the rules instead of the above shown include approach.
Expand Down