/** * Run PHP Code Sniffer over the given module. * * @param Module $module * * @return $this */ public function runSniffScan(Module $module) { // Look for an existing one before adding or updating. $conditions = array('name' => $module->getName(), 'version' => $module->getVersion()); $identifier = implode('-', $conditions); $found = $this->entityManager->getRepository('DrupalCodeMetrics\\SniffReport')->findOneBy($conditions); if ($found) { $report = $found; $this->log("Updating existing Sniff report for {$identifier}"); } else { $report = new SniffReport(); $this->log("Creating new Sniff report for {$identifier}"); } $report->setName($module->getName()); $report->setVersion($module->getVersion()); $now = new \DateTime(); $report->setUpdated($now); $analysis = $report->getSniffAnalysis($module, $this->options['extensions']); $report->setAnalysis($analysis); $this->entityManager->persist($report); $this->entityManager->flush(); if (!$analysis) { $this->log("SniffReport on " . $module->getName() . " failed. Not updating it."); $module->addStatus('sniff:failed'); } else { $module->addStatus('sniff:processed'); } return $this; }
/** * Runs PHP LinesOfCode analysis. * * Https://github.com/sebastianbergmann/phploc. * * @param \DrupalCodeMetrics\Module $module * @param $extensions * @return array|null */ function getLocAnalysis(Module $module, $extensions) { // Run phploc analyser directly as PHP. $analyser = new Analyser(); // It's my job to set the parameters right, and take care to only give it // PHP files (it borks on binaries, understandably). $tree = $module->getCodeFiles($extensions); $analysis = NULL; try { $analysis = $analyser->countFiles($tree, TRUE); } catch (Exception $e) { $message = "When processing " . $module->getLocation() . " " . $e->getMessage(); error_log($message); } return $analysis; }