/** * Adds a source item that was parsed from this source file. * * @param PHP_Depend_Code_AbstractItem $item Node parsed in this file. * * @return void * @since 0.10.0 */ public function addChild(PHP_Depend_Code_AbstractItem $item) { $this->childNodes[$item->getUUID()] = $item; }
/** * Returns the percentage code coverage for the given item instance. * * @param PHP_Depend_Code_AbstractItem $item The context code item. * * @return float */ public function getCoverage(PHP_Depend_Code_AbstractItem $item) { $lines = $this->_getLines((string) $item->getSourceFile()); $startLine = $item->getStartLine(); $endLine = $item->getEndLine(); $executable = 0; $executed = 0; for ($i = $startLine; $i <= $endLine; ++$i) { if (!isset($lines[$i])) { continue; } ++$executable; if ($lines[$i]) { ++$executed; } } if ($executed === 0) { return 0; } return $executed / $executable * 100; }
/** * Generates an identifier for the given source item. * * @param PHP_Depend_Code_AbstractItem $item The context source item. * @param string $prefix The item type identifier. * * @return string */ protected function forOffsetItem(PHP_Depend_Code_AbstractItem $item, $prefix) { $fileHash = $item->getSourceFile()->getUUID(); $itemHash = $this->hash($prefix . ':' . strtolower($item->getName())); $offset = $this->getOffsetInFile($fileHash, $itemHash); return sprintf('%s-%s-%s', $fileHash, $itemHash, $offset); }
/** * Returns the name of the declaring source file. * * @return string */ public function getFileName() { return (string) $this->_node->getSourceFile(); }