Passed
Pull Request — master (#62)
by Sergei
14:50
created

UnsetValue::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
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
 * Modifier "Unset Value".
11
 *
12
 * Удаляет элемент массива с заданым ключом.
13
 */
14
final class UnsetValue implements DataModifierInterface
15
{
16
    /**
17
     * @var int|string
18
     */
19
    private $key;
20
21
    /**
22
     * @param int|string $key
23
     */
24
    public function __construct($key)
25
    {
26
        $this->key = $key;
27
    }
28
29
    /**
30
     * @param int|string $key
31
     * @return self
32
     */
33
    public function withKey($key): self
34
    {
35
        $new = clone $this;
36
        $new->key = $key;
37
        return $new;
38
    }
39
40
    public function apply(array $data): array
41
    {
42
        unset($data[$this->key]);
43
        return $data;
44
    }
45
}
46