/** * @param string $name * * @return \phpDocumentor\GraphViz\Graph */ private function getGraphByName($name) { $name = 'cluster_' . $name; if (!$this->graph->hasGraph($name)) { $graph = $this->graph->create($name); $this->graph->addGraph($graph); } return $this->graph->getGraph($name); }
/** * @covers phpDocumentor\GraphViz\Graph::findNode */ public function testFindNode() { $this->assertNull($this->fixture->findNode('MyNode')); $mock = $this->getMock('phpDocumentor\\GraphViz\\Node', array(), array(), '', false); $mock->expects($this->any())->method('getName')->will($this->returnValue('MyName')); $this->fixture->setNode($mock); $this->assertSame($mock, $this->fixture->findNode('MyName')); $subGraph = Graph::create(); $mock2 = $this->getMock('phpDocumentor\\GraphViz\\Node', array(), array(), '', false); $mock2->expects($this->any())->method('getName')->will($this->returnValue('MyName2')); $subGraph->setNode($mock2); $this->fixture->addGraph($subGraph); $this->assertSame($mock2, $this->fixture->findNode('MyName2')); }
/** * Builds a tree of namespace subgraphs with their classes associated. * * @param GraphVizGraph $graph * @param NamespaceDescriptor $namespace * * @return void */ protected function buildNamespaceTree(GraphVizGraph $graph, NamespaceDescriptor $namespace) { $full_namespace_name = $namespace->getFullyQualifiedStructuralElementName(); if ($full_namespace_name == '\\') { $full_namespace_name = 'Global'; } $sub_graph = GraphVizGraph::create('cluster_' . $full_namespace_name)->setLabel($namespace->getName() == '\\' ? 'Global' : $namespace->getName())->setStyle('rounded')->setColor('gray')->setFontColor('gray')->setFontSize('11')->setRankDir('LR'); $elements = array_merge($namespace->getClasses()->getAll(), $namespace->getInterfaces()->getAll(), $namespace->getTraits()->getAll()); /** @var ClassDescriptor|InterfaceDescriptor|TraitDescriptor $sub_element */ foreach ($elements as $sub_element) { $node = Node::create($sub_element->getFullyQualifiedStructuralElementName(), $sub_element->getName())->setShape('box')->setFontName($this->nodeFont)->setFontSize('11'); if ($sub_element instanceof ClassDescriptor && $sub_element->isAbstract()) { $node->setLabel('<«abstract»<br/>' . $sub_element->getName() . '>'); } //$full_name = $sub_element->getFullyQualifiedStructuralElementName(); //$node->setURL($this->class_paths[$full_name]); //$node->setTarget('_parent'); $this->nodeCache[$sub_element->getFullyQualifiedStructuralElementName()] = $node; $sub_graph->setNode($node); } foreach ($namespace->getChildren()->getAll() as $element) { $this->buildNamespaceTree($sub_graph, $element); } $graph->addGraph($sub_graph); }
/** * Builds a tree of namespace subgraphs with their classes associated. * * @param \phpDocumentor\GraphViz\Graph $graph Graph to expand on. * @param \DOMElement $namespace_element Namespace index element. * @param \DOMXPath $xpath $xpath object to use * for querying. * @param string $full_namespace_name unabbreviated version * of the current namespace, namespace index only contains an abbreviated * version and by building/passing this icnreases performance. * * @return void */ public function buildNamespaceTree(\phpDocumentor\GraphViz\Graph $graph, \DOMElement $namespace_element, \DOMXPath $xpath, $full_namespace_name) { $namespace = $namespace_element->getAttribute('name'); $full_namespace_name .= '\\' . $namespace; $full_namespace_name = ltrim($full_namespace_name, '\\'); $sub_graph = \phpDocumentor\GraphViz\Graph::create('cluster_' . $full_namespace_name)->setLabel($full_namespace_name != 'default' ? $namespace : '')->setStyle('rounded')->setColor($full_namespace_name != 'default' ? 'gray' : 'none')->setFontColor('gray')->setFontSize('11')->setRankDir('LR'); $sub_qry = $xpath->query("/project/file/interface[@namespace='{$full_namespace_name}']" . "|/project/file/class[@namespace='{$full_namespace_name}']"); /** @var \DOMElement $sub_element */ foreach ($sub_qry as $sub_element) { $node = \phpDocumentor\GraphViz\Node::create($sub_element->getElementsByTagName('full_name')->item(0)->nodeValue, $sub_element->getElementsByTagName('name')->item(0)->nodeValue); $node->setShape('box'); $node->setFontName($this->node_font); $node->setFontSize('11'); if ($sub_element->getAttribute('abstract') == 'true') { $node->setLabel('<«abstract»<br/>' . $sub_element->getElementsByTagName('name')->item(0)->nodeValue . '>'); } $full_name = $sub_element->getElementsByTagName('full_name')->item(0)->nodeValue; if (!isset($this->class_paths[$full_name])) { echo $full_name . PHP_EOL; } else { $node->setURL($this->class_paths[$full_name]); $node->setTarget('_parent'); } $sub_graph->setNode($node); } $graph->addGraph($sub_graph); foreach ($namespace_element->getElementsByTagName('namespace') as $element) { $this->buildNamespaceTree($sub_graph, $element, $xpath, $full_namespace_name); } }