Swap   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A pass() 0 9 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 Swap implements PipeInterface
11
{
12
    use IdentificationTrait;
13
    /**
14
     * @var string
15
     */
16
    private $id;
17
    /**
18
     * @var string
19
     */
20
    private $first;
21
    /**
22
     * @var string
23
     */
24
    private $second;
25
26
    public function __construct(string $id, string $first, string $second)
27
    {
28
        $this->id = $id;
29
        $this->first = $first;
30
        $this->second = $second;
31
    }
32
33
    /**
34
     * Swap one key with another.
35
     *
36
     * @param DataBagInterface $dataBag
37
     * @return DataBagInterface
38
     */
39
    public function pass(DataBagInterface $dataBag): DataBagInterface
40
    {
41
        $first = $dataBag[$this->first] ?? null;
42
        $second = $dataBag[$this->second] ?? null;
43
        $dataBag[$this->first] = $second;
44
        $dataBag[$this->second] = $first;
45
46
        return $dataBag;
47
    }
48
}
49