You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h1>Config file<aclass="headerlink" href="#config-file" title="Permalink to this heading">¶</a></h1>
55
55
<sectionid="no-config">
56
56
<h2>No config<aclass="headerlink" href="#no-config" title="Permalink to this heading">¶</a></h2>
57
-
<p>It is possible to <em>not</em> have the config file. In that case, the default rule set (@PSR12) will be applied, yet the path will need to be provided via CLI.</p>
57
+
<p>It is possible to <em>not</em> have the config file. In that case, the default rule set (<codeclass="docutils literal notranslate"><spanclass="pre">@PSR12</span></code> for v3, <codeclass="docutils literal notranslate"><spanclass="pre">@auto</span></code> for v4) will be applied,
58
+
and under v3, the path will need to be provided via CLI (defaults to <codeclass="docutils literal notranslate"><spanclass="pre">.</span></code> under v4).</p>
<p>It is also possible to provide command line options to customize rules, yet instead of using them,
62
+
<p>While it is possible to provide command line options to configure rules,
62
63
it’s recommended to save the project configuration in a <codeclass="docutils literal notranslate"><spanclass="pre">.php-cs-fixer.dist.php</span></code> file in the root directory of your project.
63
-
The file must return an instance of <aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.89.2/src/ConfigInterface.php">PhpCsFixer\ConfigInterface</a>
64
-
which lets you configure the rules, the files and directories that
65
-
need to be analysed. You may also create <codeclass="docutils literal notranslate"><spanclass="pre">.php-cs-fixer.php</span></code> file, which is
66
-
the local configuration that will be used instead of the project configuration. It
67
-
is a good practice to add that file into your <codeclass="docutils literal notranslate"><spanclass="pre">.gitignore</span></code> file.
68
-
With the <codeclass="docutils literal notranslate"><spanclass="pre">--config</span></code> option you can specify the path to the config file.</p>
64
+
The file must return an instance of <aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.90.0/src/ConfigInterface.php">PhpCsFixer\ConfigInterface</a>,
65
+
which lets you configure the rules, finder (the files and directories that
66
+
need to be analysed), select output format and even configure path to <codeclass="docutils literal notranslate"><spanclass="pre">PHP</span></code>.</p>
67
+
<p>You may also create <codeclass="docutils literal notranslate"><spanclass="pre">.php-cs-fixer.php</span></code> file, which is
68
+
the local configuration that will be used instead of the project configuration.
69
+
You can use it to customize for your environment (like path to <codeclass="docutils literal notranslate"><spanclass="pre">PHP</span></code>) or preference (like output format or progress indicator),
70
+
while ruleset / finder shall be re-imported from project configuration.
71
+
It is a good practice to add that file into your <codeclass="docutils literal notranslate"><spanclass="pre">.gitignore</span></code> file.</p>
72
+
<p>With the <codeclass="docutils literal notranslate"><spanclass="pre">--config</span></code> option you can specify the path to the config file, when it is named differently.</p>
69
73
</section>
70
74
<sectionid="the-simplest-config">
71
75
<h2>The simplest config<aclass="headerlink" href="#the-simplest-config" title="Permalink to this heading">¶</a></h2>
@@ -66,8 +66,8 @@ <h2>Background<a class="headerlink" href="#background" title="Permalink to this
66
66
discouraged - it is meant only to give more people more chance to
67
67
contribute, and to detect bugs (<aclass="reference external" href="https://en.wikipedia.org/wiki/Linus%27s_Law">Linus’s Law</a>).</p>
68
68
<p>If possible, try to get acquainted with the public interface for the
69
-
<aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.89.2/src/Tokenizer/Tokens.php">PhpCsFixer\Tokenizer\Tokens</a> and
<aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.90.0/src/Tokenizer/Tokens.php">PhpCsFixer\Tokenizer\Tokens</a> and
<h2>Assumptions<aclass="headerlink" href="#assumptions" title="Permalink to this heading">¶</a></h2>
@@ -81,8 +81,8 @@ <h2>Assumptions<a class="headerlink" href="#assumptions" title="Permalink to thi
81
81
</ul>
82
82
<p>In case you want to create a custom fixer for your own use, you can
83
83
follow this guide as well, but you will need to apply some changes on the go,
84
-
for example use <aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.89.2/src/Fixer/FixerInterface.php">PhpCsFixer\Fixer\FixerInterface</a>
85
-
instead of <aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.89.2/src/AbstractFixer.php">PhpCsFixer\AbstractFixer</a> (which is internal
84
+
for example use <aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.90.0/src/Fixer/FixerInterface.php">PhpCsFixer\Fixer\FixerInterface</a>
85
+
instead of <aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.90.0/src/AbstractFixer.php">PhpCsFixer\AbstractFixer</a> (which is internal
<p>Note how the class and file name match. Also keep in mind that all
140
-
fixers must implement <aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.89.2/src/Fixer/FixerInterface.php">PhpCsFixer\Fixer\FixerInterface</a>. In this case, the fixer is
141
-
inheriting from <aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.89.2/src/AbstractFixer.php">PhpCsFixer\AbstractFixer</a>, which fulfills the interface with some
140
+
fixers must implement <aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.90.0/src/Fixer/FixerInterface.php">PhpCsFixer\Fixer\FixerInterface</a>. In this case, the fixer is
141
+
inheriting from <aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.90.0/src/AbstractFixer.php">PhpCsFixer\AbstractFixer</a>, which fulfills the interface with some
142
142
default behaviour.</p>
143
143
<p>Now let us create the test file at
144
144
<codeclass="docutils literal notranslate"><spanclass="pre">tests/Fixer/Comment/RemoveCommentsFixerTest.php</span></code>. Put this content inside:</p>
<p>If you need to enforce some specific code style rules, you can implement your
56
56
own fixers. There is a <aclass="reference internal" href="cookbook_fixers.html"><spanclass="doc">cookbook</span></a> with basic instructions on how to build a new fixer.</p>
57
57
<p>For each rule you want to add, create a class that implements
<p>There are several interfaces that your fixers can also implement if needed:</p>
80
80
<ulclass="simple">
81
-
<li><p><aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.89.2/src/Fixer/WhitespacesAwareFixerInterface.php">PhpCsFixer\Fixer\WhitespacesAwareFixerInterface</a>: for fixers that need to know the configured indentation and line endings;</p></li>
82
-
<li><p><aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.89.2/src/Fixer/ConfigurableFixerInterface.php">PhpCsFixer\Fixer\ConfigurableFixerInterface</a>: to create a configurable fixer;</p></li>
83
-
<li><p><aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.89.2/src/Fixer/DeprecatedFixerInterface.php">PhpCsFixer\Fixer\DeprecatedFixerInterface</a>: to deprecate a fixer.</p></li>
81
+
<li><p><aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.90.0/src/Fixer/WhitespacesAwareFixerInterface.php">PhpCsFixer\Fixer\WhitespacesAwareFixerInterface</a>: for fixers that need to know the configured indentation and line endings;</p></li>
82
+
<li><p><aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.90.0/src/Fixer/ConfigurableFixerInterface.php">PhpCsFixer\Fixer\ConfigurableFixerInterface</a>: to create a configurable fixer;</p></li>
83
+
<li><p><aclass="reference external" href="https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.90.0/src/Fixer/DeprecatedFixerInterface.php">PhpCsFixer\Fixer\DeprecatedFixerInterface</a>: to deprecate a fixer.</p></li>
<h1>Rule set <codeclass="docutils literal notranslate"><spanclass="pre">@auto</span></code><aclass="headerlink" href="#rule-set-auto" title="Permalink to this heading">¶</a></h1>
55
-
<p>Default rule set. Applies newest PER-CS and optimizations for PHP, based on project’s “composer.json” file.</p>
55
+
<p>Default rule set. Applies newest <codeclass="docutils literal notranslate"><spanclass="pre">PER-CS</span></code> and optimizations for <codeclass="docutils literal notranslate"><spanclass="pre">PHP</span></code>, based on project’s <codeclass="docutils literal notranslate"><spanclass="pre">composer.json</span></code> file.</p>
56
56
<sectionid="warning">
57
57
<h2>Warning<aclass="headerlink" href="#warning" title="Permalink to this heading">¶</a></h2>
<h1>Rule set <codeclass="docutils literal notranslate"><spanclass="pre">@autoPHPMigration</span></code><aclass="headerlink" href="#rule-set-autophpmigration" title="Permalink to this heading">¶</a></h1>
55
-
<p>Rules to improve code for PHP. Target version is automatically detected from project’s “composer.json” file.</p>
55
+
<p>Migration rules to improve code towards the minimum <codeclass="docutils literal notranslate"><spanclass="pre">PHP</span></code> supported by your project (taken from <codeclass="docutils literal notranslate"><spanclass="pre">composer.json</span></code> file).</p>
56
56
<sectionid="warning">
57
57
<h2>Warning<aclass="headerlink" href="#warning" title="Permalink to this heading">¶</a></h2>
<h1>Rule set <codeclass="docutils literal notranslate"><spanclass="pre">@autoPHPMigration:risky</span></code><aclass="headerlink" href="#rule-set-autophpmigration-risky" title="Permalink to this heading">¶</a></h1>
55
-
<p>Rules to improve code for PHP. Target version is automatically detected from project’s “composer.json” file.</p>
55
+
<p>Migration rules to improve code towards the minimum <codeclass="docutils literal notranslate"><spanclass="pre">PHP</span></code> supported by your project (taken from <codeclass="docutils literal notranslate"><spanclass="pre">composer.json</span></code> file).</p>
56
56
<sectionid="warnings">
57
57
<h2>Warnings<aclass="headerlink" href="#warnings" title="Permalink to this heading">¶</a></h2>
<h1>Rule set <codeclass="docutils literal notranslate"><spanclass="pre">@autoPHPUnitMigration:risky</span></code><aclass="headerlink" href="#rule-set-autophpunitmigration-risky" title="Permalink to this heading">¶</a></h1>
55
-
<p>Rules to improve test code for PHPUnit. Target version is automatically detected from project’s “composer.json” file.</p>
55
+
<p>Migration rules to improve test code towards the minimum <codeclass="docutils literal notranslate"><spanclass="pre">PHPUnit</span></code> supported by your project (taken from <codeclass="docutils literal notranslate"><spanclass="pre">composer.json</span></code> file).</p>
56
56
<sectionid="warnings">
57
57
<h2>Warnings<aclass="headerlink" href="#warnings" title="Permalink to this heading">¶</a></h2>
<h1>Rule set <codeclass="docutils literal notranslate"><spanclass="pre">@auto:risky</span></code><aclass="headerlink" href="#rule-set-auto-risky" title="Permalink to this heading">¶</a></h1>
55
-
<p>Default (risky) rule set. Applies newest PER-CS and optimizations for PHP and PHPUnit, based on project’s “composer.json” file.</p>
55
+
<p>Default (risky) rule set. Applies newest <codeclass="docutils literal notranslate"><spanclass="pre">PER-CS</span></code> and optimizations for <codeclass="docutils literal notranslate"><spanclass="pre">PHP</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">PHPUnit</span></code>, based on project’s <codeclass="docutils literal notranslate"><spanclass="pre">composer.json</span></code> file.</p>
56
56
<sectionid="warnings">
57
57
<h2>Warnings<aclass="headerlink" href="#warnings" title="Permalink to this heading">¶</a></h2>
0 commit comments