/** * 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; }
/** * This method calculates the NPath Complexity of a block in parenthesis and * it returns the meassured value as a string. * * <code> * ($a && ($b || $c)) * ($array as $a => $b) * ... * </code> * * @return string */ private function _sumExpressionComplexity() { $npath = '0'; $scope = 0; while (($token = current($this->_tokens)) !== false) { switch ($token->type) { case PHP_Depend_ConstantsI::T_PARENTHESIS_OPEN: ++$scope; break; case PHP_Depend_ConstantsI::T_PARENTHESIS_CLOSE: --$scope; break; case PHP_Depend_ConstantsI::T_BOOLEAN_AND: case PHP_Depend_ConstantsI::T_BOOLEAN_OR: case PHP_Depend_ConstantsI::T_LOGICAL_AND: case PHP_Depend_ConstantsI::T_LOGICAL_OR: case PHP_Depend_ConstantsI::T_LOGICAL_XOR: $npath = PHP_Depend_Util_MathUtil::add('1', $npath); break; } next($this->_tokens); if ($scope === 0) { break; } } return $npath; }