Page MenuHomePhabricator

Add linter rules to detect undeclared class constants and methods
Open, Needs TriagePublic

Description

Currently, we have the ability to detect the use of undefined classes and functions. I think that this is a very powerful tool for the purposes of static analysis.

There are a bunch of similar checks that we could do, but which would introduce additional complexity into the library maps and linter rules. Specifically, I thinj that it is possible (with varying levels of difficulty) to check for the following:

  1. Use of undefined class constants: This would involve adding constant definitions to the __phutil_library_map__.php file. The simplest case would be SomeClass::SOME_CONSTANT but self::SOME_CONSTANT should be possible as well. Late static binding (I.e. static::SOME_CONSTANT) is probably not possible. See T9054 for one such example.
  2. Use of undefined static methods/properties: This should be quite similar to the above scenario.

It might be possible to extend this to non-static methods, but only in some specific scenarios. For example:

function some_func(SomeClass $x) {
  $x->someMethod();
}
function some_func($x) {
  $x->someMethod();
}

Event Timeline

joshuaspence raised the priority of this task from to Needs Triage.
joshuaspence updated the task description. (Show Details)
joshuaspence added projects: Lint, Infrastructure.
joshuaspence added a subscriber: joshuaspence.