Passed
Push — master ( 2f6942...d6d802 )
by Chris
28:11
created

FusionSelection::collect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace WebTheory\Collection\Fusion\Collection;
4
5
use WebTheory\Collection\Access\StandardMap;
6
use WebTheory\Collection\Comparison\ObjectComparator;
7
use WebTheory\Collection\Contracts\ArrayDriverInterface;
8
use WebTheory\Collection\Contracts\ArrayFusionInterface;
9
10
class FusionSelection
11
{
12
    /**
13
     * @var array<string,ArrayFusionInterface>
14
     */
15
    protected array $fusions = [];
16
17
    protected ArrayDriverInterface $driver;
18
19 309
    public function __construct(array $fusions)
20
    {
21 309
        $this->driver = new StandardMap(new ObjectComparator());
22
23 309
        $this->collect($fusions);
24
    }
25
26 309
    public function collect(array $fusions)
27
    {
28 309
        array_walk($fusions, [$this, 'insert']);
29
    }
30
31 309
    public function insert(ArrayFusionInterface $fusion, string $name): void
32
    {
33 309
        $this->driver->insert($this->fusions, $fusion, $name);
34
    }
35
36
    public function remove(string $fusion): void
37
    {
38
        $this->driver->remove($this->fusions, $fusion);
39
    }
40
41 69
    public function fetch(string $fusion): ArrayFusionInterface
42
    {
43 69
        return $this->driver->fetch($this->fusions, $fusion);
44
    }
45
46
    public function contains(string $fusion): bool
47
    {
48
        return $this->driver->contains($this->fusions, $fusion);
49
    }
50
51
    public function remix(string $fusion, array ...$collections): array
52
    {
53
        return $this->fetch($fusion)->remix(...$collections);
54
    }
55
}
56