/** * Calculates the expression sum of the given node. * * @param PHP_Depend_Code_ASTNodeI $node The currently visited node. * * @return string * @since 0.9.12 * @todo I don't like this method implementation, it should be possible to * implement this method with more visitor behavior for the boolean * and logical expressions. */ public function sumComplexity($node) { $sum = '0'; if ($node instanceof PHP_Depend_Code_ASTConditionalExpression) { $sum = PHP_Depend_Util_MathUtil::add($sum, $node->accept($this, 1)); } else { if ($node instanceof PHP_Depend_Code_ASTBooleanAndExpression || $node instanceof PHP_Depend_Code_ASTBooleanOrExpression || $node instanceof PHP_Depend_Code_ASTLogicalAndExpression || $node instanceof PHP_Depend_Code_ASTLogicalOrExpression || $node instanceof PHP_Depend_Code_ASTLogicalXorExpression) { $sum = PHP_Depend_Util_MathUtil::add($sum, '1'); } else { foreach ($node->getChildren() as $child) { $expr = $this->sumComplexity($child); $sum = PHP_Depend_Util_MathUtil::add($sum, $expr); } } } return $sum; }
/** * Visits a switch label. * * @param PHP_Depend_Code_ASTNodeI $node The currently visited node. * @param array(string=>integer) $data The previously calculated ccn values. * * @return array(string=>integer) * @since 0.9.8 */ public function visitSwitchLabel($node, $data) { if (!$node->isDefault()) { ++$data[self::M_CYCLOMATIC_COMPLEXITY_1]; ++$data[self::M_CYCLOMATIC_COMPLEXITY_2]; } return $this->visit($node, $data); }
/** * This method adds a new child node to this node instance. * * @param PHP_Depend_Code_ASTNodeI $node The new child node. * * @return void */ public function addChild(PHP_Depend_Code_ASTNodeI $node) { // Store child node $this->nodes[] = $node; // Set this as parent $node->setParent($this); }
/** * This method adds a new child node to this node instance. * * @param PHP_Depend_Code_ASTNodeI $node The new child node. * * @return void */ public function addChild(PHP_Depend_Code_ASTNodeI $node) { $this->nodes[] = $node; $node->setParent($this); }