Map   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A pass() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlow\Pipe;
5
6
use SlayerBirden\DataFlow\DataBagInterface;
7
use SlayerBirden\DataFlow\PipeInterface;
8
use SlayerBirden\DataFlow\IdentificationTrait;
9
10
class Map implements PipeInterface
11
{
12
    use IdentificationTrait;
13
    /**
14
     * @var string
15
     */
16
    private $field;
17
    /**
18
     * @var MapperCallbackInterface
19
     */
20
    private $callback;
21
    /**
22
     * @var string
23
     */
24
    private $identifier;
25
26 4
    public function __construct(string $identifier, string $field, MapperCallbackInterface $callback)
27
    {
28 4
        $this->identifier = $identifier;
29 4
        $this->field = $field;
30 4
        $this->callback = $callback;
31 4
    }
32
33
    /**
34
     * Mapping handler.
35
     * Proceeds to transform an entry to a new value using callback function.
36
     *
37
     * {@inheritdoc}
38
     */
39 3
    public function pass(DataBagInterface $dataBag): DataBagInterface
40
    {
41 3
        $dataBag[$this->field] = ($this->callback)($dataBag[$this->field] ?? null, $dataBag);
42
43 3
        return $dataBag;
44
    }
45
}
46