Passed
Pull Request — master (#62)
by Sergei
05:53
created

UnsetValue::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Arrays\Collection\Modifier;
6
7
use Yiisoft\Arrays\Collection\Modifier\ModifierInterface\DataModifierInterface;
8
9
/**
10
 * Removes an array element with a given key.
11
 */
12
final class UnsetValue implements DataModifierInterface
13
{
14
    /**
15
     * @var int|string
16
     */
17
    private $key;
18
19
    /**
20
     * @param int|string $key
21
     */
22 8
    public function __construct($key)
23
    {
24 8
        $this->key = $key;
25 8
    }
26
27
    /**
28
     * @param int|string $key
29
     * @return self
30
     */
31 1
    public function withKey($key): self
32
    {
33 1
        $new = clone $this;
34 1
        $new->key = $key;
35 1
        return $new;
36
    }
37
38 6
    public function apply(array $data): array
39
    {
40 6
        unset($data[$this->key]);
41 6
        return $data;
42
    }
43
}
44