| @@ 590-604 (lines=15) @@ | ||
| 587 | * |
|
| 588 | * @throws InvalidArgumentException |
|
| 589 | */ |
|
| 590 | public function merge( $elements ) { |
|
| 591 | if ( $elements instanceof static ) { |
|
| 592 | $elements = $elements->to_array(); |
|
| 593 | } |
|
| 594 | ||
| 595 | if ( ! is_array( $elements ) ) { |
|
| 596 | throw new InvalidArgumentException( 'Merge must be given array or Collection' ); |
|
| 597 | } |
|
| 598 | ||
| 599 | $this->type->validate_elements( $elements ); |
|
| 600 | ||
| 601 | return $this->new_from_trusted( |
|
| 602 | array_merge( $this->elements, $elements ) |
|
| 603 | ); |
|
| 604 | } |
|
| 605 | ||
| 606 | /** |
|
| 607 | * {@inheritdoc} |
|
| @@ 280-290 (lines=11) @@ | ||
| 277 | * |
|
| 278 | * @throws InvalidArgumentException |
|
| 279 | */ |
|
| 280 | public function merge( $source ) { |
|
| 281 | if ( $source instanceof self ) { |
|
| 282 | $source = $source->to_array(); |
|
| 283 | } |
|
| 284 | ||
| 285 | if ( ! is_array( $source ) ) { |
|
| 286 | throw new InvalidArgumentException( 'Combine must be a Dictionary or an array' ); |
|
| 287 | } |
|
| 288 | ||
| 289 | return new static( $this->get_key_type(), $this->get_value_type(), array_merge( $this->storage, $source ) ); |
|
| 290 | } |
|
| 291 | ||
| 292 | ||
| 293 | /** |
|