Page MenuHomePhabricator

D14623.id35393.diff
No OneTemporary

D14623.id35393.diff

diff --git a/src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php
--- a/src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php
@@ -37,7 +37,13 @@
// 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
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/function-call-should-be-type-cast/binary-expression.lint-test
@@ -0,0 +1,7 @@
+<?php
+intval($x / 2) + 1;
+~~~~~~~~~~
+advice:2:1
+~~~~~~~~~~
+<?php
+(int)($x / 2) + 1;

File Metadata

Mime Type
text/plain
Expires
Thu, Oct 24, 11:31 AM (2 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6713612
Default Alt Text
D14623.id35393.diff (1 KB)

Event Timeline