Beta::getTableName()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord;
6
7
use Yiisoft\ActiveRecord\ActiveQuery;
8
use Yiisoft\ActiveRecord\ActiveQueryInterface;
9
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord;
10
11
final class Beta extends ActiveRecord
12
{
13
    protected int $id;
14
    protected string $alpha_string_identifier;
15
    protected Alpha $alpha;
16
17
    public function getTableName(): string
18
    {
19
        return 'beta';
20
    }
21
22
    public function getId(): int
23
    {
24
        return $this->id;
25
    }
26
27
    public function getAlphaStringIdentifier(): string
28
    {
29
        return $this->alpha_string_identifier;
30
    }
31
32
    public function relationQuery(string $name): ActiveQueryInterface
33
    {
34
        return match ($name) {
35
            'alpha' => $this->getAlphaQuery(),
36
            default => parent::relationQuery($name),
37
        };
38
    }
39
40
    public function getAlpha(): Alpha|null
41
    {
42
        return $this->relation('alpha');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->relation('alpha') could return the type array which is incompatible with the type-hinted return Yiisoft\ActiveRecord\Tes...ActiveRecord\Alpha|null. Consider adding an additional type-check to rule them out.
Loading history...
43
    }
44
45
    public function getAlphaQuery(): ActiveQuery
46
    {
47
        return $this->hasOne(Alpha::class, ['string_identifier' => 'alpha_string_identifier']);
48
    }
49
}
50