From: Joshua Spence Date: Wed, 2 Dec 2015 03:13:11 +0000 (+1100) Subject: Fix another edge case for "function call should be type cast" linter rule X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=76ae02325dd3aa516b01263da53f7ad0ee123ff7;p=arcanist.git Fix another edge case for "function call should be type cast" linter rule Summary: Fix a minor issue in which changing a function call to a type cast affects the result of an expression. Test Plan: Added test case. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D14623 --- diff --git a/src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php index e39934ac..9e4546c4 100644 --- a/src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php @@ -37,7 +37,13 @@ final class ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule // one parameter. if (count($parameters->getChildren()) == 1) { $parameter = $parameters->getChildByIndex(0); - $replacement = '('.$cast_name.')'.$parameter->getConcreteString(); + $replacement = '('.$cast_name.')'; + + if ($parameter->getTypeName() == 'n_BINARY_EXPRESSION') { + $replacement .= '('.$parameter->getConcreteString().')'; + } else { + $replacement .= $parameter->getConcreteString(); + } } if (strtolower($function_name) == 'intval') { diff --git a/src/lint/linter/xhpast/rules/__tests__/function-call-should-be-type-cast/binary-expression.lint-test b/src/lint/linter/xhpast/rules/__tests__/function-call-should-be-type-cast/binary-expression.lint-test new file mode 100644 index 00000000..b3fbc1f9 --- /dev/null +++ b/src/lint/linter/xhpast/rules/__tests__/function-call-should-be-type-cast/binary-expression.lint-test @@ -0,0 +1,7 @@ +