Passed
Pull Request — master (#278)
by Sergei
02:46
created

CustomerExtraAttributes::hasAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord;
6
7
use Yiisoft\ActiveRecord\ActiveRecord;
8
9
/**
10
 * Class CustomerClosureField.
11
 *
12
 * @property int $id
13
 * @property string $name
14
 * @property string $email
15
 * @property string $address
16
 * @property int $status
17
 * @property string $sex
18
 */
19
final class CustomerExtraAttributes extends ActiveRecord
20
{
21
    private array $extraAttributes = [
22
        'sex' => 'm',
23
    ];
24
25
    public function getTableName(): string
26
    {
27
        return 'customer';
28
    }
29
30
    public function getAttribute(string $name): mixed
31
    {
32
        if (array_key_exists($name, $this->extraAttributes)) {
33
            return $this->extraAttributes[$name];
34
        }
35
36
        return parent::getAttribute($name);
37
    }
38
39
    public function getAttributes(array $names = null, array $except = []): array
40
    {
41
        return array_merge(parent::getAttributes($names, $except), $this->extraAttributes);
42
    }
43
44
    public function hasAttribute($name): bool
45
    {
46
        return array_key_exists($name, $this->extraAttributes) || parent::hasAttribute($name);
47
    }
48
}
49