Page MenuHomePhabricator
Diviner libphutil Tech Docs ArcanistXHPASTLintNamingHook

abstract class ArcanistXHPASTLintNamingHook
libphutil Technical Documentation ()

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

Tasks

Overriding Symbol Name Lint Messages

  • abstract public function lintSymbolName($type, $name, $default) — 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.

Name Utilities

  • public static function isUpperCamelCase($symbol) — Returns true if a symbol name is UpperCamelCase.
  • public static function isLowerCamelCase($symbol) — Returns true if a symbol name is lowerCamelCase.
  • public static function isUppercaseWithUnderscores($symbol) — Returns true if a symbol name is UPPERCASE_WITH_UNDERSCORES.
  • public static function isLowercaseWithUnderscores($symbol) — Returns true if a symbol name is lowercase_with_underscores.
  • public static function stripPHPFunction($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 @{method:isLowerCamelCase}.
  • public static function stripPHPVariable($symbol) — Strip non-name components from PHP variable symbols. Notably, this discards the "$", to make a symbol appropriate for testing with methods like @{method:isLowercaseWithUnderscores}.

Internals

No methods for this task.

internals

  • final public function __construct() — The constructor is final because @{class:ArcanistXHPASTLinter} is responsible for hook instantiation.

Methods

final public function __construct()

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

Return
this//Implicit.//

abstract public function lintSymbolName($type, $name, $default)

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;
Parameters
string$typeThe symbol type.
string$nameThe symbol name.
string|null$defaultThe default result from the main rule engine.
Return
string|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.

public static function isUpperCamelCase($symbol)

Returns true if a symbol name is UpperCamelCase.

Parameters
string$symbolSymbol name.
Return
boolTrue if the symbol is UpperCamelCase.

public static function isLowerCamelCase($symbol)

Returns true if a symbol name is lowerCamelCase.

Parameters
string$symbolSymbol name.
Return
boolTrue if the symbol is lowerCamelCase.

public static function isUppercaseWithUnderscores($symbol)

Returns true if a symbol name is UPPERCASE_WITH_UNDERSCORES.

Parameters
string$symbolSymbol name.
Return
boolTrue if the symbol is UPPERCASE_WITH_UNDERSCORES.

public static function isLowercaseWithUnderscores($symbol)

Returns true if a symbol name is lowercase_with_underscores.

Parameters
string$symbolSymbol name.
Return
boolTrue if the symbol is lowercase_with_underscores.

public static function stripPHPFunction($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().

Parameters
string$symbolSymbol name.
Return
stringStripped symbol.

public static function stripPHPVariable($symbol)

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

Parameters
string$symbolSymbol name.
Return
stringStripped symbol.