1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-01-10 23:01:04 +01:00

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
This commit is contained in:
Joshua Spence 2015-12-02 14:13:11 +11:00
parent 09052d5247
commit 76ae02325d
2 changed files with 14 additions and 1 deletions

View file

@ -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') {

View file

@ -0,0 +1,7 @@
<?php
intval($x / 2) + 1;
~~~~~~~~~~
advice:2:1
~~~~~~~~~~
<?php
(int)($x / 2) + 1;