ObjectWithDataSet::hasAttribute()   A
last analyzed

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 1
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\Number;
9
use Yiisoft\Validator\Rule\Required;
10
11
use function array_key_exists;
12
13
final class ObjectWithDataSet implements DataSetInterface
14
{
15
    #[Required]
16
    public string $name = '';
17
18
    #[Number(min: 21)]
19
    protected int $age = 17;
20
21
    #[Number(max: 100)]
22
    private int $number = 42;
0 ignored issues
show
introduced by
The private property $number is not used, and could be removed.
Loading history...
23
24
    public function getAttributeValue(string $attribute): mixed
25
    {
26
        return $this->getData()[$attribute] ?? null;
27
    }
28
29
    public function getData(): ?array
30
    {
31
        return ['key1' => 7, 'key2' => 42];
32
    }
33
34
    public function hasAttribute(string $attribute): bool
35
    {
36
        return array_key_exists($attribute, $this->getData());
37
    }
38
}
39