Ejemplo n.º 1
0
 /**
  * Collects all children from a given node.
  *
  * @param PHP_Depend_Code_ASTNode $node The current root node.
  *
  * @return array
  */
 protected static function collectGraph(PHP_Depend_Code_ASTNode $node)
 {
     $graph = array();
     foreach ($node->getChildren() as $child) {
         $graph[] = get_class($child) . ' (' . $child->getImage() . ')';
         if (0 < count($child->getChildren())) {
             $graph[] = self::collectGraph($child);
         }
     }
     return $graph;
 }
Ejemplo n.º 2
0
 /**
  * Collects all children from a given node.
  *
  * @param PHP_Depend_Code_ASTNode $node   The current root node.
  * @param array                   $actual Previous filled list.
  *
  * @return array(string)
  */
 protected function collectChildNodes(PHP_Depend_Code_ASTNode $node, array $actual = array())
 {
     foreach ($node->getChildren() as $child) {
         $actual[] = get_class($child);
         $actual = $this->collectChildNodes($child, $actual);
     }
     return $actual;
 }
Ejemplo n.º 3
0
 /**
  * Calculates the expression sum of the given node.
  *
  * @param PHP_Depend_Code_ASTNode $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;
 }