Skip to content

Commit

Permalink
bug #5045 BacktickToShellExecFixer - add priority relation to NativeF…
Browse files Browse the repository at this point in the history
…unctionInvocationFixer and SingleQuoteFixer (kubawerlos)

This PR was merged into the 2.15 branch.

Discussion
----------

BacktickToShellExecFixer - add priority relation to NativeFunctionInvocationFixer and SingleQuoteFixer

This is actually a bug fix, because at `2.16` `NativeFunctionInvocationFixer` has priority [10](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.16.4/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php#L171), which is greater that `BacktickToShellExecFixer` priority ([2](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.16.4/src/Fixer/Alias/BacktickToShellExecFixer.php#L63)).

So, for the person who will be merging this up to `2.16`: on the conflict in `NativeFunctionInvocationFixer` for priorities `10` and `1` - choose `1` or tests would fail.

Commits
-------

7e5ffd7 BacktickToShellExecFixer - add priority relation to NativeFunctionInvocationFixer and SingleQuoteFixer
  • Loading branch information
SpacePossum committed Aug 6, 2020
2 parents 4bbb114 + 7e5ffd7 commit d1c79b1
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Fixer/Alias/BacktickToShellExecFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getDefinition()
/**
* {@inheritdoc}
*
* Must run before EscapeImplicitBackslashesFixer, ExplicitStringVariableFixer.
* Must run before EscapeImplicitBackslashesFixer, ExplicitStringVariableFixer, NativeFunctionInvocationFixer, SingleQuoteFixer.
*/
public function getPriority()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ public function isRisky()
/**
* {@inheritdoc}
*
* Must run after StrictParamFixer.
* Must run after BacktickToShellExecFixer, StrictParamFixer.
*/
public function getPriority()
{
return 0;
return 1;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Strict/StrictParamFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function isRisky()
*/
public function getPriority()
{
return 1;
return 2;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/StringNotation/SingleQuoteFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getDefinition()
/**
* {@inheritdoc}
*
* Must run after EscapeImplicitBackslashesFixer.
* Must run after BacktickToShellExecFixer, EscapeImplicitBackslashesFixer.
*/
public function getPriority()
{
Expand Down
2 changes: 2 additions & 0 deletions tests/AutoReview/FixerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function provideFixersPriorityCases()
[$fixers['array_syntax'], $fixers['ternary_operator_spaces']],
[$fixers['backtick_to_shell_exec'], $fixers['escape_implicit_backslashes']],
[$fixers['backtick_to_shell_exec'], $fixers['explicit_string_variable']],
[$fixers['backtick_to_shell_exec'], $fixers['native_function_invocation']],
[$fixers['backtick_to_shell_exec'], $fixers['single_quote']],
[$fixers['blank_line_after_opening_tag'], $fixers['no_blank_lines_before_namespace']],
[$fixers['braces'], $fixers['array_indentation']],
[$fixers['braces'], $fixers['method_argument_space']],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
Integration of fixers: backtick_to_shell_exec,native_function_invocation.
--RULESET--
{"backtick_to_shell_exec": true, "native_function_invocation": true}
--EXPECT--
<?php
$var = \shell_exec("pwd");

--INPUT--
<?php
$var = `pwd`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
Integration of fixers: backtick_to_shell_exec,single_quote.
--RULESET--
{"backtick_to_shell_exec": true, "single_quote": true}
--EXPECT--
<?php
$var = shell_exec('pwd');

--INPUT--
<?php
$var = `pwd`;

0 comments on commit d1c79b1

Please sign in to comment.