From 76ae02325dd3aa516b01263da53f7ad0ee123ff7 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Wed, 2 Dec 2015 14:13:11 +1100 Subject: [PATCH] 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 --- ...canistFunctionCallShouldBeTypeCastXHPASTLinterRule.php | 8 +++++++- .../binary-expression.lint-test | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/lint/linter/xhpast/rules/__tests__/function-call-should-be-type-cast/binary-expression.lint-test 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 @@ +