1 <?php declare(strict_types=1);
3 namespace PhpParser\Internal;
6 use PhpParser\Node\Expr;
9 * This node is used internally by the format-preserving pretty printer to print anonymous classes.
11 * The normal anonymous class structure violates assumptions about the order of token offsets.
12 * Namely, the constructor arguments are part of the Expr\New_ node and follow the class node, even
13 * though they are actually interleaved with them. This special node type is used temporarily to
14 * restore a sane token offset order.
18 class PrintableNewAnonClassNode extends Expr
20 /** @var Node\Arg[] Arguments */
22 /** @var null|Node\Name Name of extended class */
24 /** @var Node\Name[] Names of implemented interfaces */
26 /** @var Node\Stmt[] Statements */
29 public function __construct(
30 array $args, Node\Name $extends = null, array $implements, array $stmts, array $attributes
32 parent::__construct($attributes);
34 $this->extends = $extends;
35 $this->implements = $implements;
36 $this->stmts = $stmts;
39 public static function fromNewNode(Expr\New_ $newNode) {
40 $class = $newNode->class;
41 assert($class instanceof Node\Stmt\Class_);
42 assert($class->name === null);
44 $newNode->args, $class->extends, $class->implements,
45 $class->stmts, $newNode->getAttributes()
49 public function getType() : string {
50 return 'Expr_PrintableNewAnonClass';
53 public function getSubNodeNames() : array {
54 return ['args', 'extends', 'implements', 'stmts'];