首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在php-cs-fixer中使用其他文件扩展名,例如.ctp?

如何在php-cs-fixer中使用其他文件扩展名,例如.ctp?
EN

Stack Overflow用户
提问于 2018-02-25 04:52:55
回答 2查看 1.1K关注 0票数 1

如何在php-cs-fixer中使用其他文件扩展名,例如cakephp模板.ctp文件?

我试过这段代码:

代码语言:javascript
复制
<?php
$finder = PhpCsFixer\Finder::create()
    ->notPath('bootstrap/cache')
    ->notPath('storage')
    ->notPath('vendor')
    ->in(__DIR__)
    ->name('*.php') // <===== *.ctp
    ->notName('*.blade.php')
    ->ignoreDotFiles(true)
    ->ignoreVCS(true)
;

return PhpCsFixer\Config::create()
    ->setRules(array(
        '@Symfony' => true,
        'binary_operator_spaces' => ['align_double_arrow' => false],
        'array_syntax' => ['syntax' => 'short'],
        'linebreak_after_opening_tag' => true,
        'not_operator_with_successor_space' => true,
        'ordered_imports' => true,
        'phpdoc_order' => true,
    ))
    ->setFinder($finder)
;
EN

回答 2

Stack Overflow用户

发布于 2018-06-18 19:32:11

问题是,使用运行PHP CS Fixer的原始方法,您在配置文件中配置了一次路径查找器,然后将路径也作为CLI参数传递。因此,您在配置中完全定义了finder,但后来被CLI参数覆盖,您还会收到一条消息:

代码语言:javascript
复制
Paths from configuration file have been overridden by paths provided as command arguments.

解决方案是:-仅在配置文件中提供路径-仅提供路径作为CLI参数-在两个位置都提供路径(例如,在配置plugins中,而作为CLI参数plugins/subdir (因为传递完全相同的值实际上没有意义...),但也提供--path-mode=intersection参数,以不覆盖路径,但采用路径的公共部分(一个在配置中,一个作为CLI参数)

票数 0
EN

Stack Overflow用户

发布于 2019-09-27 16:27:49

非常重要的一点是,不要在终端命令示例中使用路径参数:

代码语言:javascript
复制
php-cs-fixer fix test/global.php

cs修复程序使用来自命令参数的路径,而不是查找器

只需运行

代码语言:javascript
复制
php-cs-fixer fix 

这很简单,但你可以通过疏忽跳过它。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48967493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档