const LINT_UNNECESSARY_SEMICOLON = 56;
const LINT_SELF_MEMBER_REFERENCE = 57;
const LINT_LOGICAL_OPERATORS = 58;
+ const LINT_INNER_FUNCTION = 59;
private $blacklistedFunctions = array();
private $naminghook;
self::LINT_UNNECESSARY_SEMICOLON => 'Unnecessary Semicolon',
self::LINT_SELF_MEMBER_REFERENCE => 'Self Member Reference',
self::LINT_LOGICAL_OPERATORS => 'Logical Operators',
+ self::LINT_INNER_FUNCTION => 'Inner Functions',
);
}
self::LINT_UNNECESSARY_SEMICOLON => $advice,
self::LINT_SELF_MEMBER_REFERENCE => $advice,
self::LINT_LOGICAL_OPERATORS => $advice,
+ self::LINT_INNER_FUNCTION => $warning,
);
}
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '21';
+ return '22';
}
protected function resolveFuture($path, Future $future) {
'lintConstantDefinitions' => self::LINT_NAMING_CONVENTIONS,
'lintSelfMemberReference' => self::LINT_SELF_MEMBER_REFERENCE,
'lintLogicalOperators' => self::LINT_LOGICAL_OPERATORS,
+ 'lintInnerFunctions' => self::LINT_INNER_FUNCTION,
);
foreach ($method_codes as $method => $codes) {
}
}
+ private function lintInnerFunctions(XHPASTNode $root) {
+ $function_decls = $root->selectDescendantsOfType('n_FUNCTION_DECLARATION');
+
+ foreach ($function_decls as $function_declaration) {
+ $inner_functions = $function_declaration
+ ->selectDescendantsOfType('n_FUNCTION_DECLARATION');
+
+ foreach ($inner_functions as $inner_function) {
+ if ($inner_function->getChildByIndex(2)->getTypeName() == 'n_EMPTY') {
+ // Anonymous closure.
+ continue;
+ }
+
+ $this->raiseLintAtNode(
+ $inner_function,
+ self::LINT_INNER_FUNCTION,
+ pht('Avoid the use of inner functions.'));
+ }
+ }
+ }
+
/**
* Retrieve all calls to some specified function(s).
*