【问题标题】:How to use other file extensions in php-cs-fixer, for example .ctp?如何在 php-cs-fixer 中使用其他文件扩展名,例如 .ctp?
【发布时间】:2018-02-24 20:52:54
【问题描述】:

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

我已经尝试过这段代码:

<?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)
;

【问题讨论】:

    标签: cakephp php-cs-fixer


    【解决方案1】:

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

    Paths from configuration file have been overridden by paths provided as command arguments.
    

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

    【讨论】:

    【解决方案2】:

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

    php-cs-fixer fix test/global.php
    

    cs fixer 使用来自命令参数的路径,而不是查找器

    只需运行

    php-cs-fixer fix 
    

    很简单,但是一不留神就可以跳过

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-31
      • 1970-01-01
      • 2018-02-11
      • 2018-02-12
      • 2018-02-28
      • 1970-01-01
      相关资源
      最近更新 更多