Chris@13: args($args) Chris@13: ); Chris@13: } Chris@13: Chris@13: /** Chris@13: * Creates a method call node. Chris@13: * Chris@13: * @param Expr $var Variable the method is called on Chris@13: * @param string|Identifier|Expr $name Method name Chris@13: * @param array $args Method arguments Chris@13: * Chris@13: * @return Expr\MethodCall Chris@13: */ Chris@13: public function methodCall(Expr $var, $name, array $args = []) : Expr\MethodCall { Chris@13: return new Expr\MethodCall( Chris@13: $var, Chris@13: BuilderHelpers::normalizeIdentifierOrExpr($name), Chris@13: $this->args($args) Chris@13: ); Chris@13: } Chris@13: Chris@13: /** Chris@13: * Creates a static method call node. Chris@13: * Chris@13: * @param string|Name|Expr $class Class name Chris@13: * @param string|Identifier|Expr $name Method name Chris@13: * @param array $args Method arguments Chris@13: * Chris@13: * @return Expr\StaticCall Chris@13: */ Chris@13: public function staticCall($class, $name, array $args = []) : Expr\StaticCall { Chris@13: return new Expr\StaticCall( Chris@13: BuilderHelpers::normalizeNameOrExpr($class), Chris@13: BuilderHelpers::normalizeIdentifierOrExpr($name), Chris@13: $this->args($args) Chris@13: ); Chris@13: } Chris@13: Chris@13: /** Chris@13: * Creates an object creation node. Chris@13: * Chris@13: * @param string|Name|Expr $class Class name Chris@13: * @param array $args Constructor arguments Chris@13: * Chris@13: * @return Expr\New_ Chris@13: */ Chris@13: public function new($class, array $args = []) : Expr\New_ { Chris@13: return new Expr\New_( Chris@13: BuilderHelpers::normalizeNameOrExpr($class), Chris@13: $this->args($args) Chris@13: ); Chris@13: } Chris@13: Chris@13: /** Chris@13: * Creates a constant fetch node. Chris@13: * Chris@13: * @param string|Name $name Constant name Chris@13: * Chris@13: * @return Expr\ConstFetch Chris@13: */ Chris@13: public function constFetch($name) : Expr\ConstFetch { Chris@13: return new Expr\ConstFetch(BuilderHelpers::normalizeName($name)); Chris@13: } Chris@17: Chris@17: /** Chris@17: * Creates a property fetch node. Chris@17: * Chris@17: * @param Expr $var Variable holding object Chris@17: * @param string|Identifier|Expr $name Property name Chris@17: * Chris@17: * @return Expr\PropertyFetch Chris@17: */ Chris@17: public function propertyFetch(Expr $var, $name) : Expr\PropertyFetch { Chris@17: return new Expr\PropertyFetch($var, BuilderHelpers::normalizeIdentifierOrExpr($name)); Chris@17: } Chris@13: Chris@13: /** Chris@13: * Creates a class constant fetch node. Chris@13: * Chris@13: * @param string|Name|Expr $class Class name Chris@13: * @param string|Identifier $name Constant name Chris@13: * Chris@13: * @return Expr\ClassConstFetch Chris@13: */ Chris@13: public function classConstFetch($class, $name): Expr\ClassConstFetch { Chris@13: return new Expr\ClassConstFetch( Chris@13: BuilderHelpers::normalizeNameOrExpr($class), Chris@13: BuilderHelpers::normalizeIdentifier($name) Chris@13: ); Chris@13: } Chris@13: Chris@13: /** Chris@13: * Creates nested Concat nodes from a list of expressions. Chris@13: * Chris@13: * @param Expr|string ...$exprs Expressions or literal strings Chris@13: * Chris@13: * @return Concat Chris@13: */ Chris@13: public function concat(...$exprs) : Concat { Chris@13: $numExprs = count($exprs); Chris@13: if ($numExprs < 2) { Chris@13: throw new \LogicException('Expected at least two expressions'); Chris@0: } Chris@0: Chris@13: $lastConcat = $this->normalizeStringExpr($exprs[0]); Chris@13: for ($i = 1; $i < $numExprs; $i++) { Chris@13: $lastConcat = new Concat($lastConcat, $this->normalizeStringExpr($exprs[$i])); Chris@13: } Chris@13: return $lastConcat; Chris@13: } Chris@13: Chris@13: /** Chris@13: * @param string|Expr $expr Chris@13: * @return Expr Chris@13: */ Chris@13: private function normalizeStringExpr($expr) : Expr { Chris@13: if ($expr instanceof Expr) { Chris@13: return $expr; Chris@13: } Chris@13: Chris@13: if (\is_string($expr)) { Chris@13: return new String_($expr); Chris@13: } Chris@13: Chris@13: throw new \LogicException('Expected string or Expr'); Chris@0: } Chris@0: }