diff --git a/src/lint/linter/xhpast/rules/ArcanistDeprecationXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistDeprecationXHPASTLinterRule.php index bc57bb2d..d94192b5 100644 --- a/src/lint/linter/xhpast/rules/ArcanistDeprecationXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/rules/ArcanistDeprecationXHPASTLinterRule.php @@ -1,57 +1,57 @@ array( 'type' => 'optional map', 'help' => pht( - 'Functions which should should be considered deprecated.'), + 'Functions which should be considered deprecated.'), ), ); } public function setLinterConfigurationValue($key, $value) { switch ($key) { case 'xhpast.deprecated.functions': $this->deprecatedFunctions = $value; return; default: return parent::getLinterConfigurationOptions(); } } public function process(XHPASTNode $root) { $map = $this->deprecatedFunctions; $function_calls = $this->getFunctionCalls($root, array_keys($map)); foreach ($function_calls as $call) { $name = $call ->getChildByIndex(0) ->getConcreteString(); $name = strtolower($name); if (empty($map[$name])) { continue; } $this->raiseLintAtNode($call, $map[$name]); } } } diff --git a/src/lint/linter/xhpast/rules/ArcanistUnsafeDynamicStringXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistUnsafeDynamicStringXHPASTLinterRule.php index bf3c8e51..67cdfcc0 100644 --- a/src/lint/linter/xhpast/rules/ArcanistUnsafeDynamicStringXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/rules/ArcanistUnsafeDynamicStringXHPASTLinterRule.php @@ -1,105 +1,105 @@ array( 'type' => 'optional map', 'help' => pht( - 'Classes which should should not be used because they represent the '. + 'Classes which should not be used because they represent the '. 'unsafe usage of dynamic strings.'), ), 'xhpast.dynamic-string.functions' => array( 'type' => 'optional map', 'help' => pht( - 'Functions which should should not be used because they represent '. - 'the unsafe usage of dynamic strings.'), + 'Functions which should not be used because they represent the '. + 'unsafe usage of dynamic strings.'), ), ); return $options + parent::getLinterConfigurationOptions(); } public function setLinterConfigurationValue($key, $value) { switch ($key) { case 'xhpast.dynamic-string.classes': $this->dynamicStringClasses = $value; return; case 'xhpast.dynamic-string.functions': $this->dynamicStringFunctions = $value; return; default: parent::setLinterConfigurationValue($key, $value); return; } } public function process(XHPASTNode $root) { $this->lintUnsafeDynamicStringClasses($root); $this->lintUnsafeDynamicStringFunctions($root); } private function lintUnsafeDynamicStringClasses(XHPASTNode $root) { $news = $root->selectDescendantsOfType('n_NEW'); $this->lintUnsafeDynamicStringCall($news, $this->dynamicStringClasses); } private function lintUnsafeDynamicStringFunctions(XHPASTNode $root) { $calls = $root->selectDescendantsOfType('n_FUNCTION_CALL'); $this->lintUnsafeDynamicStringCall($calls, $this->dynamicStringFunctions); } private function lintUnsafeDynamicStringCall( AASTNodeList $calls, array $safe) { if ($safe) { $safe = array_combine( array_map('strtolower', array_keys($safe)), $safe); } foreach ($calls as $call) { $name = $call->getChildByIndex(0)->getConcreteString(); $param = idx($safe, strtolower($name)); if ($param === null) { continue; } $parameters = $call->getChildByIndex(1); if (count($parameters->getChildren()) <= $param) { continue; } $identifier = $parameters->getChildByIndex($param); if (!$identifier->isConstantString()) { $this->raiseLintAtNode( $call, pht( "Parameter %d of `%s` should be a scalar string, ". "otherwise it's not safe.", $param + 1, $name)); } } } }