Merging::merge()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
The expression return $this->newCopy(ar...ms(), $other->items())) returns the type Stratadox\Collection\Collection which is incompatible with the documented return type Stratadox\ImmutableCollection\Merging.
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