PhpParser\Node\Name::concat PHP Method

concat() public static method

The type of the generated instance depends on which class this method is called on, for example Name\FullyQualified::concat() will yield a Name\FullyQualified instance. If one of the arguments is null, a new instance of the other name will be returned. If both arguments are null, null will be returned. As such, writing Name::concat($namespace, $shortName) where $namespace is a Name node or null will work as expected.
public static concat ( string | array | self | null $name1, string | array | self | null $name2, array $attributes = [] ) : static | null
$name1 string | array | self | null The first name
$name2 string | array | self | null The second name
$attributes array Attributes to assign to concatenated name
return static | null Concatenated name
    public static function concat($name1, $name2, array $attributes = [])
    {
        if (null === $name1 && null === $name2) {
            return null;
        } elseif (null === $name1) {
            return new static(self::prepareName($name2), $attributes);
        } else {
            if (null === $name2) {
                return new static(self::prepareName($name1), $attributes);
            } else {
                return new static(array_merge(self::prepareName($name1), self::prepareName($name2)), $attributes);
            }
        }
    }

Usage Example

 protected function addAlias(Stmt\UseUse $use, $type, Name $prefix = null)
 {
     parent::addAlias($use, $type, $prefix);
     if ($type == Stmt\Use_::TYPE_NORMAL) {
         // Add prefix for group uses
         $name = strval($prefix ? Name::concat($prefix, $use->name) : $use->name);
         $this->classAliases[$use->alias] = $name;
     }
 }
All Usage Examples Of PhpParser\Node\Name::concat