PDepend\Metrics\Analyzer\NPathComplexityAnalyzer::visitIfStatement PHP Method

visitIfStatement() public method

if () S; -- NP(if) = NP() + NP() + 1 -- if () else S; -- NP(if) = NP() + NP() + NP( --
Since: 0.9.12
public visitIfStatement ( PDepend\Source\AST\ASTNode $node, string $data ) : string
$node PDepend\Source\AST\ASTNode The currently visited node.
$data string The previously calculated npath value.
return string
    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);
    }