Page MenuHomePhabricator

D14611.id35369.diff
No OneTemporary

D14611.id35369.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
@@ -28,7 +28,7 @@
$function_name = $cast
->getChildOfType(0, 'n_SYMBOL_NAME')
->getConcreteString();
- $cast_name = $cast_functions[$function_name];
+ $cast_name = $cast_functions[strtolower($function_name)];
$parameters = $cast->getChildOfType(1, 'n_CALL_PARAMETER_LIST');
$replacement = null;
@@ -40,6 +40,23 @@
$replacement = '('.$cast_name.')'.$parameter->getConcreteString();
}
+ if (strtolower($function_name) == 'intval') {
+ if (count($parameters->getChildren()) >= 2) {
+ $base = $parameters->getChildByIndex(1);
+
+ if ($base->getTypeName() != 'n_NUMERIC_SCALAR') {
+ break;
+ }
+
+ if ($base->getConcreteString() != '10') {
+ continue;
+ }
+
+ $parameter = $parameters->getChildByIndex(0);
+ $replacement = '('.$cast_name.')'.$parameter->getConcreteString();
+ }
+ }
+
$this->raiseLintAtNode(
$cast,
pht(
diff --git a/src/lint/linter/xhpast/rules/__tests__/function-call-should-be-type-cast/base.lint-test b/src/lint/linter/xhpast/rules/__tests__/function-call-should-be-type-cast/base.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/function-call-should-be-type-cast/base.lint-test
@@ -0,0 +1,12 @@
+<?php
+intval($x);
+intval($x, 8);
+intval($x, 10);
+~~~~~~~~~~
+advice:2:1
+advice:4:1
+~~~~~~~~~~
+<?php
+(int)$x;
+intval($x, 8);
+(int)$x;

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 1:55 PM (20 h, 13 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6794636
Default Alt Text
D14611.id35369.diff (1 KB)

Event Timeline