Passed
Pull Request — master (#62)
by Sergei
12:01
created

ReplaceValue::apply()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Arrays\Collection\Modifier;
6
7
final class ReplaceValue implements DataModifierInterface
8
{
9
    private $key = null;
10
    private $value = null;
11
12
    public function apply(array $data): array
13
    {
14
        if ($this->key !== null) {
15
            $data[$this->key] = $this->value;
16
        }
17
        return $data;
18
    }
19
20
    public function forKey($key): self
21
    {
22
        $new = clone $this;
23
        $new->key = $key;
24
        return $new;
25
    }
26
27
    public function toValue($value): self
28
    {
29
        $new = clone $this;
30
        $new->value = $value;
31
        return $new;
32
    }
33
}
34