Delete::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 4
cts 4
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 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