/** * 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); }