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

Promotion   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 24
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTableName() 0 3 1
A relationQuery() 0 5 1
A getItems() 0 3 1
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