Employee::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
/**
12
 * Class Employee
13
 */
14
final class Employee extends ActiveRecord
15
{
16
    protected int $id;
17
    protected int $department_id;
18
    protected string $first_name;
19
    protected string $last_name;
20
21
    public function getTableName(): string
22
    {
23
        return 'employee';
24
    }
25
26
    public function relationQuery(string $name): ActiveQueryInterface
27
    {
28
        return match ($name) {
29
            'department' => $this->getDepartmentQuery(),
30
            'dossier' => $this->getDossierQuery(),
31
            default => parent::relationQuery($name),
32
        };
33
    }
34
35
    public function getFullName(): string
36
    {
37
        return $this->first_name . ' ' . $this->last_name;
38
    }
39
40
    public function getDepartment(): Department
41
    {
42
        return $this->relation('department');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->relation('department') returns the type array|null which is incompatible with the type-hinted return Yiisoft\ActiveRecord\Tes...ActiveRecord\Department.
Loading history...
43
    }
44
45
    public function getDepartmentQuery(): ActiveQuery
46
    {
47
        return $this
48
            ->hasOne(Department::class, [
49
                'id' => 'department_id',
50
            ])
51
            ->inverseOf('employees')
52
        ;
53
    }
54
55
    public function getDossier(): Dossier
56
    {
57
        return $this->relation('dossier');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->relation('dossier') returns the type array|null which is incompatible with the type-hinted return Yiisoft\ActiveRecord\Tes...bs\ActiveRecord\Dossier.
Loading history...
58
    }
59
60
    public function getDossierQuery(): ActiveQuery
61
    {
62
        return $this->hasOne(
63
            Dossier::class,
64
            [
65
                'department_id' => 'department_id',
66
                'employee_id' => 'id',
67
            ]
68
        )->inverseOf('employee');
69
    }
70
}
71