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

ValidationContext::getAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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 10
    public function __construct(
14
        ?DataSetInterface $dataSet = null,
15
        ?string $attribute = null
16
    ) {
17 10
        $this->dataSet = $dataSet;
18 10
        $this->attribute = $attribute;
19 10
    }
20
21
    /**
22
     * @return DataSetInterface|null Optional data set.
23
     */
24
    public function getDataSet(): ?DataSetInterface
25
    {
26
        return $this->dataSet;
27
    }
28
29
    public function getAttribute(): ?string
30
    {
31
        return $this->attribute;
32
    }
33
34
    public function withAttribute(?string $attribute): self
35
    {
36
        $new = clone $this;
37
        $new->attribute = $attribute;
38
        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 10
    public function isPreviousRulesErrored(): bool
45
    {
46 10
        return $this->previousRulesErrored;
47
    }
48
49 10
    public function withPreviousRulesErrored(bool $previousRulesErrored): self
50
    {
51 10
        $new = clone $this;
52 10
        $new->previousRulesErrored = $previousRulesErrored;
53 10
        return $new;
54
    }
55
}
56