Fixes #1725. Improve PHP-CS-Fixer support with handling script path
Detect if the executable path is either .phar (PHP) or not and run the executable PHP-CS-Fixer differently considering.
This commit is contained in:
parent
eafc43f6ff
commit
8b5363f7bf
|
@ -1,14 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$hello = 'world';
|
$hello = "world";
|
||||||
|
|
||||||
if (!isset($_SESSION)) {
|
if (!isset($_SESSION)) {
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
require_once 'sql.req.php';
|
require_once("sql.req.php");
|
||||||
|
|
||||||
|
|
||||||
// friend requests
|
// friend requests
|
||||||
$q = $mysqli->query('');
|
$q = $mysqli->query("");
|
||||||
$num = $q->num_rows;
|
$num = $q->num_rows;
|
||||||
echo '<a href="notifications.php">';
|
echo '<a href="notifications.php">';
|
||||||
if ($num>0) {
|
if ($num>0) {
|
||||||
|
@ -18,8 +19,9 @@ if ($num > 0) {
|
||||||
}
|
}
|
||||||
echo '</a>';
|
echo '</a>';
|
||||||
|
|
||||||
|
|
||||||
// new messages
|
// new messages
|
||||||
$q = $mysqli->query('');
|
$q = $mysqli->query("");
|
||||||
$num = $q->num_rows;
|
$num = $q->num_rows;
|
||||||
echo '<a href="messages.php">';
|
echo '<a href="messages.php">';
|
||||||
if ($num>0) {
|
if ($num>0) {
|
||||||
|
|
|
@ -119,7 +119,10 @@ class Executable
|
||||||
@isVersion(@versionsSupported)
|
@isVersion(@versionsSupported)
|
||||||
|
|
||||||
isVersion: (range) ->
|
isVersion: (range) ->
|
||||||
semver.satisfies(@version, range)
|
@versionSatisfies(@version, range)
|
||||||
|
|
||||||
|
versionSatisfies: (version, range) ->
|
||||||
|
semver.satisfies(version, range)
|
||||||
|
|
||||||
getConfig: () ->
|
getConfig: () ->
|
||||||
atom?.config.get("#{parentConfigKey}.#{@key}") or {}
|
atom?.config.get("#{parentConfigKey}.#{@key}") or {}
|
||||||
|
@ -129,21 +132,16 @@ class Executable
|
||||||
###
|
###
|
||||||
run: (args, options = {}) ->
|
run: (args, options = {}) ->
|
||||||
@debug("Run: ", @cmd, args, options)
|
@debug("Run: ", @cmd, args, options)
|
||||||
{ cwd, ignoreReturnCode, help, onStdin, returnStderr, returnStdoutOrStderr } = options
|
{ cmd, cwd, ignoreReturnCode, help, onStdin, returnStderr, returnStdoutOrStderr } = options
|
||||||
exeName = @cmd
|
exeName = cmd or @cmd
|
||||||
config = @getConfig()
|
|
||||||
cwd ?= os.tmpDir()
|
cwd ?= os.tmpDir()
|
||||||
|
|
||||||
# Resolve executable and all args
|
# Resolve executable and all args
|
||||||
Promise.all([@shellEnv(), this.resolveArgs(args)])
|
Promise.all([@shellEnv(), this.resolveArgs(args)])
|
||||||
.then(([env, args]) =>
|
.then(([env, args]) =>
|
||||||
@debug('exeName, args:', exeName, args)
|
@debug('exeName, args:', exeName, args)
|
||||||
|
|
||||||
# Get PATH and other environment variables
|
# Get PATH and other environment variables
|
||||||
if config and config.path
|
exePath = @path(exeName)
|
||||||
exePath = config.path
|
|
||||||
else
|
|
||||||
exePath = @which(exeName)
|
|
||||||
Promise.all([exeName, args, env, exePath])
|
Promise.all([exeName, args, env, exePath])
|
||||||
)
|
)
|
||||||
.then(([exeName, args, env, exePath]) =>
|
.then(([exeName, args, env, exePath]) =>
|
||||||
|
@ -198,6 +196,14 @@ class Executable
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
path: (cmd = @cmd) ->
|
||||||
|
config = @getConfig()
|
||||||
|
if config and config.path
|
||||||
|
Promise.resolve(config.path)
|
||||||
|
else
|
||||||
|
exeName = cmd
|
||||||
|
@which(exeName)
|
||||||
|
|
||||||
resolveArgs: (args) ->
|
resolveArgs: (args) ->
|
||||||
args = _.flatten(args)
|
args = _.flatten(args)
|
||||||
Promise.all(args)
|
Promise.all(args)
|
||||||
|
|
|
@ -25,8 +25,13 @@ module.exports = class PHPCSFixer extends Beautifier
|
||||||
cmd: "php-cs-fixer"
|
cmd: "php-cs-fixer"
|
||||||
homepage: "https://github.com/FriendsOfPHP/PHP-CS-Fixer"
|
homepage: "https://github.com/FriendsOfPHP/PHP-CS-Fixer"
|
||||||
installation: "https://github.com/FriendsOfPHP/PHP-CS-Fixer#installation"
|
installation: "https://github.com/FriendsOfPHP/PHP-CS-Fixer#installation"
|
||||||
|
optional: true
|
||||||
version: {
|
version: {
|
||||||
parse: (text) -> text.match(/version (.*) by/)[1] + ".0"
|
parse: (text) ->
|
||||||
|
try
|
||||||
|
text.match(/version (.*) by/)[1] + ".0"
|
||||||
|
catch
|
||||||
|
text.match(/PHP CS Fixer (\d+\.\d+\.\d+)/)[1]
|
||||||
}
|
}
|
||||||
docker: {
|
docker: {
|
||||||
image: "unibeautify/php-cs-fixer"
|
image: "unibeautify/php-cs-fixer"
|
||||||
|
@ -66,7 +71,10 @@ module.exports = class PHPCSFixer extends Beautifier
|
||||||
"--allow-risky=#{options.allow_risky}" if options.allow_risky
|
"--allow-risky=#{options.allow_risky}" if options.allow_risky
|
||||||
"--using-cache=no"
|
"--using-cache=no"
|
||||||
]
|
]
|
||||||
if phpCsFixer.isVersion('1.x')
|
|
||||||
|
isVersion1 = ((phpCsFixer.isInstalled and phpCsFixer.isVersion('1.x')) or \
|
||||||
|
(options.cs_fixer_version and phpCsFixer.versionSatisfies("#{options.cs_fixer_version}.0.0", '1.x')))
|
||||||
|
if isVersion1
|
||||||
phpCsFixerOptions = [
|
phpCsFixerOptions = [
|
||||||
"fix"
|
"fix"
|
||||||
"--level=#{options.level}" if options.level
|
"--level=#{options.level}" if options.level
|
||||||
|
@ -82,43 +90,32 @@ module.exports = class PHPCSFixer extends Beautifier
|
||||||
|
|
||||||
# Find php-cs-fixer.phar script
|
# Find php-cs-fixer.phar script
|
||||||
if options.cs_fixer_path
|
if options.cs_fixer_path
|
||||||
@deprecate("The \"cs_fixer_path\" has been deprecated. Please switch to using the config with path \"Executables - PHP-CS-Fixer - Path\" in Atom-Beautify package settings now.")
|
deprecationMessage = "The \"PHP - PHP-CS-Fixer Path (cs_fixer_path)\" configuration option has been deprecated. Please switch to using the option named \"Executables - PHP-CS-Fixer - Path\" in Atom-Beautify package settings now."
|
||||||
|
@deprecate(deprecationMessage)
|
||||||
|
|
||||||
@Promise.all([
|
@Promise.all([
|
||||||
@which(options.cs_fixer_path) if options.cs_fixer_path
|
@which(options.cs_fixer_path) if options.cs_fixer_path
|
||||||
@which('php-cs-fixer')
|
phpCsFixer.path()
|
||||||
tempFile = @tempFile("temp", text, '.php')
|
tempFile = @tempFile("temp", text, '.php')
|
||||||
]).then(([customPath, phpCsFixerPath]) =>
|
]).then(([customPhpCsFixerPath, phpCsFixerPath]) =>
|
||||||
paths = [customPath, phpCsFixerPath]
|
|
||||||
@debug('php-cs-fixer paths', paths)
|
|
||||||
_ = require 'lodash'
|
|
||||||
# Get first valid, absolute path
|
# Get first valid, absolute path
|
||||||
phpCSFixerPath = _.find(paths, (p) -> p and path.isAbsolute(p) )
|
finalPhpCsFixerPath = if customPhpCsFixerPath and path.isAbsolute(customPhpCsFixerPath) then \
|
||||||
@verbose('phpCSFixerPath', phpCSFixerPath)
|
customPhpCsFixerPath else phpCsFixerPath
|
||||||
@debug('phpCSFixerPath', phpCSFixerPath, paths)
|
@verbose('finalPhpCsFixerPath', finalPhpCsFixerPath, phpCsFixerPath, customPhpCsFixerPath)
|
||||||
|
|
||||||
# Check if PHP-CS-Fixer path was found
|
isPhpScript = (finalPhpCsFixerPath.indexOf(".phar") isnt -1) or (finalPhpCsFixerPath.indexOf(".php") isnt -1)
|
||||||
if phpCSFixerPath?
|
@verbose('isPhpScript', isPhpScript)
|
||||||
# Found PHP-CS-Fixer path
|
|
||||||
if @isWindows
|
if finalPhpCsFixerPath and isPhpScript
|
||||||
php.run([phpCSFixerPath, phpCsFixerOptions, tempFile], runOptions)
|
php.run([finalPhpCsFixerPath, phpCsFixerOptions, tempFile], runOptions)
|
||||||
.then(=>
|
.then(=>
|
||||||
@readFile(tempFile)
|
@readFile(tempFile)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
@run(phpCSFixerPath, [phpCsFixerOptions, tempFile], runOptions)
|
phpCsFixer.run([phpCsFixerOptions, tempFile],
|
||||||
|
Object.assign({}, runOptions, { cmd: finalPhpCsFixerPath })
|
||||||
|
)
|
||||||
.then(=>
|
.then(=>
|
||||||
@readFile(tempFile)
|
@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"
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue