Completed
Push — master ( 928248...a75adc )
by Wilmer
14s queued 11s
created

Employee::getDepartment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
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\ActiveRecord;
9
10
/**
11
 * Class Employee
12
 *
13
 * @property int $id
14
 * @property int $department_id
15
 * @property string $first_name
16
 * @property string $last_name
17
 *
18
 * @property string $fullName
19
 * @property Department $department
20
 * @property Dossier $dossier
21
 */
22
class Employee extends ActiveRecord
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public static function tableName(): string
28
    {
29
        return 'employee';
30
    }
31
32
    /**
33
     * Returns employee full name.
34
     *
35
     * @return string
36
     */
37
    public function getFullName(): string
38
    {
39
        return $this->first_name . ' ' . $this->last_name;
40
    }
41
42
    /**
43
     * Returns employee department.
44
     *
45
     * @return ActiveQuery
46
     */
47
    public function getDepartment(): ActiveQuery
48
    {
49
        return $this
50
            ->hasOne(Department::class, [
51
                'id' => 'department_id',
52
            ])
53
            ->inverseOf('employees')
54
        ;
55
    }
56
57
    /**
58
     * Returns employee department.
59
     *
60
     * @return ActiveQuery
61
     */
62
    public function getDossier(): ActiveQuery
63
    {
64
        return $this
65
            ->hasOne(Dossier::class, [
66
                'department_id' => 'department_id',
67
                'employee_id' => 'id',
68
            ])
69
            ->inverseOf('employee')
70
        ;
71
    }
72
}
73