Passed
Pull Request — master (#322)
by
unknown
02:36
created

ArrayDataSet::getAttributeValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\DataSet;
6
7
use Yiisoft\Validator\DataSetInterface;
8
9
use function array_key_exists;
10
11
final class ArrayDataSet implements DataSetInterface
12
{
13 581
    public function __construct(private array $data = [])
14
    {
15
    }
16
17 51
    public function getAttributeValue(string $attribute): mixed
18
    {
19 51
        return $this->hasAttribute($attribute) ? $this->data[$attribute] : null;
20
    }
21
22 11
    public function getData(): array
23
    {
24 11
        return $this->data;
25
    }
26
27 62
    public function hasAttribute(string $attribute): bool
28
    {
29 62
        return array_key_exists($attribute, $this->data);
30
    }
31
}
32