original_string: public function merge($collection)
      {
          if (!is_array($collection) && !($collection instanceof Traversable)) {
              throw new Exception\InvalidArgumentException(
                  sprintf(
                      'Expected argument "array" or "Traversable"; "%s" given',
                      gettype($collection) . (is_object($collection) ? '(' . get_class($collection) . ')' : '')
                  )
              );
          }
  
          foreach ($collection as $key => $value) {
              if ($this->has($key)) {
                  if (is_int($key)) {
                      $this->append($value);
                  } else {
                      if ($value instanceof CollectionInterface) {
                          $value = $value->toArray();
  
                          if ($this->collections[$key] instanceof CollectionInterface) {
                              $value = $this->collections[$key]->merge($value);
                          } else {
                              $value = new static($value);
                          }
                      }
  
                      $this->set($key, $value);
                  }
              } else {
                  if ($value instanceof CollectionInterface) {
                      $value = new static($value->toArray());
                  }
  
                  $this->set($key, $value);
              }
          }
  
          return $this;
      }
code: public function merge($collection)
      {
          if (!is_array($collection) && !($collection instanceof Traversable)) {
              throw new Exception\InvalidArgumentException(
                  sprintf(
                      'Expected argument "array" or "Traversable"; "%s" given',
                      gettype($collection) . (is_object($collection) ? '(' . get_class($collection) . ')' : '')
                  )
              );
          }
  
          foreach ($collection as $key => $value) {
              if ($this->has($key)) {
                  if (is_int($key)) {
                      $this->append($value);
                  } else {
                      if ($value instanceof CollectionInterface) {
                          $value = $value->toArray();
  
                          if ($this->collections[$key] instanceof CollectionInterface) {
                              $value = $this->collections[$key]->merge($value);
                          } else {
                              $value = new static($value);
                          }
                      }
  
                      $this->set($key, $value);
                  }
              } else {
                  if ($value instanceof CollectionInterface) {
                      $value = new static($value->toArray());
                  }
  
                  $this->set($key, $value);
              }
          }
  
          return $this;
      }
code_tokens: public function merge ( $ collection ) { if ( ! is_array ( $ collection ) && ! ( $ collection instanceof Traversable ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'Expected argument "array" or "Traversable"; "%s" given' , gettype ( $ collection ) . ( is_object ( $ collection ) ? '(' . get_class ( $ collection ) . ')' : '' ) ) ) ; } foreach ( $ collection as $ key => $ value ) { if ( $ this -> has ( $ key ) ) { if ( is_int ( $ key ) ) { $ this -> append ( $ value ) ; } else { if ( $ value instanceof CollectionInterface ) { $ value = $ value -> toArray ( ) ; if ( $ this -> collections [ $ key ] instanceof CollectionInterface ) { $ value = $ this -> collections [ $ key ] -> merge ( $ value ) ; } else { $ value = new static ( $ value ) ; } } $ this -> set ( $ key , $ value ) ; } } else { if ( $ value instanceof CollectionInterface ) { $ value = new static ( $ value -> toArray ( ) ) ; } $ this -> set ( $ key , $ value ) ; } } return $ this ; }
docstring: Merge another Collection with this one.
  
  For duplicate keys, the following will be performed:
  - Nested Configs will be recursively merged.
  - Items in $merge with INTEGER keys will be appended.
  - Items in $merge with STRING keys will overwrite current values.
  
  @param array|Traversable $collection
  
  @return $this
  @throws \Xloit\Collection\Exception\InvalidArgumentException
  @throws \Zend\Stdlib\Exception\InvalidArgumentException
docstring_tokens: Merge another Collection with this one .