Skip to content

Instantly share code, notes, and snippets.

@grom358 grom358/indexer.md
Last active Aug 29, 2015

Embed
What would you like to do?
Index Features
  • Query what source code files exist in the codebase
  • Query what classes/traits/interfaces exist. eg. $index->getClasses() returns fully qualified list of class names
  • Query what functions exist. eg. $index->getFunctions() returns fully qualified list of function names
  • On a class/trait/interface can find what methods/properties/constants exist
  • On a class/interface can inspect the parent class/interface
  • On a class/trait inspect what interfaces are implemented
  • For a class find subclasses
  • For a trait find trait usages
  • For an interface find class/traits that implement the interface
  • For an interface find interfaces which extend it
  • For a class/trait find methods/properties, including methods/properties defined by a parent class
  • For a method/function find usages
  • When a file is removed any usages/classes/functions/traits/interfaces are removed from index
  • Magic methods/properties defined by @method and @property should be supported

From indexer will built a static checker that does the following:

  • Checks that referenced class/trait/interface exists
  • Checks that a method/property exists on class/interface when used
  • Notify of dead code
  • Check for undefined variables (indicates possible typos)
  • Checks correct parameters are given to function/methods/constructors
@phenaproxima

This comment has been minimized.

Copy link

commented Apr 22, 2015

Here are the test methods I've sketched in based on this gist:

  public function testGetFiles() {
    // $index->getFiles() returns a collection of FileIndex keyed by filename
  }

  public function testGetClasses() {
    // $index->getClasses() returns a collection of ClassIndex keyed by
    // fully qualified name
  }

  public function testGetInterfaces() {
    // $index->getInterfaces() returns a collection of InterfaceIndex keyed by
    // fully qualified name
  }

  public function testGetTraits() {
    // $index->getTraits() returns a collection of TraitIndex keyed by fully
    // qualified name
  }

  public function testGetFunctions() {
    // $index->getFunctions() returns a collection of FunctionIndex keyed
    // by name
  }

  public function testGetConstants() {
    // $index->getConstants() returns a collection of ConstantIndex keyed
    // by fully qualified name
  }

  public function testGetClassProperties() {
    // $index->getClass('foo')->getProperties() returns a collection of
    // PropertyIndex keyed by name
  }

  public function testGetClassOwnProperties() {
    // $index->getClass('foo')->getOwnProperties() returns a collection of
    // PropertyIndex keyed by name
  }

  public function testGetClassMethods() {
    // $index->getClass('foo')->getMethods() returns a collection of
    // MethodIndex keyed by name
  }

  public function testGetClassOwnMethods() {
    // $index->getClass('foo')->getOwnMethods() returns a collection of
    // MethodIndex keyed by name
  }

  public function testGetClassConstants() {
    // $index->getClass('foo')->getConstants() returns a collection of
    // ConstantIndex keyed by name
  }

  public function testGetClassOwnConstants() {
    // $index->getClass('foo')->getOwnConstants() returns a collection of
    // ConstantIndex keyed by name
  }

  public function testGetInterfaceMethods() {
    // $index->getInterface('foo')->getMethods() returns a collection of
    // MethodIndex keyed by name
  }

  public function testGetInterfaceOwnMethods() {
    // $index->getInterface('foo')->getOwnMethods() returns a collection of
    // MethodIndex keyed by name
  }

  public function testGetInterfaceConstants() {
    // $index->getInterface('foo')->getConstants() returns a collection of
    // ConstantIndex keyed by name
  }

  public function testGetInterfaceOwnConstants() {
    // $index->getInterface('foo')->getOwnConstants() returns a collection of
    // ConstantIndex keyed by name
  }

  public function testGetTraitProperties() {
    // $index->getTrait('foo')->getProperties() returns a collection of
    // PropertyIndex keyed by name
  }

  public function testGetTraitOwnProperties() {
    // $index->getTrait('foo')->getOwnProperties() returns a collection of
    // PropertyIndex keyed by name
  }

  public function testGetTraitMethods() {
    // $index->getTrait('foo')->getMethods() returns a collection of
    // MethodIndex keyed by name
  }

  public function testGetTraitOwnMethods() {
    // $index->getTrait('foo')->getOwnMethods() returns a collection of
    // MethodIndex keyed by name
  }

  public function testGetTraitConstants() {
    // $index->getTrait('foo')->getConstants() returns a collection of
    // ConstantIndex keyed by name
  }

  public function testGetTraitOwnConstants() {
    // $index->getTrait('foo')->getOwnConstants() returns a collection of
    // ConstantIndex keyed by name
  }

  public function testGetClassParent() {
    // $index->getClass('foo')->getParent() returns a ClassIndex or NULL
  }

  public function testGetClassInterfaces() {
    // $index->getClass('foo')->getInterfaces() returns a collection of
    // InterfaceIndex keyed by fully qualified name
  }

  public function testGetClassTraits() {
    // $index->getClass('foo')->getTraits() returns a collection of TraitIndex
    // keyed by fully qualified name
  }

  public function testGetClassExtendedBy() {
    // $index->getClass('foo')->extendedBy() returns a collection of
    // ClassIndex keyed by fully qualified name
  }

  public function testGetInterfaceParents() {
    // $index->getInterface('foo')->getParents() returns a collection of
    // InterfaceIndex keyed by fully qualified name
  }

  public function testGetInterfaceExtendedBy() {
    // $index->getInterface('foo')->extendedBy() returns a collection of
    // InterfaceIndex keyed by fully qualified name
  }

  public function testGetInterfaceImplementedBy() {
    // $index->getInterface('foo')->implementedBy() returns a collection of
    // ClassIndex keyed by fully qualified name
  }

  public function testGetTraitClasses() {
    // $index->getTrait('foo')->getClasses() returns a collection of
    // ClassIndex keyed by fully qualified name
  }

  public function testGetTraitTraitsUsing() {
    // $index->getTrait('foo')->getTraitsUsing() returns a collection of
    // TraitIndex keyed by fully qualified name
  }

  public function testGetTraitTraitsUsed() {
    // $index->getTrait('foo')->getTraitsUsed() returns a collection of
    // TraitIndex keyed by fully qualified name
  }

  public function testGetClassInstances() {
    // $index->getClass('foo')->getInstances() returns SourcePosition[]
  }

  public function testGetFunctionCalls() {
    // $index->getFunction('foo')->getCalls() returns SourcePosition[]
  }

  public function testFileDelete() {
    // $index->getFile('foo')->delete() should delete classes, functions,
    // constants, interfaces, and traits it contains
  }

  public function testMethodAnnotation() {
    // $index->getClass('foo')->getMethod('baz') should return a MethodIndex
    // for @method mixed baz(integer $bar)
  }

  public function testPropertyAnnotation() {
    // $index->getClass('foo')->getProperty('baz') should return a
    // PropertyIndex for @property string $baz
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.