1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 23:02:41 +01:00

Use CaseInsensitiveArray in ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule

Summary: Demonstrates the use of `CaseInsensitiveArray`. Depends on D14624.

Test Plan: Ran unit tests.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D14625
This commit is contained in:
Joshua Spence 2015-12-03 08:10:30 +11:00
parent 76ae02325d
commit 8ed3c45c82

View file

@ -14,21 +14,25 @@ final class ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule
} }
public function process(XHPASTNode $root) { public function process(XHPASTNode $root) {
static $cast_functions = array( static $cast_functions;
'boolval' => 'bool',
'doubleval' => 'double',
'floatval' => 'double',
'intval' => 'int',
'strval' => 'string',
);
$casts = $this->getFunctionCalls($root, array_keys($cast_functions)); if ($cast_functions === null) {
$cast_functions = new CaseInsensitiveArray(array(
'boolval' => 'bool',
'doubleval' => 'double',
'floatval' => 'double',
'intval' => 'int',
'strval' => 'string',
));
}
$casts = $this->getFunctionCalls($root, $cast_functions->getKeys());
foreach ($casts as $cast) { foreach ($casts as $cast) {
$function_name = $cast $function_name = $cast
->getChildOfType(0, 'n_SYMBOL_NAME') ->getChildOfType(0, 'n_SYMBOL_NAME')
->getConcreteString(); ->getConcreteString();
$cast_name = $cast_functions[strtolower($function_name)]; $cast_name = $cast_functions[$function_name];
$parameters = $cast->getChildOfType(1, 'n_CALL_PARAMETER_LIST'); $parameters = $cast->getChildOfType(1, 'n_CALL_PARAMETER_LIST');
$replacement = null; $replacement = null;