Page MenuHomePhabricator
Paste P1885

ArcanistParentMemberReferenceXHPASTLinterRule.php
ActivePublic

Authored by joshuaspence on Nov 9 2015, 12:36 AM.
<?php
final class ArcanistParentMemberReferenceXHPASTLinterRule
extends ArcanistXHPASTLinterRule {
const ID = 100;
public function getLintName() {
return pht('Parent Member Reference');
}
public function getLintSeverity() {
return ArcanistLintSeverity::SEVERITY_ADVICE;
}
public function process(XHPASTNode $root) {
$class_declarations = $root->selectDescendantsOfType('n_CLASS_DECLARATION');
foreach ($class_declarations as $class_declaration) {
$parent_class = $class_declaration
->getChildOfType(2, 'n_EXTENDS_LIST')
->getChildOfType(0, 'n_CLASS_NAME')
->getConcreteString();
$class_static_accesses = $class_declaration
->selectDescendantsOfType('n_CLASS_STATIC_ACCESS');
$closures = $this->getAnonymousClosures($class_declaration);
foreach ($class_static_accesses as $class_static_access) {
$double_colons = $class_static_access
->selectTokensOfType('T_PAAMAYIM_NEKUDOTAYIM');
$class_ref = $class_static_access->getChildByIndex(0);
if ($class_ref->getTypeName() != 'n_CLASS_NAME') {
continue;
}
$class_ref_name = $class_ref->getConcreteString();
if (strtolower($parent_class) == strtolower($class_ref_name)) {
$in_closure = false;
foreach ($closures as $closure) {
if ($class_ref->isDescendantOf($closure)) {
$in_closure = true;
break;
}
}
if (version_compare($this->version, '5.4.0', '>=') || !$in_closure) {
$this->raiseLintAtNode(
$class_ref,
pht(
'Use `%s` to call.',
'parent::'),
'parent');
}
}
}
}
}
}

Event Timeline

joshuaspence changed the title of this paste from untitled to ArcanistParentMemberReferenceXHPASTLinterRule.php.Nov 9 2015, 12:36 AM
joshuaspence edited the content of this paste. (Show Details)
joshuaspence added a project: Lint.