/** * @param AbstractNode|AbstractASTArtifact $node * * @return float */ private function calculateNameToCommentSimilarityInPercent($node) { $docComment = $node->getDocComment(); if (empty($docComment)) { return 0; } similar_text($this->transformString($node->getName()), $this->getCommentDescription($docComment), $percent); return round($percent); }
/** * 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; }
/** * Returns an array of nodes that build a cycle for the requested node or it * returns <b>null</b> if no cycle exists . * * @param \PDepend\Source\AST\AbstractASTArtifact $node * @return \PDepend\Source\AST\AbstractASTArtifact[] */ public function getCycle(AbstractASTArtifact $node) { if (array_key_exists($node->getId(), $this->collectedCycles)) { return $this->collectedCycles[$node->getId()]; } $list = array(); if ($this->collectCycle($list, $node)) { $this->collectedCycles[$node->getId()] = $list; } else { $this->collectedCycles[$node->getId()] = null; } return $this->collectedCycles[$node->getId()]; }
/** * Initializes the temporary node container for the given <b>$node</b>. * * @param \PDepend\Source\AST\AbstractASTArtifact $node * @return void */ protected function initNode(AbstractASTArtifact $node) { if (!isset($this->nodes[$node->getId()])) { $this->nodes[$node->getId()] = array('in' => array(), 'out' => array(), 'name' => $node->getName(), 'type' => get_class($node)); } }
/** * Adds a source item that was parsed from this source file. * * @param \PDepend\Source\AST\AbstractASTArtifact $artifact * @return void * @since 0.10.0 */ public function addChild(AbstractASTArtifact $artifact) { $this->childNodes[$artifact->getId()] = $artifact; }
/** * 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); }
/** * Tries to restore the metrics for a cached node. If this method has * restored the metrics it will return <b>TRUE</b>, otherwise the return * value will be <b>FALSE</b>. * * @param \PDepend\Source\AST\AbstractASTArtifact $node * @return boolean */ protected function restoreFromCache(AbstractASTArtifact $node) { $id = $node->getId(); if ($node->isCached() && isset($this->metricsCached[$id])) { $this->metrics[$id] = $this->metricsCached[$id]; return true; } return false; }
/** * Returns an array of all efferent nodes. * * @param \PDepend\Source\AST\AbstractASTArtifact $node * @return \PDepend\Source\AST\AbstractASTArtifact[] */ public function getEfferents(AbstractASTArtifact $node) { $efferents = array(); if (isset($this->efferentNodes[$node->getId()])) { $efferents = $this->efferentNodes[$node->getId()]; } return $efferents; }
public function endVisitNode(AbstractASTArtifact $node) { $this->nodes[$node->getName() . '#end'] = true; parent::endVisitNode($node); }