问题
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)
;
回答1:
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.
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)
回答2:
Very important do not use path argument in terminal command Example:
php-cs-fixer fix test/global.php
cs fixer use path from command argument, NOT finder
Just run with
php-cs-fixer fix
It is simple, but you can skip it by inattention
来源:https://stackoverflow.com/questions/48967493/how-to-use-other-file-extensions-in-php-cs-fixer-for-example-ctp