Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13983775
D14611.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D14611.id.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Mon, Oct 21, 8:32 AM (3 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6725081
Default Alt Text
D14611.id.diff (1 KB)
Attached To
Mode
D14611: Minor fix for typecast linter rule
Attached
Detach File
Event Timeline
Log In to Comment