/** * Analyzes the sources placed at the given path and returns the results. * * @param string $sourceCodeDir * @param string $modulesRelativePattern * * @return DependencyResponse * * @throws \InvalidArgumentException */ public function analyze($sourceCodeDir, $modulesRelativePattern) { // Get the modules and their paths. $modules = $this->getModules($sourceCodeDir, $modulesRelativePattern); if (empty($modules)) { return DependencyResponse::createEmptyResponse(); } // Get the module declarations: what classes they expose and what classes they use. $declarations = array(); foreach ($modules as $name => $path) { $declarations[$name] = $this->scanModule($path); } // Prepare the response. $moduleNames = array_keys($modules); $dependencyGraph = $this->buildDependencyGraph($declarations); $connectedComponents = $this->connectedComponentsAnalyzer->get($dependencyGraph); $score = count($connectedComponents) / count($modules); // Return the response. return new DependencyResponse($moduleNames, $dependencyGraph, $connectedComponents, $score); }
/** * Parses the analysis dependency results and generates the dependency graph edges in a format * that it will be used for rendering. * * @param DependencyResponse $dependencyResponse * @param array $nodes * * @return array */ private function computeGraphEdges(DependencyResponse $dependencyResponse, array $nodes) { $graph = $dependencyResponse->getGraph(); $edges = array(); $index = 0; foreach ($graph as $vertex => $neighbours) { foreach ($neighbours as $neighbour) { $edges[] = array('id' => Settings::GRAPH_EDGE_ID_PREFIX . $index, 'source' => $nodes[$vertex]['id'], 'target' => $nodes[$neighbour]['id'], 'color' => $nodes[$vertex]['color'], 'type' => Settings::GRAPH_EDGE_TYPE); $index++; } } return $edges; }