diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -7,6 +7,9 @@ private $rules = array(); + private $lintNameMap; + private $lintSeverityMap; + public function __construct() { $this->rules = ArcanistXHPASTLinterRule::loadAllRules(); } @@ -37,11 +40,25 @@ } public function getLintNameMap() { - return mpull($this->rules, 'getLintName', 'getLintID'); + if ($this->lintNameMap === null) { + $this->lintNameMap = mpull( + $this->rules, + 'getLintName', + 'getLintID'); + } + + return $this->lintNameMap; } public function getLintSeverityMap() { - return mpull($this->rules, 'getLintSeverity', 'getLintID'); + if ($this->lintSeverityMap === null) { + $this->lintSeverityMap = mpull( + $this->rules, + 'getLintSeverity', + 'getLintID'); + } + + return $this->lintSeverityMap; } public function getLinterConfigurationOptions() { diff --git a/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php b/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php --- a/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php @@ -3,6 +3,7 @@ abstract class ArcanistXHPASTLinterRule extends Phobject { private $linter = null; + private $lintID = null; final public static function loadAllRules() { $rules = array(); @@ -31,26 +32,31 @@ } final public function getLintID() { - $class = new ReflectionClass($this); - - $const = $class->getConstant('ID'); - if ($const === false) { - throw new Exception( - pht( - '`%s` class `%s` must define an ID constant.', - __CLASS__, - get_class($this))); - } + if ($this->lintID === null) { + $class = new ReflectionClass($this); + + $const = $class->getConstant('ID'); + if ($const === false) { + throw new Exception( + pht( + '`%s` class `%s` must define an ID constant.', + __CLASS__, + get_class($this))); + } + + if (!is_int($const)) { + throw new Exception( + pht( + '`%s` class `%s` has an invalid ID constant. '. + 'ID must be an integer.', + __CLASS__, + get_class($this))); + } - if (!is_int($const)) { - throw new Exception( - pht( - '`%s` class `%s` has an invalid ID constant. ID must be an integer.', - __CLASS__, - get_class($this))); + $this->lintID = $const; } - return $const; + return $this->lintID; } abstract public function getLintName();