Exemplo n.º 1
0
 /**
  * This method parses the contents of a string or here-/now-doc node. It
  * will not consume the given stop token, so it is up to the calling method
  * to consume the stop token. The return value of this method is the prepared
  * input string node.
  *
  * @param  \PDepend\Source\AST\ASTNode $node
  * @param  integer                     $stopToken
  * @return \PDepend\Source\AST\ASTNode
  * @since  0.9.12
  */
 private function parseStringExpressions(ASTNode $node, $stopToken)
 {
     while (($tokenType = $this->tokenizer->peek()) != Tokenizer::T_EOF) {
         switch ($tokenType) {
             case $stopToken:
                 break 2;
             case Tokens::T_BACKSLASH:
                 $node->addChild($this->parseEscapedAstLiteralString());
                 break;
             case Tokens::T_DOLLAR:
                 $node->addChild($this->parseCompoundVariableOrLiteral());
                 break;
             case Tokens::T_VARIABLE:
                 $node->addChild($this->parseVariable());
                 break;
             case Tokens::T_CURLY_BRACE_OPEN:
                 $node->addChild($this->parseCompoundExpressionOrLiteral());
                 break;
             default:
                 $node->addChild($this->parseLiteral());
                 break;
         }
     }
     return $node;
 }
 /**
  * Visits a switch label.
  *
  * @param \PDepend\Source\AST\ASTNode $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 \PDepend\Source\AST\ASTNode $node The new child node.
  *
  * @return void
  */
 public function addChild(\PDepend\Source\AST\ASTNode $node)
 {
     $this->nodes[] = $node;
     $node->setParent($this);
 }
Exemplo n.º 4
0
 /**
  * Returns the name of the declaring source file.
  *
  * @return string
  */
 public function getFileName()
 {
     return (string) $this->node->getCompilationUnit()->getFileName();
 }
Exemplo n.º 5
0
 /**
  * Calculates the expression sum of the given node.
  *
  * @param \PDepend\Source\AST\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 ASTConditionalExpression) {
         $sum = MathUtil::add($sum, $node->accept($this, 1));
     } elseif ($node instanceof ASTBooleanAndExpression || $node instanceof ASTBooleanOrExpression || $node instanceof ASTLogicalAndExpression || $node instanceof ASTLogicalOrExpression || $node instanceof ASTLogicalXorExpression) {
         $sum = MathUtil::add($sum, '1');
     } else {
         foreach ($node->getChildren() as $child) {
             $expr = $this->sumComplexity($child);
             $sum = MathUtil::add($sum, $expr);
         }
     }
     return $sum;
 }
Exemplo n.º 6
0
 /**
  * Magic sleep method that returns an array with those property names that
  * should be cached for this node instance.
  *
  * @return array(string)
  */
 public function __sleep()
 {
     return array_merge(array('value'), parent::__sleep());
 }
 /**
  * Collects all children from a given node.
  *
  * @param \PDepend\Source\AST\ASTNode $node The current root node.
  *
  * @return array
  */
 protected static function collectGraph(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;
 }