Passed
Pull Request — master (#102)
by Sergei
01:57
created

ValidationContext   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 55
ccs 19
cts 19
cp 1
rs 10
c 1
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setParam() 0 3 1
A getParams() 0 3 1
A withAttribute() 0 5 1
A getParam() 0 3 1
A getAttribute() 0 3 1
A __construct() 0 8 1
A getDataSet() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
use Yiisoft\Arrays\ArrayHelper;
8
9
final class ValidationContext
10
{
11
    private ?DataSetInterface $dataSet;
12
    private ?string $attribute = null;
13
    private array $params = [];
14
15 15
    public function __construct(
16
        ?DataSetInterface $dataSet = null,
17
        ?string $attribute = null,
18
        array $params = []
19
    ) {
20 15
        $this->dataSet = $dataSet;
21 15
        $this->attribute = $attribute;
22 15
        $this->params = $params;
23 15
    }
24
25
    /**
26
     * @return DataSetInterface|null Optional data set.
27
     */
28 2
    public function getDataSet(): ?DataSetInterface
29
    {
30 2
        return $this->dataSet;
31
    }
32
33 3
    public function getAttribute(): ?string
34
    {
35 3
        return $this->attribute;
36
    }
37
38 2
    public function withAttribute(?string $attribute): self
39
    {
40 2
        $new = clone $this;
41 2
        $new->attribute = $attribute;
42 2
        return $new;
43
    }
44
45 3
    public function getParams(): array
46
    {
47 3
        return $this->params;
48
    }
49
50
    /**
51
     * @param string $key
52
     * @param mixed $default
53
     *
54
     * @return mixed
55
     */
56 11
    public function getParam(string $key, $default = null)
57
    {
58 11
        return ArrayHelper::getValue($this->params, $key, $default);
59
    }
60
61 11
    public function setParam(string $key, $value): void
62
    {
63 11
        $this->params[$key] = $value;
64 11
    }
65
}
66