]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Use `CaseInsensitiveArray` in `ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule`
authorJoshua Spence <josh@freelancer.com>
Wed, 2 Dec 2015 21:10:30 +0000 (08:10 +1100)
committerJoshua Spence <josh@freelancer.com>
Wed, 2 Dec 2015 21:10:30 +0000 (08:10 +1100)
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

src/lint/linter/xhpast/rules/ArcanistFunctionCallShouldBeTypeCastXHPASTLinterRule.php

index 9e4546c4cc5ebd52b8ec4c42c6ba324e3e72da04..3a2005b06ccaabc2285d1f0d4cf0f683562b9f71 100644 (file)
@@ -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;