Copy::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlow\Pipe;
5
6
use SlayerBirden\DataFlow\DataBagInterface;
7
use SlayerBirden\DataFlow\IdentificationTrait;
8
use SlayerBirden\DataFlow\PipeInterface;
9
10
class Copy implements PipeInterface
11
{
12
    use IdentificationTrait;
13
    /**
14
     * @var string
15
     */
16
    private $id;
17
    /**
18
     * @var string
19
     */
20
    private $from;
21
    /**
22
     * @var string
23
     */
24
    private $to;
25
26 1
    public function __construct(string $id, string $from, string $to)
27
    {
28 1
        $this->id = $id;
29 1
        $this->from = $from;
30 1
        $this->to = $to;
31 1
    }
32
33
    /**
34
     * Copy data from one key to another. Create if doesn't exist.
35
     *
36
     * @param DataBagInterface $dataBag
37
     * @return DataBagInterface
38
     */
39 1
    public function pass(DataBagInterface $dataBag): DataBagInterface
40
    {
41 1
        $from = $dataBag[$this->from] ?? null;
42 1
        $dataBag[$this->to] = $from;
43
44 1
        return $dataBag;
45
    }
46
}
47