Ejemplo n.º 1
0
 /**
  * Creates a new class member.
  *
  * @param string $name
  *  The name of the member, with or without the leading $.
  * @param \Pharborist\ExpressionNode $value
  *  The default value of the member, if any.
  * @param string $visibility
  *  The member's visibility. Can be public, private, or protected. Defaults to
  *  public.
  *
  * @return ClassMemberListNode
  *
  * @todo Not all expressions can be default values, but I forget what sorts of
  * expressions are valid for this. Will need better sanity checking here.
  */
 public static function create($name, ExpressionNode $value = NULL, $visibility = 'public')
 {
     $code = $visibility . ' $' . ltrim($name, '$');
     if ($value instanceof ExpressionNode) {
         $code .= ' = ' . $value->getText();
     }
     /** @var ClassNode $class_node */
     $class_node = Parser::parseSnippet('class Foo { ' . $code . '; }');
     return $class_node->getStatements()[0]->remove();
 }
Ejemplo n.º 2
0
 /**
  * Creates a new return statement.
  *
  * @param \Pharborist\ExpressionNode $expr
  *  The expression to return.
  *
  * @return static
  */
 public static function create(ExpressionNode $expr)
 {
     return Parser::parseSnippet('return ' . $expr->getText() . ';');
 }