Repository: friendsoftwig/twigcs (php)

Issue:
Support config files with `.php` extension
In addition to the already supported `.twig_cs` and `.twig_cs.dist` files, I suggest to add the support for `.twig_cs.php` and `.twig_cs.dist.php`
Inspired from PHP-CS-Fixer, they already did that in https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/5607, they also have removed the support of old names in https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/5609

Benefits of this move are:
- IDE will automatically detect the file as being a PHP file
- the config file can be targeted in a generic way with `*.php` like other PHP files to be included in other CS tools like PHP-CS-Fixer, PHP_CodeSniffer, etc, no need to maintain it as a particular case

I can try to come with a PR if the idea is accepted

Pull request:
Add support for config files with `.php` extension
Fixes #246

Better reviewed commit by commit

Patch:
diff --git a/README.md b/README.md
index 63f13cb..ad8ef5a 100644
--- a/README.md
+++ b/README.md
@@ -121,7 +121,7 @@ For more complex needs, have a look at the [custom ruleset documentation](doc/ru
 Using configuration, you can easily store per-project settings:
 
 ```php
-// ~/.twig_cs.dist
+// ~/.twig_cs.dist.php
 <?php
 
 return \FriendsOfTwig\Twigcs\Config\Config::create()
@@ -140,15 +140,22 @@ you must use the `--config` option:
 
 ```
 cd ~/dirA
-twigcs --config ~/dirB/.twig_cs.dist # Will lint templates in ~/dirA with the config of ~/dirB
+twigcs --config ~/dirB/.twig_cs.dist.php # Will lint templates in ~/dirA with the config of ~/dirB
 ```
 
-By default, the files `.twig_cs` and `.twig_cs.dist` are looked up in your current working directory (CWD).
+By default, the files
+
+- `.twig_cs.php`
+- `.twig_cs`
+- `.twig_cs.dist.php`
+- `.twig_cs.dist`
+
+are looked up in your current working directory (CWD).
 
 You can also provide finders inside config files, they will completely replace the path in the CLI:
 
 ```php
-// ~/.twig_cs.dist
+// ~/.twig_cs.dist.php
 <?php
 
 $finderA = FriendsOfTwig\Twigcs\Finder\TemplateFinder::create()->in(__DIR__.'/dirA');
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 610c19c..8381c7b 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -88,7 +88,9 @@
     <MixedInferredReturnType occurrences="1">
       <code>string</code>
     </MixedInferredReturnType>
-    <MixedOperand occurrences="3">
+    <MixedOperand occurrences="5">
+      <code>$configDir</code>
+      <code>$configDir</code>
       <code>$configDir</code>
       <code>$configDir</code>
       <code>$cwd</code>
diff --git a/src/Config/ConfigResolver.php b/src/Config/ConfigResolver.php
index 9929caa..3a822a0 100644
--- a/src/Config/ConfigResolver.php
+++ b/src/Config/ConfigResolver.php
@@ -337,7 +337,9 @@ final class ConfigResolver
         $configDir = $this->cwd;
 
         return [
+            $configDir.\DIRECTORY_SEPARATOR.'.twig_cs.php',
             $configDir.\DIRECTORY_SEPARATOR.'.twig_cs',
+            $configDir.\DIRECTORY_SEPARATOR.'.twig_cs.dist.php',
             $configDir.\DIRECTORY_SEPARATOR.'.twig_cs.dist',
         ];
     }


