Delete   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 35
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A pass() 0 10 3
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 Delete implements PipeInterface
11
{
12
    use IdentificationTrait;
13
    /**
14
     * @var string
15
     */
16
    private $id;
17
    /**
18
     * @var string[]
19
     */
20
    private $fieldNames;
21
22 3
    public function __construct(string $id, string ...$fieldNames)
23
    {
24 3
        $this->id = $id;
25 3
        $this->fieldNames = $fieldNames;
26 3
    }
27
28
    /**
29
     * Delete data from the bag by key[s]
30
     *
31
     * @param DataBagInterface $dataBag
32
     * @return DataBagInterface
33
     */
34 2
    public function pass(DataBagInterface $dataBag): DataBagInterface
35
    {
36 2
        foreach ($this->fieldNames as $name) {
37 2
            if (isset($dataBag[$name])) {
38 2
                unset($dataBag[$name]);
39
            }
40
        }
41
42 2
        return $dataBag;
43
    }
44
}
45