From 87ed01e7befb00682950bb8e1b810e5bd895b106 Mon Sep 17 00:00:00 2001 From: onigra <3280467rec@gmail.com> Date: Sat, 11 Feb 2017 20:37:21 +0900 Subject: [PATCH] Enable PHP-CS-Fixer Path option except Windows --- src/beautifiers/php-cs-fixer.coffee | 81 +++++++++++++++-------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/beautifiers/php-cs-fixer.coffee b/src/beautifiers/php-cs-fixer.coffee index 0cf8f01..0b8ec16 100644 --- a/src/beautifiers/php-cs-fixer.coffee +++ b/src/beautifiers/php-cs-fixer.coffee @@ -19,21 +19,22 @@ module.exports = class PHPCSFixer extends Beautifier configFile = if context? and context.filePath? then @findFile(path.dirname(context.filePath), '.php_cs') - 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 + # 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 + if @isWindows @run("php", [ phpCSFixerPath "fix" @@ -51,30 +52,30 @@ module.exports = class PHPCSFixer extends Beautifier @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" + @run(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" + } }) - ) - ) - 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) + .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" + }) ) + )