Diviner

Class ArcanistXHPASTLintNamingHook

Definedsrc/lint/linter/xhpast/ArcanistXHPASTLintNamingHook.php:14
GroupLint Integration
This class is stable: you may safely extend it.

You can extend this class and set "lint.xhpast.naminghook" in your .arcconfig to have an opportunity to override lint results for symbol names.

Tasks

Overriding Symbol Name Lint Messages

Name Utilities

internals

Methods

final public this __construct()

returnthis

The constructor is final because ArcanistXHPASTLinter is responsible for hook instantiation.

public static bool isLowerCamelCase($symbol)

parametersstring$symbolSymbol name.
returnboolTrue if the symbol is lowerCamelCase.

Returns true if a symbol name is lowerCamelCase.

public static bool isLowercaseWithUnderscores($symbol)

parametersstring$symbolSymbol name.
returnboolTrue if the symbol is lowercase_with_underscores.

Returns true if a symbol name is lowercase_with_underscores.

public static bool isUpperCamelCase($symbol)

parametersstring$symbolSymbol name.
returnboolTrue if the symbol is UpperCamelCase.

Returns true if a symbol name is UpperCamelCase.

public static bool isUppercaseWithUnderscores($symbol)

parametersstring$symbolSymbol name.
returnboolTrue if the symbol is UPPERCASE_WITH_UNDERSCORES.

Returns true if a symbol name is UPPERCASE_WITH_UNDERSCORES.

public abstract string|null lintSymbolName($type, $name, $default)

parametersstring$typeThe symbol type.
string$nameThe symbol name.
string|null$defaultThe default result from the main rule engine.
returnstring|nullNull to accept the name, or a message to reject it with. You should return the default value if you don't want to specifically provide an override.

Callback invoked for each symbol, which can override the default determination of name validity or accept it by returning $default. The symbol types are: xhp-class, class, interface, function, method, parameter, constant, and member.

For example, if you want to ban all symbols with "quack" in them and otherwise accept all the defaults, except allow any naming convention for methods with "duck" in them, you might implement the method like this:

if (preg_match('/quack/i', $name)) {
  return 'Symbol names containing "quack" are forbidden.';
}
if ($type == 'method' && preg_match('/duck/i', $name)) {
  return null; // Always accept.
}
return $default;

public static string stripPHPFunction($symbol)

parametersstring$symbolSymbol name.
returnstringStripped symbol.

Strip non-name components from PHP function symbols. Notably, this discards the "__" magic-method signifier, to make a symbol appropriate for testing with methods like isLowerCamelCase().

public static string stripPHPVariable($symbol)

parametersstring$symbolSymbol name.
returnstringStripped symbol.

Strip non-name components from PHP variable symbols. Notably, this discards the "$", to make a symbol appropriate for testing with methods like isLowercaseWithUnderscores().