DRY php-cs-fixer options

This commit is contained in:
onigra 2017-02-11 20:49:42 +09:00
parent bf7586c858
commit c48989d9a9
1 changed files with 10 additions and 15 deletions

View File

@ -18,6 +18,12 @@ module.exports = class PHPCSFixer extends Beautifier
@debug('php-cs-fixer', options)
configFile = if context? and context.filePath? then @findFile(path.dirname(context.filePath), '.php_cs')
phpCsFixerOptions = [
"fix"
"--level=#{options.level}" if options.level
"--fixers=#{options.fixers}" if options.fixers
"--config-file=#{configFile}" if configFile
]
runOptions = {
ignoreReturnCode: true
help: {
@ -40,26 +46,15 @@ module.exports = class PHPCSFixer extends Beautifier
# Check if PHP-CS-Fixer path was found
if phpCSFixerPath?
# Found PHP-CS-Fixer path
if @isWindows
@run("php", [
phpCSFixerPath
"fix"
"--level=#{options.level}" if options.level
"--fixers=#{options.fixers}" if options.fixers
"--config-file=#{configFile}" if configFile
tempFile = @tempFile("temp", text)
], runOptions)
if @isWindows
@run("php", [phpCSFixerPath, phpCsFixerOptions, tempFile], runOptions)
.then(=>
@readFile(tempFile)
)
else
@run(phpCSFixerPath, [
"fix"
"--level=#{options.level}" if options.level
"--fixers=#{options.fixers}" if options.fixers
"--config-file=#{configFile}" if configFile
tempFile = @tempFile("temp", text)
], runOptions)
@run(phpCSFixerPath, [phpCsFixerOptions, tempFile], runOptions)
.then(=>
@readFile(tempFile)
)