Item::getName()   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
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
/**
12
 * Class Item.
13
 */
14
final class Item extends ActiveRecord
15
{
16
    protected int $id;
17
    protected string $name;
18
    protected int $category_id;
19
20
    public function getTableName(): string
21
    {
22
        return 'item';
23
    }
24
25
    public function relationQuery(string $name): ActiveQueryInterface
26
    {
27
        return match ($name) {
28
            'category' => $this->getCategoryQuery(),
29
            default => parent::relationQuery($name),
30
        };
31
    }
32
33
    public function getId(): int
34
    {
35
        return $this->id;
36
    }
37
38
    public function getName(): string
39
    {
40
        return $this->name;
41
    }
42
43
    public function getCategoryId(): int
44
    {
45
        return $this->category_id;
46
    }
47
48
    public function getCategory(): Category
49
    {
50
        return $this->relation('category');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->relation('category') returns the type array|null which is incompatible with the type-hinted return Yiisoft\ActiveRecord\Tes...s\ActiveRecord\Category.
Loading history...
51
    }
52
53
    public function getCategoryQuery(): ActiveQuery
54
    {
55
        return $this->hasOne(Category::class, ['id' => 'category_id']);
56
    }
57
}
58