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

RulesProvidedDataSet   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 29
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getRules() 0 3 1
A getAttributeValue() 0 3 1
A getData() 0 3 1
A getSource() 0 3 1
A hasAttribute() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\Support\DataSet;
6
7
use Yiisoft\Validator\DataSetInterface;
8
use Yiisoft\Validator\RulesProviderInterface;
9
10
use function array_key_exists;
11
12
final class RulesProvidedDataSet implements RulesProviderInterface, DataSetInterface
13
{
14
    public function __construct(private array $data, private array $rules)
15
    {
16
    }
17
18
    public function getAttributeValue(string $attribute): mixed
19
    {
20
        return $this->data[$attribute] ?? null;
21
    }
22
23
    public function getRules(): iterable
24
    {
25
        return $this->rules;
26
    }
27
28
    public function getData(): ?array
29
    {
30
        return $this->data;
31
    }
32
33
    public function getSource(): array
34
    {
35
        return $this->data;
36
    }
37
38
    public function hasAttribute(string $attribute): bool
39
    {
40
        return array_key_exists($attribute, $this->data);
41
    }
42
}
43