|  | <?php | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  | namespace Trismegiste\Mondrian\Visitor; | 
     |  |  | 
     |  | use Trismegiste\Mondrian\Transform\Vertex; | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  | class VertexCollector extends PassCollector | 
     |  | { | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  | protected function enterClassNode(\PHPParser_Node_Stmt_Class $node) | 
     |  | { | 
     |  | $index = $this->currentClass; | 
     |  | if (!$this->existsVertex('class', $index)) { | 
     |  | $v = new Vertex\ClassVertex($index); | 
     |  | $this->graph->addVertex($v); | 
     |  | $this->indicesVertex('class', $index, $v); | 
     |  | } | 
     |  | } | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  | protected function enterInterfaceNode(\PHPParser_Node_Stmt_Interface $node) | 
     |  | { | 
     |  | $index = $this->currentClass; | 
     |  | if (!$this->existsVertex('interface', $index)) { | 
     |  | $v = new Vertex\InterfaceVertex($index); | 
     |  | $this->graph->addVertex($v); | 
     |  | $this->indicesVertex('interface', $index, $v); | 
     |  | } | 
     |  | } | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  | protected function enterPublicMethodNode(\PHPParser_Node_Stmt_ClassMethod $node) | 
     |  | { | 
     |  | if ($this->isTrait($this->currentClass)) { | 
     |  | $this->enterTraitMethod($node); | 
     |  | } elseif ($this->isInterface($this->currentClass)) { | 
     |  | $this->enterInterfaceMethod($node); | 
     |  | } else { | 
     |  | $this->enterClassMethod($node); | 
     |  | } | 
     |  | } | 
     |  |  | 
     |  | private function enterTraitMethod(\PHPParser_Node_Stmt_ClassMethod $node) | 
     |  | { | 
     |  |  | 
     |  |  | 
     |  | if (!$node->isAbstract()) { | 
     |  | $this->pushImplementation($node); | 
     |  | } | 
     |  |  | 
     |  |  | 
     |  | $index = $this->currentClass . '::' . $this->currentMethod; | 
     |  | foreach ($node->params as $order => $aParam) { | 
     |  | $this->pushParameter($index, $order); | 
     |  | } | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  | $traitUser = $this->getClassesUsingTraitForDeclaringMethod($this->currentClass, $this->currentMethod); | 
     |  | foreach ($traitUser as $classname) { | 
     |  |  | 
     |  | $index = $classname . '::' . $this->currentMethod; | 
     |  | if (!$this->existsVertex('method', $index)) { | 
     |  | $v = new Vertex\MethodVertex($index); | 
     |  | $this->graph->addVertex($v); | 
     |  | $this->indicesVertex('method', $index, $v); | 
     |  | } | 
     |  | } | 
     |  | } | 
     |  |  | 
     |  | private function enterClassMethod(\PHPParser_Node_Stmt_ClassMethod $node) | 
     |  | { | 
     |  |  | 
     |  | $declaringClass = $this->getDeclaringClass($this->currentClass, $this->currentMethod); | 
     |  | if ($this->currentClass == $declaringClass) { | 
     |  | $this->pushMethod($node); | 
     |  | } | 
     |  |  | 
     |  |  | 
     |  | if (!$node->isAbstract()) { | 
     |  | $this->pushImplementation($node); | 
     |  | } | 
     |  | } | 
     |  |  | 
     |  | private function enterInterfaceMethod(\PHPParser_Node_Stmt_ClassMethod $node) | 
     |  | { | 
     |  |  | 
     |  | $declaringClass = $this->getDeclaringClass($this->currentClass, $this->currentMethod); | 
     |  | if ($this->currentClass == $declaringClass) { | 
     |  | $this->pushMethod($node); | 
     |  | } | 
     |  | } | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  | protected function pushMethod(\PHPParser_Node_Stmt_ClassMethod $node, $index = null) | 
     |  | { | 
     |  | if (is_null($index)) { | 
     |  | $index = $this->getCurrentMethodIndex(); | 
     |  | } | 
     |  | if (!$this->existsVertex('method', $index)) { | 
     |  | $v = new Vertex\MethodVertex($index); | 
     |  | $this->graph->addVertex($v); | 
     |  | $this->indicesVertex('method', $index, $v); | 
     |  |  | 
     |  | foreach ($node->params as $order => $aParam) { | 
     |  | $this->pushParameter($index, $order); | 
     |  | } | 
     |  | } | 
     |  | } | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  | protected function pushImplementation(\PHPParser_Node_Stmt_ClassMethod $node) | 
     |  | { | 
     |  | $index = $this->getCurrentMethodIndex(); | 
     |  | if (!$this->existsVertex('impl', $index)) { | 
     |  | $v = new Vertex\ImplVertex($index); | 
     |  | $this->graph->addVertex($v); | 
     |  | $this->indicesVertex('impl', $index, $v); | 
     |  | } | 
     |  | } | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  |  | 
     |  | protected function pushParameter($methodName, $order) | 
     |  | { | 
     |  | $index = $methodName . '/' . $order; | 
     |  | if (!$this->existsVertex('param', $index)) { | 
     |  | $v = new Vertex\ParamVertex($index); | 
     |  | $this->graph->addVertex($v); | 
     |  | $this->indicesVertex('param', $index, $v); | 
     |  | } | 
     |  | } | 
     |  |  | 
     |  | protected function enterTraitNode(\PHPParser_Node_Stmt_Trait $node) | 
     |  | { | 
     |  | $index = $this->currentClass; | 
     |  | if (!$this->existsVertex('trait', $index)) { | 
     |  | $v = new Vertex\TraitVertex($index); | 
     |  | $this->graph->addVertex($v); | 
     |  | $this->indicesVertex('trait', $index, $v); | 
     |  | } | 
     |  | } | 
     |  |  | 
     |  | } |