]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Explicitly enumerate PHP magic methods
authorJoshua Spence <josh@joshuaspence.com>
Mon, 22 Sep 2014 22:02:19 +0000 (08:02 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Mon, 22 Sep 2014 22:02:19 +0000 (08:02 +1000)
Summary: Explicitly list PHP magic methods (methods beginning with `__`) instead of assuming that //all// methods beginning with `__` are okay in terms of naming conventions. These magic methods were obtained from http://us1.php.net/manual/en/language.oop5.magic.php.

Test Plan:
```
   Warning  (XHP9) Naming Conventions
    Follow naming conventions: methods should be named using lowerCamelCase.

               1 <?php
               2
               3 class Foo {
    >>>        4     function __foo() {}
               5
               6     function _bar() {}
               7 }

   Warning  (XHP9) Naming Conventions
    Follow naming conventions: methods should be named using lowerCamelCase.

               3 class Foo {
               4     function __foo() {}
               5
    >>>        6     function _bar() {}
               7 }
```

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D10539

src/lint/linter/xhpast/ArcanistXHPASTLintNamingHook.php

index 237996ad7f2d8aa4a6e134c077b3f7b90bf37367..5bb135139ab2f749f38d2c99db0da92f38defa69 100644 (file)
@@ -113,9 +113,29 @@ abstract class ArcanistXHPASTLintNamingHook {
    * @task util
    */
   public static function stripPHPFunction($symbol) {
-    // Allow initial "__" for magic methods like __construct; we could also
-    // enumerate these explicitly.
-    return preg_replace('/^__/', '', $symbol);
+    switch ($symbol) {
+      case '__assign_concat':
+      case '__call':
+      case '__callStatic':
+      case '__clone':
+      case '__concat':
+      case '__construct':
+      case '__debugInfo':
+      case '__destruct':
+      case '__get':
+      case '__invoke':
+      case '__isset':
+      case '__set':
+      case '__set_state':
+      case '__sleep':
+      case '__toString':
+      case '__unset':
+      case '__wakeup':
+        return preg_replace('/^__/', '', $symbol);
+
+      default:
+        return $symbol;
+    }
   }
 
   /**