Passed
Pull Request — master (#464)
by Sergei
11:05
created

ObjectWithDataSetAndRulesProvider::getSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\Support\Data;
6
7
use Yiisoft\Validator\DataSetInterface;
8
use Yiisoft\Validator\Rule\Equal;
9
use Yiisoft\Validator\Rule\Number;
10
use Yiisoft\Validator\Rule\Required;
11
use Yiisoft\Validator\RulesProviderInterface;
12
13
use function array_key_exists;
14
15
final class ObjectWithDataSetAndRulesProvider implements DataSetInterface, RulesProviderInterface
16
{
17
    #[Required]
18
    public string $name = '';
19
20
    #[Number(min: 21)]
21
    protected int $key1 = 17;
22
23
    #[Number(max: 100)]
24
    private int $key2 = 42;
0 ignored issues
show
introduced by
The private property $key2 is not used, and could be removed.
Loading history...
25
26
    public function getRules(): iterable
27
    {
28
        return [
29
            'key1' => [new Required()],
30
            'key2' => [new Required(), new Equal(99)],
31
        ];
32
    }
33
34
    public function getAttributeValue(string $attribute): mixed
35
    {
36
        return $this->getObjectData()[$attribute] ?? null;
37
    }
38
39
    public function getData(): ?array
40
    {
41
        return $this->getObjectData();
42
    }
43
44
    public function getSource(): self
45
    {
46
        return $this;
47
    }
48
49
    public function hasAttribute(string $attribute): bool
50
    {
51
        return array_key_exists($attribute, $this->getObjectData());
52
    }
53
54
    private function getObjectData(): array
55
    {
56
        return ['key1' => 7, 'key2' => 42];
57
    }
58
}
59