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

ValidationContext   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 60
ccs 24
cts 24
cp 1
rs 10
c 1
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getParams() 0 3 1
A withAttribute() 0 5 1
A withPreviousRulesErrored() 0 5 1
A isPreviousRulesErrored() 0 3 1
A withParams() 0 5 1
A getAttribute() 0 3 1
A __construct() 0 6 1
A getDataSet() 0 3 1
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