在 Symfony Finder / PHP-CS-Fixer 中获取非 PHP 文件扩展名
Getting Non PHP File Extensions in Symfony Finder / PHP-CS-Fixer
正在努力为我的查找器添加非 php 扩展。进行了长时间的 google 搜索,但一无所获。找到这个但不太明白:How to use other file extensions in php-cs-fixer, for example .ctp?
这是我的:
<?php
$finder = PhpCsFixer\Finder::create()
->notPath('path/to/some/file.inc')
->notPath('path/to/some/file.class')
->in(__DIR__)
->name('*.php')
->name('*.inc')
->name('*.class');
return PhpCsFixer\Config::create()
->setRules(
array(
'Rule 1' => true,
...
'Rule n' => true,
)
)
->setFinder($finder);
我希望它能处理 *.inc 和 *.class 文件,但它似乎只选择 *.php 文件。
关于我可能遗漏了什么的任何线索?
PS
我忘了补充一点,尝试单个 ->name('/(\.php|\.inc|\.class)$/');
没有区别。它仍然只选择 *.php 个文件。
此外,请给我一个明确的答案,而不是不加解释地否决我……我做错了什么吗?如果是这样,请指出这一点。
您的问题描述不完整,无法重现。
ker@dus:~/github/PHP-CS-Fixer λ cat .php_cs.dist
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/example')
->name('*.inc')
;
return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
])
->setFinder($finder)
;
ker@dus:~/github/PHP-CS-Fixer λ ls -al example/
total 16
drwxr-xr-x 2 keradus keradus 4096 cze 18 13:20 .
drwxr-xr-x 11 keradus keradus 4096 cze 18 10:20 ..
-rw-rw-r-- 1 keradus keradus 1550 cze 17 12:00 FileReader.php
-rw-rw-r-- 1 keradus keradus 1507 cze 18 13:20 FileRemoval.inc
ker@dus:~/github/PHP-CS-Fixer λ php php-cs-fixer fix -vv --dry-run --diff --diff-format=udiff
Loaded config default from "/home/keradus/github/PHP-CS-Fixer/.php_cs.dist".
.F
Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error
1) example/FileRemoval.inc (braces)
---------- begin diff ----------
--- Original
+++ New
@@ -29,7 +29,8 @@
*/
private $files = [];
- public function __construct() {
+ public function __construct()
+ {
register_shutdown_function([$this, 'clean']);
}
----------- end diff -----------
Checked all files in 0.027 seconds, 12.000 MB memory used
*.inc
文件已修复
** 由 OP 编辑 **
在项目 gitter 页面上获得一些大力支持后:https://gitter.im/PHP-CS-Fixer/Lobby,事实证明问题是我在命令行上调用东西的方式覆盖了我的配置文件中的路径信息。
一条线索是 CLI 消息 Paths from configuration file have been overridden by paths provided as command arguments
。
我原来的命令是...
php php-cs-fixer fix /path/to/project/folder --config /path/to/config/file/.php_cs.dist
应该使用的两个选项:
跳过/path/to/project/folder
正确的命令 = php php-cs-fixer fix --config /path/to/config/file/.php_cs.dist
。根据开发者的说法,这可能有一个缺点,即可能无法 运行 具有根项目子路径的工具。
在 CLI 语句中添加一个 -path-mode=intersection
标志,使它们相互配合。正确的命令 = php php-cs-fixer fix /path/to/project/folder --config /path/to/config/file/.php_cs.dist --path-mode=intersection
正在努力为我的查找器添加非 php 扩展。进行了长时间的 google 搜索,但一无所获。找到这个但不太明白:How to use other file extensions in php-cs-fixer, for example .ctp?
这是我的:
<?php
$finder = PhpCsFixer\Finder::create()
->notPath('path/to/some/file.inc')
->notPath('path/to/some/file.class')
->in(__DIR__)
->name('*.php')
->name('*.inc')
->name('*.class');
return PhpCsFixer\Config::create()
->setRules(
array(
'Rule 1' => true,
...
'Rule n' => true,
)
)
->setFinder($finder);
我希望它能处理 *.inc 和 *.class 文件,但它似乎只选择 *.php 文件。
关于我可能遗漏了什么的任何线索?
PS
我忘了补充一点,尝试单个 ->name('/(\.php|\.inc|\.class)$/');
没有区别。它仍然只选择 *.php 个文件。
此外,请给我一个明确的答案,而不是不加解释地否决我……我做错了什么吗?如果是这样,请指出这一点。
您的问题描述不完整,无法重现。
ker@dus:~/github/PHP-CS-Fixer λ cat .php_cs.dist
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/example')
->name('*.inc')
;
return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
])
->setFinder($finder)
;
ker@dus:~/github/PHP-CS-Fixer λ ls -al example/
total 16
drwxr-xr-x 2 keradus keradus 4096 cze 18 13:20 .
drwxr-xr-x 11 keradus keradus 4096 cze 18 10:20 ..
-rw-rw-r-- 1 keradus keradus 1550 cze 17 12:00 FileReader.php
-rw-rw-r-- 1 keradus keradus 1507 cze 18 13:20 FileRemoval.inc
ker@dus:~/github/PHP-CS-Fixer λ php php-cs-fixer fix -vv --dry-run --diff --diff-format=udiff
Loaded config default from "/home/keradus/github/PHP-CS-Fixer/.php_cs.dist".
.F
Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error
1) example/FileRemoval.inc (braces)
---------- begin diff ----------
--- Original
+++ New
@@ -29,7 +29,8 @@
*/
private $files = [];
- public function __construct() {
+ public function __construct()
+ {
register_shutdown_function([$this, 'clean']);
}
----------- end diff -----------
Checked all files in 0.027 seconds, 12.000 MB memory used
*.inc
文件已修复
** 由 OP 编辑 **
在项目 gitter 页面上获得一些大力支持后:https://gitter.im/PHP-CS-Fixer/Lobby,事实证明问题是我在命令行上调用东西的方式覆盖了我的配置文件中的路径信息。
一条线索是 CLI 消息 Paths from configuration file have been overridden by paths provided as command arguments
。
我原来的命令是...
php php-cs-fixer fix /path/to/project/folder --config /path/to/config/file/.php_cs.dist
应该使用的两个选项:
跳过
/path/to/project/folder
正确的命令 =php php-cs-fixer fix --config /path/to/config/file/.php_cs.dist
。根据开发者的说法,这可能有一个缺点,即可能无法 运行 具有根项目子路径的工具。在 CLI 语句中添加一个
-path-mode=intersection
标志,使它们相互配合。正确的命令 =php php-cs-fixer fix /path/to/project/folder --config /path/to/config/file/.php_cs.dist --path-mode=intersection