Stratadox /
ImmutableCollection
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Stratadox\ImmutableCollection; |
||
| 6 | |||
| 7 | use function array_merge; |
||
| 8 | use Stratadox\Collection\Collection; |
||
| 9 | use Stratadox\Collection\Mergeable; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Behaviour to allow "merging" the immutable collection. |
||
| 13 | * |
||
| 14 | * Provides access to merging behaviour in the form of a method that |
||
| 15 | * returns a modified copy of the original (immutable) collection. |
||
| 16 | * |
||
| 17 | * @package Stratadox\Collection |
||
| 18 | * @author Stratadox |
||
| 19 | */ |
||
| 20 | trait Merging |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @see Mergeable::merge() |
||
| 24 | * @param Collection $other |
||
| 25 | * @return static |
||
| 26 | */ |
||
| 27 | public function merge(Collection $other) |
||
| 28 | { |
||
| 29 | return $this->newCopy(array_merge($this->items(), $other->items())); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 30 | } |
||
| 31 | |||
| 32 | /** @see Collection::items() */ |
||
| 33 | abstract public function items(): array; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @see ImmutableCollection::newCopy() |
||
| 37 | * @param array $items |
||
| 38 | * @return Collection|static |
||
| 39 | */ |
||
| 40 | abstract protected function newCopy(array $items): Collection; |
||
| 41 | } |
||
| 42 |