Passed
Pull Request — master (#108)
by Sergei
02:14
created

ValidationContext   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 47
ccs 18
cts 18
cp 1
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A withAttribute() 0 5 1
A withPreviousRulesErrored() 0 5 1
A isPreviousRulesErrored() 0 3 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
13 18
    public function __construct(
14
        ?DataSetInterface $dataSet = null,
15
        ?string $attribute = null
16
    ) {
17 18
        $this->dataSet = $dataSet;
18 18
        $this->attribute = $attribute;
19 18
    }
20
21
    /**
22
     * @return DataSetInterface|null Optional data set.
23
     */
24 4
    public function getDataSet(): ?DataSetInterface
25
    {
26 4
        return $this->dataSet;
27
    }
28
29 4
    public function getAttribute(): ?string
30
    {
31 4
        return $this->attribute;
32
    }
33
34 4
    public function withAttribute(?string $attribute): self
35
    {
36 4
        $new = clone $this;
37 4
        $new->attribute = $attribute;
38 4
        return $new;
39
    }
40
41
    /**
42
     * @return bool set to true if rule is part of a group of rules and one of the previous validations failed
43
     */
44 18
    public function isPreviousRulesErrored(): bool
45
    {
46 18
        return $this->previousRulesErrored;
47
    }
48
49 16
    public function withPreviousRulesErrored(bool $previousRulesErrored): self
50
    {
51 16
        $new = clone $this;
52 16
        $new->previousRulesErrored = $previousRulesErrored;
53 16
        return $new;
54
    }
55
}
56