Passed
Pull Request — master (#102)
by Sergei
02:09 queued 15s
created

ValidationContext::getParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
final class ValidationContext
8
{
9
    private ?DataSetInterface $dataSet;
10
    private ?string $attribute = null;
11
    private bool $previousRulesErrored = false;
12
    private array $params = [];
13
14 15
    public function __construct(
15
        ?DataSetInterface $dataSet = null,
16
        ?string $attribute = null
17
    ) {
18 15
        $this->dataSet = $dataSet;
19 15
        $this->attribute = $attribute;
20 15
    }
21
22
    /**
23
     * @return DataSetInterface|null Optional data set.
24
     */
25 1
    public function getDataSet(): ?DataSetInterface
26
    {
27 1
        return $this->dataSet;
28
    }
29
30 1
    public function getAttribute(): ?string
31
    {
32 1
        return $this->attribute;
33
    }
34
35 2
    public function withAttribute(?string $attribute): self
36
    {
37 2
        $new = clone $this;
38 2
        $new->attribute = $attribute;
39 2
        return $new;
40
    }
41
42
    /**
43
     * @return bool set to true if rule is part of a group of rules and one of the previous validations failed
44
     */
45 11
    public function isPreviousRulesErrored(): bool
46
    {
47 11
        return $this->previousRulesErrored;
48
    }
49
50 12
    public function withPreviousRulesErrored(bool $previousRulesErrored): self
51
    {
52 12
        $new = clone $this;
53 12
        $new->previousRulesErrored = $previousRulesErrored;
54 12
        return $new;
55
    }
56
57 1
    public function getParams(): array
58
    {
59 1
        return $this->params;
60
    }
61
62 2
    public function withParams(array $params): self
63
    {
64 2
        $new = clone $this;
65 2
        $new->params = $params;
66 2
        return $new;
67
    }
68
}
69