From 8ed3c45c822654a6e9617feddbdd2ee4ef48f3dd Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Thu, 3 Dec 2015 08:10:30 +1100 Subject: [PATCH] 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 --- ...onCallShouldBeTypeCastXHPASTLinterRule.php | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php index 9e4546c4..3a2005b0 100644 --- a/src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php @@ -14,21 +14,25 @@ final class ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule } public function process(XHPASTNode $root) { - static $cast_functions = array( - 'boolval' => 'bool', - 'doubleval' => 'double', - 'floatval' => 'double', - 'intval' => 'int', - 'strval' => 'string', - ); + static $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, array_keys($cast_functions)); + $casts = $this->getFunctionCalls($root, $cast_functions->getKeys()); foreach ($casts as $cast) { $function_name = $cast ->getChildOfType(0, 'n_SYMBOL_NAME') ->getConcreteString(); - $cast_name = $cast_functions[strtolower($function_name)]; + $cast_name = $cast_functions[$function_name]; $parameters = $cast->getChildOfType(1, 'n_CALL_PARAMETER_LIST'); $replacement = null; -- 2.43.0