Test patch:
diff --git a/tests/Config/ConfigResolverTest.php b/tests/Config/ConfigResolverTest.php
index 41c57a6..aa452a3 100644
--- a/tests/Config/ConfigResolverTest.php
+++ b/tests/Config/ConfigResolverTest.php
@@ -143,11 +143,34 @@ PHP;
     public function provideDefaultConfigFileNameAndAvailableDefaultConfigFileNames(): array
     {
         return [
+            [
+                '.twig_cs.php',
+                [
+                    '.twig_cs',
+                    '.twig_cs.dist',
+                    '.twig_cs.dist.php',
+                    '.twig_cs.php',
+                ],
+            ],
             [
                 '.twig_cs',
                 [
                     '.twig_cs',
                     '.twig_cs.dist',
+                    '.twig_cs.dist.php',
+                ],
+            ],
+            [
+                '.twig_cs.dist.php',
+                [
+                    '.twig_cs.dist',
+                    '.twig_cs.dist.php',
+                ],
+            ],
+            [
+                '.twig_cs.dist',
+                [
+                    '.twig_cs.dist',
                 ],
             ],
         ];
@@ -278,6 +301,8 @@ PHP;
         $defaultConfigFileNames = [
             '.twig_cs',
             '.twig_cs.dist',
+            '.twig_cs.dist.php',
+            '.twig_cs.php',
         ];
 
         foreach ($defaultConfigFileNames as $defaultConfigFileName) {
diff --git a/tests/Console/LintCommandTest.php b/tests/Console/LintCommandTest.php
index 4db4b50..68b014f 100644
--- a/tests/Console/LintCommandTest.php
+++ b/tests/Console/LintCommandTest.php
@@ -192,7 +192,7 @@ class LintCommandTest extends TestCase
     {
         $this->commandTester->execute([
             'paths' => null,
-            '--config' => 'tests/data/config/external/.twig_cs.dist',
+            '--config' => 'tests/data/config/external/.twig_cs.dist.php',
         ]);
 
         $output = $this->commandTester->getDisplay();
@@ -209,7 +209,7 @@ l.1 c.8 : WARNING Unused variable "foo".
     {
         $this->commandTester->execute([
             'paths' => ['tests/data/syntax_error'],
-            '--config' => 'tests/data/config/external/.twig_cs.dist',
+            '--config' => 'tests/data/config/external/.twig_cs.dist.php',
         ]);
 
         $output = $this->commandTester->getDisplay();
@@ -227,7 +227,7 @@ l.1 c.17 : ERROR Unexpected "}".
     public function testConfigFileWithDisplayAndSeverity()
     {
         $this->commandTester->execute([
-            '--config' => 'tests/data/config/external/.twig_cs_with_display_blocking.dist',
+            '--config' => 'tests/data/config/external/.twig_cs_with_display_blocking.dist.php',
         ]);
 
         $output = $this->commandTester->getDisplay();
@@ -271,7 +271,7 @@ l.1 c.17 : ERROR Unexpected "}".
     public function testUnusedWithFileLoader()
     {
         $this->commandTester->execute([
-            '--config' => 'tests/data/config/loaders/.twig_cs.dist',
+            '--config' => 'tests/data/config/loaders/.twig_cs.dist.php',
         ]);
 
         $output = $this->commandTester->getDisplay();
diff --git a/tests/data/config/external/.twig_cs.dist b/tests/data/config/external/.twig_cs.dist.php
similarity index 100%
rename from tests/data/config/external/.twig_cs.dist
rename to tests/data/config/external/.twig_cs.dist.php
diff --git a/tests/data/config/external/.twig_cs_with_display_blocking.dist b/tests/data/config/external/.twig_cs_with_display_blocking.dist.php
similarity index 100%
rename from tests/data/config/external/.twig_cs_with_display_blocking.dist
rename to tests/data/config/external/.twig_cs_with_display_blocking.dist.php
diff --git a/tests/data/config/loaders/.twig_cs.dist b/tests/data/config/loaders/.twig_cs.dist.php
similarity index 100%
rename from tests/data/config/loaders/.twig_cs.dist
rename to tests/data/config/loaders/.twig_cs.dist.php
diff --git a/tests/data/config/namespaced_loaders/.twig_cs.dist b/tests/data/config/namespaced_loaders/.twig_cs.dist
deleted file mode 100644
index 92a46fb..0000000
--- a/tests/data/config/namespaced_loaders/.twig_cs.dist
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-
-use FriendsOfTwig\Twigcs\TemplateResolver\FileResolver;
-use FriendsOfTwig\Twigcs\TemplateResolver\NamespacedResolver;
-
-$finder = FriendsOfTwig\Twigcs\Finder\TemplateFinder::create()
-    ->in(__DIR__)
-;
-
-return \FriendsOfTwig\Twigcs\Config\Config::create()
-    ->setFinder($finder)
-    ->setTemplateResolver(new NamespacedResolver([
-        'a' => new FileResolver(__DIR__.'/a'),
-        'b' => new FileResolver(__DIR__.'/b'),
-    ]))
-    ->setSeverity('warning')
-    ->setReporter('console')
-    ->setName('my-config')
-    ->setRuleSet(FriendsOfTwig\Twigcs\Ruleset\Official::class)
-;
diff --git a/tests/data/config/namespaced_loaders/a/child.html.twig b/tests/data/config/namespaced_loaders/a/child.html.twig
deleted file mode 100644
index 055f6d2..0000000
--- a/tests/data/config/namespaced_loaders/a/child.html.twig
+++ /dev/null
@@ -1,3 +0,0 @@
-{{ foo }}
-
-{% set unused_child = 1 %}
diff --git a/tests/data/config/namespaced_loaders/b/parent.html.twig b/tests/data/config/namespaced_loaders/b/parent.html.twig
deleted file mode 100644
index 3b8c850..0000000
--- a/tests/data/config/namespaced_loaders/b/parent.html.twig
+++ /dev/null
@@ -1,4 +0,0 @@
-{% set foo = 1 %}
-{% set unused_parent = 2 %}
-
-{% embed '@c/child.html.twig' %}
\ No newline at end of file