/** * This method calculates the NPath Complexity of an if-statement, the * meassured value is then returned as a string. * * <code> * if (<expr>) * <if-range> * S; * * -- NP(if) = NP(<if-range>) + NP(<expr>) + 1 -- * * * if (<expr>) * <if-range> * else * <else-range> * S; * * -- NP(if) = NP(<if-range>) + NP(<expr>) + NP(<else-range> -- * </code> * * @param PHP_Depend_Code_ASTNodeI $node The currently visited node. * @param string $data The previously calculated npath value. * * @return string * @since 0.9.12 */ public function visitIfStatement($node, $data) { $npath = $this->sumComplexity($node->getChild(0)); foreach ($node->getChildren() as $child) { if ($child instanceof PHP_Depend_Code_ASTStatement) { $stmt = $child->accept($this, 1); $npath = PHP_Depend_Util_MathUtil::add($npath, $stmt); } } if (!$node->hasElse()) { $npath = PHP_Depend_Util_MathUtil::add($npath, '1'); } return PHP_Depend_Util_MathUtil::mul($npath, $data); }