Department   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 31
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A relationQuery() 0 5 1
A getTableName() 0 3 1
A getEmployeesQuery() 0 8 1
A getEmployees() 0 3 1
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
use Yiisoft\ActiveRecord\ActiveRecordInterface;
11
12
/**
13
 * Class Department
14
 */
15
final class Department extends ActiveRecord
16
{
17
    protected int $id;
18
    protected string $title;
19
20
    public function getTableName(): string
21
    {
22
        return 'department';
23
    }
24
25
    public function relationQuery(string $name): ActiveQueryInterface
26
    {
27
        return match ($name) {
28
            'employees' => $this->getEmployeesQuery(),
29
            default => parent::relationQuery($name),
30
        };
31
    }
32
33
    public function getEmployees(): ActiveRecordInterface
34
    {
35
        return $this->relation('employees');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->relation('employees') could return the type array|null which is incompatible with the type-hinted return Yiisoft\ActiveRecord\ActiveRecordInterface. Consider adding an additional type-check to rule them out.
Loading history...
36
    }
37
38
    public function getEmployeesQuery(): ActiveQuery
39
    {
40
        return $this->hasMany(
41
            Employee::class,
42
            [
43
                'department_id' => 'id',
44
            ]
45
        )->inverseOf('department');
46
    }
47
}
48