diff --git a/src/beautifiers/php-cs-fixer.coffee b/src/beautifiers/php-cs-fixer.coffee index 959432d..5dfa56d 100644 --- a/src/beautifiers/php-cs-fixer.coffee +++ b/src/beautifiers/php-cs-fixer.coffee @@ -19,63 +19,55 @@ 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: { + link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" + } + } - if @isWindows - # Find php-cs-fixer.phar script - @Promise.all([ - @which(options.cs_fixer_path) if options.cs_fixer_path - @which('php-cs-fixer') - ]).then((paths) => - @debug('php-cs-fixer paths', paths) - _ = require 'lodash' - # Get first valid, absolute path - phpCSFixerPath = _.find(paths, (p) -> p and path.isAbsolute(p) ) - @verbose('phpCSFixerPath', phpCSFixerPath) - @debug('phpCSFixerPath', phpCSFixerPath, paths) - # Check if PHP-CS-Fixer path was found - if phpCSFixerPath? - # Found PHP-CS-Fixer path - @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) - ], { - ignoreReturnCode: true - help: { - link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" - } - }) + # Find php-cs-fixer.phar script + @Promise.all([ + @which(options.cs_fixer_path) if options.cs_fixer_path + @which('php-cs-fixer') + ]).then((paths) => + @debug('php-cs-fixer paths', paths) + _ = require 'lodash' + # Get first valid, absolute path + phpCSFixerPath = _.find(paths, (p) -> p and path.isAbsolute(p) ) + @verbose('phpCSFixerPath', phpCSFixerPath) + @debug('phpCSFixerPath', phpCSFixerPath, paths) + + # Check if PHP-CS-Fixer path was found + if phpCSFixerPath? + # Found PHP-CS-Fixer path + tempFile = @tempFile("temp", text) + + if @isWindows + @run("php", [phpCSFixerPath, phpCsFixerOptions, tempFile], runOptions) .then(=> @readFile(tempFile) ) else - @verbose('php-cs-fixer not found!') - # Could not find PHP-CS-Fixer path - @Promise.reject(@commandNotFoundError( - 'php-cs-fixer' - { + @run(phpCSFixerPath, [phpCsFixerOptions, tempFile], runOptions) + .then(=> + @readFile(tempFile) + ) + else + @verbose('php-cs-fixer not found!') + # Could not find PHP-CS-Fixer path + @Promise.reject(@commandNotFoundError( + 'php-cs-fixer' + { link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" program: "php-cs-fixer.phar" pathOption: "PHP - CS Fixer Path" - }) - ) - ) - else - @run("php-cs-fixer", [ - "fix" - "--level=#{options.level}" if options.level - "--fixers=#{options.fixers}" if options.fixers - "--config-file=#{configFile}" if configFile - tempFile = @tempFile("temp", text) - ], { - ignoreReturnCode: true - help: { - link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" - } - }) - .then(=> - @readFile(tempFile) + }) ) + )