/**
  * Enter in a new instance statement (only process "hard-coded" classname)
  *
  * @param \PHPParser_Node_Expr_New $node
  * @return \PHPParser_Node_Expr_MethodCall|null
  */
 protected function enterNewInstance(\PHPParser_Node_Expr_New $node)
 {
     if ($node->class instanceof \PHPParser_Node_Name) {
         $classShortcut = (string) $node->class;
         $methodName = 'create' . str_replace('\\', '_', $classShortcut) . count($node->args);
         $calling = new \PHPParser_Node_Expr_MethodCall(new \PHPParser_Node_Expr_Variable('this'), $methodName);
         $calling->args = $node->args;
         $calling->setAttribute('classShortcut', $classShortcut);
         $this->factoryMethodStack[$methodName] = $calling;
         $this->currentPhpFile->modified();
         return $calling;
     }
     return null;
 }
示例#2
0
 public function pExpr_MethodCall(\PHPParser_Node_Expr_MethodCall $node)
 {
     $firstToken = '';
     $lastToken = '';
     if (count($node->args) > 0) {
         if ($node->getAttribute('startLine') != reset($node->args)->getAttribute('startLine')) {
             $firstToken = LF . $this->indentToken;
         }
         if ($node->getAttribute('startLine') != end($node->args)->getAttribute('startLine')) {
             $lastToken = LF;
         }
     }
     return $this->pVarOrNewExpr($node->var) . '->' . $this->pObjectProperty($node->name) . '(' . $firstToken . $this->pParameterNodes($node->args) . $lastToken . ')';
 }