diff --git a/spec/beautifier-php-cs-fixer-spec.coffee b/spec/beautifier-php-cs-fixer-spec.coffee index a9b420da4..1e49e7061 100644 --- a/spec/beautifier-php-cs-fixer-spec.coffee +++ b/spec/beautifier-php-cs-fixer-spec.coffee @@ -123,7 +123,7 @@ describe "PHP-CS-Fixer Beautifier", -> p.then(cb, cb) return p - failWhichProgram('php') + # failWhichProgram('php') failWhichProgram('php-cs-fixer') unless isWindows diff --git a/src/beautifiers/beautifier.coffee b/src/beautifiers/beautifier.coffee index 26b797f1c..197e7a743 100644 --- a/src/beautifiers/beautifier.coffee +++ b/src/beautifiers/beautifier.coffee @@ -149,9 +149,13 @@ module.exports = class Beautifier which: (exe, options = {}) -> # Get PATH and other environment variables @getShellEnvironment() - .then((env) -> - new Promise((resolve, reject) -> + .then((env) => + new Promise((resolve, reject) => options.path ?= env.PATH + if @isWindows + # Trick node-which into including files + # with no extension as executables + options.pathExt ?= ";#{process.env.PATHEXT ? '.EXE'}" which(exe, options, (err, path) -> resolve(exe) if err resolve(path) diff --git a/src/beautifiers/php-cs-fixer.coffee b/src/beautifiers/php-cs-fixer.coffee index 1d631950f..6757d8c54 100644 --- a/src/beautifiers/php-cs-fixer.coffee +++ b/src/beautifiers/php-cs-fixer.coffee @@ -15,61 +15,19 @@ module.exports = class PHPCSFixer extends Beautifier beautify: (text, language, options) -> @debug('php-cs-fixer', options) - isWin = @isWindows - if isWin - # 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 p.charAt(0) is '/' ) - @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 - tempFile = @tempFile("temp", text) - ], { - ignoreReturnCode: true - help: { - link: "http://php.net/manual/en/install.php" - } - }) - .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" - }) - ) + @run(options.cs_fixer_path or "php-cs-fixer", [ + "fix" + "--level=#{options.level}" if options.level + "--fixers=#{options.fixers}" if options.fixers + tempFile = @tempFile("temp", text) + ], { + ignoreReturnCode: true + help: { + link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" + program: "php-cs-fixer" + pathOption: "PHP - CS Fixer Path" + } + }) + .then(=> + @readFile(tempFile) ) - else - @run("php-cs-fixer", [ - "fix" - "--level=#{options.level}" if options.level - "--fixers=#{options.fixers}" if options.fixers - tempFile = @tempFile("temp", text) - ], { - ignoreReturnCode: true - help: { - link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" - } - }) - .then(=> - @readFile(tempFile) - )