public function insertItem(Node $item, $index) {
    $items = $this->getItems();
    if ($items->isEmpty()) {
      if ($index !== 0) {
        throw new \OutOfBoundsException('index out of bounds');
      }
      $this->append($item);
    }
    else {
      $max_index = count($items) - 1;
      if ($index < 0 || $index > $max_index) {
        throw new \OutOfBoundsException('index out of bounds');
      }
      $items[$index]->before([
        $item,
        Token::comma(),
        Token::space(),
      ]);
    }
    return $this;
  }
public function insertItem(Node $item, $index) {
    $items = $this->getItems();
    if ($items->isEmpty()) {
      if ($index !== 0) {
        throw new \OutOfBoundsException('index out of bounds');
      }
      $this->append($item);
    }
    else {
      $max_index = count($items) - 1;
      if ($index < 0 || $index > $max_index) {
        throw new \OutOfBoundsException('index out of bounds');
      }
      $items[$index]->before([
        $item,
        Token::comma(),
        Token::space(),
      ]);
    }
    return $this;
  }
public function insertItem ( Node $ item , $ index ) { $ items = $ this -> getItems ( ) ; if ( $ items -> isEmpty ( ) ) { if ( $ index !== 0 ) { throw new \ OutOfBoundsException ( 'index out of bounds' ) ; } $ this -> append ( $ item ) ; } else { $ max_index = count ( $ items ) - 1 ; if ( $ index < 0 || $ index > $ max_index ) { throw new \ OutOfBoundsException ( 'index out of bounds' ) ; } $ items [ $ index ] -> before ( [ $ item , Token :: comma ( ) , Token :: space ( ) , ] ) ; } return $ this ; }
Insert item before index.

@param Node $item
@param int $index
@throws \OutOfBoundsException
Index out of bounds.
@return $this
Insert item before index .