Exemple #1
0
 /**
  * Returns the percentage code coverage for the given item instance.
  *
  * @param  \PDepend\Source\AST\AbstractASTArtifact $artifact
  * @return float
  */
 public function getCoverage(AbstractASTArtifact $artifact)
 {
     $lines = $this->getLines($artifact->getCompilationUnit()->getFileName());
     $startLine = $artifact->getStartLine();
     $endLine = $artifact->getEndLine();
     $executable = 0;
     $executed = 0;
     for ($i = $startLine; $i <= $endLine; ++$i) {
         if (!isset($lines[$i])) {
             continue;
         }
         ++$executable;
         if ($lines[$i]) {
             ++$executed;
         }
     }
     if (0 === $executed && 1 === $executable && 0 < $endLine - $startLine) {
         return 100;
     }
     if ($executed === 0) {
         return 0;
     }
     return $executed / $executable * 100;
 }
Exemple #2
0
 /**
  * Generates an identifier for the given source item.
  *
  * @param  \PDepend\Source\AST\AbstractASTArtifact $artifact
  * @param  string                                  $prefix   The item type identifier.
  * @return string
  */
 protected function forOffsetItem(AbstractASTArtifact $artifact, $prefix)
 {
     $fileHash = $artifact->getCompilationUnit()->getId();
     $itemHash = $this->hash($prefix . ':' . strtolower($artifact->getName()));
     $offset = $this->getOffsetInFile($fileHash, $itemHash);
     return sprintf('%s-%s-%s', $fileHash, $itemHash, $offset);
 }