Page MenuHomePhorge
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.

Other Methods

internals

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

Methods

public function __get($name)
Inherited

This method is not documented.
Parameters
$name
Return
wild

public function __set($name, $value)
Inherited

This method is not documented.
Parameters
$name
$value
Return
wild

public function current()
Inherited

This method is not documented.
Return
wild

public function key()
Inherited

This method is not documented.
Return
wild

public function next()
Inherited

This method is not documented.
Return
wild

public function rewind()
Inherited

This method is not documented.
Return
wild

public function valid()
Inherited

This method is not documented.
Return
wild

private function throwOnAttemptedIteration()
Inherited

This method is not documented.
Return
wild

public function getPhobjectClassConstant($key, $byte_limit)
Inherited

Phobject

Read the value of a class constant.

This is the same as just typing self::CONSTANTNAME, but throws a more useful message if the constant is not defined and allows the constant to be limited to a maximum length.

Parameters
string$keyName of the constant.
int|null$byte_limitMaximum number of bytes permitted in the value.
Return
stringValue of the constant.

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.