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

ReplaceValue   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 25
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A apply() 0 6 2
A toValue() 0 5 1
A forKey() 0 5 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