Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3294908
ArcanistXHPASTLintNamingHook.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
4 KB
Referenced Files
None
Subscribers
None
ArcanistXHPASTLintNamingHook.php
View Options
<?php
/**
* You can extend this class and set ##"lint.xhpast.naminghook"## in your
* ##.arcconfig## to have an opportunity to override lint results for symbol
* names.
*
* @task override Overriding Symbol Name Lint Messages
* @task util Name Utilities
* @task internal Internals
* @group lint
* @stable
*/
abstract
class
ArcanistXHPASTLintNamingHook
{
/* -( Internals )---------------------------------------------------------- */
/**
* The constructor is final because @{class:ArcanistXHPASTLinter} is
* responsible for hook instantiation.
*
* @return this
* @task internals
*/
final
public
function
__construct
(
)
{
// <empty>
}
/* -( Overriding Symbol Name Lint Messages )------------------------------- */
/**
* 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;
*
* @param string The symbol type.
* @param string The symbol name.
* @param string|null The default result from the main rule engine.
* @return string|null Null 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.
* @task override
*/
abstract
public
function
lintSymbolName
(
$type
,
$name
,
$default
)
;
/* -( Name Utilities )----------------------------------------------------- */
/**
* Returns true if a symbol name is UpperCamelCase.
*
* @param string Symbol name.
* @return bool True if the symbol is UpperCamelCase.
* @task util
*/
public
static
function
isUpperCamelCase
(
$symbol
)
{
return
preg_match
(
'/^[A-Z][A-Za-z0-9]*$/'
,
$symbol
)
;
}
/**
* Returns true if a symbol name is lowerCamelCase.
*
* @param string Symbol name.
* @return bool True if the symbol is lowerCamelCase.
* @task util
*/
public
static
function
isLowerCamelCase
(
$symbol
)
{
return
preg_match
(
'/^[a-z][A-Za-z0-9]*$/'
,
$symbol
)
;
}
/**
* Returns true if a symbol name is UPPERCASE_WITH_UNDERSCORES.
*
* @param string Symbol name.
* @return bool True if the symbol is UPPERCASE_WITH_UNDERSCORES.
* @task util
*/
public
static
function
isUppercaseWithUnderscores
(
$symbol
)
{
return
preg_match
(
'/^[A-Z0-9_]+$/'
,
$symbol
)
;
}
/**
* Returns true if a symbol name is lowercase_with_underscores.
*
* @param string Symbol name.
* @return bool True if the symbol is lowercase_with_underscores.
* @task util
*/
public
static
function
isLowercaseWithUnderscores
(
$symbol
)
{
return
preg_match
(
'/^[a-z0-9_]+$/'
,
$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}.
*
* @param string Symbol name.
* @return string Stripped symbol.
* @task util
*/
public
static
function
stripPHPFunction
(
$symbol
)
{
// Allow initial "__" for magic methods like __construct; we could also
// enumerate these explicitly.
return
preg_replace
(
'/^__/'
,
''
,
$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}.
*
* @param string Symbol name.
* @return string Stripped symbol.
* @task util
*/
public
static
function
stripPHPVariable
(
$symbol
)
{
return
preg_replace
(
'/^\$/'
,
''
,
$symbol
)
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Mar 26, 23:51 (4 d, 11 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1135539
Default Alt Text
ArcanistXHPASTLintNamingHook.php (4 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment