1 | <?php |
||
20 | class GraphHandler implements ActionHandler |
||
21 | { |
||
22 | /** @var string Name of the font to use to display the node labels with */ |
||
23 | protected $nodeFont = 'Courier'; |
||
24 | |||
25 | /** @var Node[] a cache where nodes for classes, interfaces and traits are stored for reference */ |
||
26 | protected $nodeCache = array(); |
||
27 | |||
28 | /** @var Analyzer */ |
||
29 | private $analyzer; |
||
|
|||
30 | |||
31 | // public function __construct(Analyzer $analyzer) |
||
32 | // { |
||
33 | // $this->analyzer = $analyzer; |
||
34 | // } |
||
35 | |||
36 | /** |
||
37 | * Executes the activities that this Action represents. |
||
38 | * |
||
39 | * @param Action|Graph $action |
||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | public function __invoke(Action $action) |
||
44 | { |
||
45 | // $project = $this->analyzer->getProjectDescriptor(); |
||
46 | // try { |
||
47 | // $this->checkIfGraphVizIsInstalled(); |
||
48 | // } catch (\Exception $e) { |
||
49 | // echo $e->getMessage(); |
||
50 | // |
||
51 | // return; |
||
52 | // } |
||
53 | // |
||
54 | // $graph = GraphVizGraph::create() |
||
55 | // ->setRankSep('1.0') |
||
56 | // ->setCenter('true') |
||
57 | // ->setRank('source') |
||
58 | // ->setRankDir('RL') |
||
59 | // ->setSplines('true') |
||
60 | // ->setConcentrate('true'); |
||
61 | // |
||
62 | // $this->buildNamespaceTree($graph, $project->getNamespace()); |
||
63 | // |
||
64 | // $classes = $project->getIndexes()->get('classes', new Collection())->getAll(); |
||
65 | // $interfaces = $project->getIndexes()->get('interfaces', new Collection())->getAll(); |
||
66 | // $traits = $project->getIndexes()->get('traits', new Collection())->getAll(); |
||
67 | // |
||
68 | // /** @var ClassDescriptor[]|InterfaceDescriptor[]|TraitDescriptor[] $containers */ |
||
69 | // $containers = array_merge($classes, $interfaces, $traits); |
||
70 | // |
||
71 | // foreach ($containers as $container) { |
||
72 | // $from_name = $container->getFullyQualifiedStructuralElementName(); |
||
73 | // |
||
74 | // $parents = array(); |
||
75 | // $implemented = array(); |
||
76 | // if ($container instanceof ClassDescriptor) { |
||
77 | // if ($container->getParent()) { |
||
78 | // $parents[] = $container->getParent(); |
||
79 | // } |
||
80 | // $implemented = $container->getInterfaces()->getAll(); |
||
81 | // } |
||
82 | // if ($container instanceof InterfaceDescriptor) { |
||
83 | // $parents = $container->getParent()->getAll(); |
||
84 | // } |
||
85 | // |
||
86 | // /** @var string|ClassDescriptor|InterfaceDescriptor $parent */ |
||
87 | // foreach ($parents as $parent) { |
||
88 | // $edge = $this->createEdge($graph, $from_name, $parent); |
||
89 | // $edge->setArrowHead('empty'); |
||
90 | // $graph->link($edge); |
||
91 | // } |
||
92 | // |
||
93 | // /** @var string|ClassDescriptor|InterfaceDescriptor $parent */ |
||
94 | // foreach ($implemented as $parent) { |
||
95 | // $edge = $this->createEdge($graph, $from_name, $parent); |
||
96 | // $edge->setStyle('dotted'); |
||
97 | // $edge->setArrowHead('empty'); |
||
98 | // $graph->link($edge); |
||
99 | // } |
||
100 | // } |
||
101 | // |
||
102 | // $destination = $action->getRenderContext()->getDestination() . '/' . $action->getDestination(); |
||
103 | // if (! file_exists(dirname($destination))) { |
||
104 | // @mkdir(dirname($destination), 0777, true); |
||
105 | // } |
||
106 | // $graph->export('svg', $destination); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Creates a GraphViz Edge between two nodes. |
||
111 | * |
||
112 | * @param Graph $graph |
||
113 | * @param string $from_name |
||
114 | * @param string|ClassDescriptor|InterfaceDescriptor|TraitDescriptor $to |
||
115 | * |
||
116 | * @return Edge |
||
117 | */ |
||
118 | protected function createEdge($graph, $from_name, $to) |
||
131 | |||
132 | /** |
||
133 | * @param string $name |
||
134 | * @param Graph $graph |
||
135 | * |
||
136 | * @return Node |
||
137 | */ |
||
138 | protected function createEmptyNode($name, $graph) |
||
147 | |||
148 | /** |
||
149 | * Builds a tree of namespace subgraphs with their classes associated. |
||
150 | * |
||
151 | * @param GraphVizGraph $graph |
||
152 | * @param NamespaceDescriptor $namespace |
||
153 | * |
||
154 | * @return void |
||
155 | */ |
||
156 | protected function buildNamespaceTree(GraphVizGraph $graph, NamespaceDescriptor $namespace) |
||
202 | |||
203 | /** |
||
204 | * Checks whether GraphViz is installed and throws an Exception otherwise. |
||
205 | * |
||
206 | * @throws \RuntimeException if graphviz is not found. |
||
207 | * |
||
208 | * @return void |
||
209 | */ |
||
210 | protected function checkIfGraphVizIsInstalled() |
||
221 | } |
||
222 |
This check marks private properties in classes that are never used. Those properties can be removed.