Ejemplo n.º 1
0
 /**
  * This method calculates the NPath Complexity of a while-statement, the
  * meassured value is then returned as a string.
  *
  * <code>
  * while (<expr>)
  *   <while-range>
  * S;
  *
  * -- NP(while) = NP(<while-range>) + NP(<expr>) + 1 --
  * </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 visitWhileStatement($node, $data)
 {
     $expr = $this->sumComplexity($node->getChild(0));
     $stmt = $node->getChild(1)->accept($this, 1);
     $npath = PHP_Depend_Util_MathUtil::add($expr, $stmt);
     $npath = PHP_Depend_Util_MathUtil::add($npath, '1');
     return PHP_Depend_Util_MathUtil::mul($npath, $data);
 }
Ejemplo n.º 2
0
 /**
  * This method calculates the NPath Complexity of a switch-statement, the
  * meassured value is then returned as a string.
  *
  * <code>
  * switch (<expr>)
  *   <case-range1>
  *   <case-range2>
  *   ...
  *   <default-range>
  *
  * -- NP(switch) = NP(<expr>) + NP(<default-range>) +  NP(<case-range1>) ... --
  * </code>
  *
  * @return string
  */
 private function _calculateSwitchStatement()
 {
     // Remove <switch> token
     next($this->_tokens);
     $scope = 0;
     $case = '0';
     $npath = $this->_sumExpressionComplexity();
     while (($token = current($this->_tokens)) !== false) {
         switch ($token->type) {
             case PHP_Depend_ConstantsI::T_CURLY_BRACE_OPEN:
                 ++$scope;
                 $token = next($this->_tokens);
                 break;
             case PHP_Depend_ConstantsI::T_CURLY_BRACE_CLOSE:
                 --$scope;
                 $token = next($this->_tokens);
                 break;
             case PHP_Depend_ConstantsI::T_CASE:
             case PHP_Depend_ConstantsI::T_DEFAULT:
                 $token = next($this->_tokens);
                 $npath = PHP_Depend_Util_MathUtil::add($npath, $case);
                 $case = '1';
                 break;
             default:
                 $comp = $this->_calculateScopeOrStatement();
                 $case = PHP_Depend_Util_MathUtil::mul($case, $comp);
                 break;
         }
         if ($scope === 0) {
             break;
         }
     }
     return PHP_Depend_Util_MathUtil::add($npath, $case);
 }