/** * 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 \PDepend\Source\AST\ASTNode $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 ASTStatement) { $stmt = $child->accept($this, 1); $npath = MathUtil::add($npath, $stmt); } } if (!$node->hasElse()) { $npath = MathUtil::add($npath, '1'); } return MathUtil::mul($npath, $data); }