如何在php-cs-fixer中使用其他文件扩展名,例如.ctp? [英] How to use other file extensions in php-cs-fixer, for example .ctp?

查看:99
本文介绍了如何在php-cs-fixer中使用其他文件扩展名,例如.ctp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to use other file extensions in php-cs-fixer, for example cakephp template .ctp files ?

我已经尝试了以下代码:

I have trying this code:

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


推荐答案

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

Thing is, that with original way of running the PHP CS Fixer, you have path finder configured once in config file, and then you pass the path also as CLI argument. As a result - you have fully defined finder in config, which got later overwritten by CLI argument, also you got a message:

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

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

Solution is to: - provide a path only in config file - provide a path only as CLI argument - provide a path in both places (ex, in config plugins, while as CLI argument plugins/subdir (as passing exactly same value doesn't really make sense...), but then also provide --path-mode=intersection parameter, to not override the path, but take common part of paths (one in config, one as CLI arg)

这篇关于如何在php-cs-fixer中使用其他文件扩展名,例如.ctp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