Joiner::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Uvinum\Joiner;
4
5
use Uvinum\Joiner\Manipulator\Manipulator;
6
use Uvinum\Joiner\Serializer\Serializer;
7
8
final class Joiner
9
{
10
    /** @var Serializer */
11
    private $serializer;
12
13
    /** @var Manipulator */
14
    private $manipulator;
15
16
    private $base;
17
18 15
    public function __construct(Serializer $serializer, Manipulator $manipulator)
19
    {
20 15
        $this->serializer  = $serializer;
21 15
        $this->manipulator = $manipulator;
22 15
        $this->base        = null;
23 15
    }
24
25 15
    public function join($arg)
26
    {
27 15
        $this->base = $arg;
28
29 15
        return $this;
30
    }
31
32 12
    public function append($key, $arg)
33
    {
34 12
        $serializedArg = $this->serializer->serialize($arg);
35 12
        $this->manipulator->append($key, $serializedArg);
36
37 12
        return $this;
38
    }
39
40
    public function filter(... $key)
41
    {
42 3
        array_map(function ($key_to_remove) {
43 3
            $this->manipulator->filter($key_to_remove);
44 3
        }, $key);
45
46 3
        return $this;
47
    }
48
49 15
    public function execute()
50
    {
51 15
        $serializedBase = $this->serializer->serialize($this->base);
52 15
        $this->base     = null;
53
54 15
        return $this->manipulator->process($serializedBase);
55
    }
56
}
57