Passed
Pull Request — master (#361)
by Alexander
02:53
created

Promotion::getTableName()   A

Complexity

Conditions 1
Paths 1

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 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Tests\Driver\Pgsql\Stubs;
6
7
use Yiisoft\ActiveRecord\ActiveQueryInterface;
8
use Yiisoft\ActiveRecord\ActiveRecord;
9
10
final class Promotion extends ActiveRecord
11
{
12
    public int $id;
13
    /** @var int[] $item_ids */
14
    public array $item_ids;
15
    public string $title;
16
17
    public function getTableName(): string
18
    {
19
        return '{{%promotion}}';
20
    }
21
22
    public function relationQuery(string $name): ActiveQueryInterface
23
    {
24
        return match ($name) {
25
            'items' => $this->hasMany(Item::class, ['id' => 'item_ids'])->inverseOf('promotions'),
26
            default => parent::relationQuery($name),
27
        };
28
    }
29
30
    /** @return Item[] */
31
    public function getItems(): array
32
    {
33
        return $this->relation('items');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->relation('items') could return the type Yiisoft\ActiveRecord\ActiveRecordInterface|null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
34
    }
35
}
36