Passed
Pull Request — master (#351)
by
unknown
02:56
created

SingleValueDataSet   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 4
dl 0
loc 19
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasAttribute() 0 3 1
A getAttributeValue() 0 3 1
A __construct() 0 2 1
A getData() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\DataSet;
6
7
use BadMethodCallException;
8
use Yiisoft\Validator\DataSetInterface;
9
10
/**
11
 * Used for a single value of any (mixed) data type. Does not support attributes.
12
 */
13
final class SingleValueDataSet implements DataSetInterface
14
{
15 508
    public function __construct(private mixed $value)
16
    {
17
    }
18
19 3
    public function getAttributeValue(string $attribute): mixed
20
    {
21 3
        throw new BadMethodCallException('Single value data set does not support attributes.');
22
    }
23
24 507
    public function getData(): mixed
25
    {
26 507
        return $this->value;
27
    }
28
29 1
    public function hasAttribute(string $attribute): bool
30
    {
31 1
        throw new BadMethodCallException('Single value data set does not support attributes.');
32
    }
33
}
34