| Total Complexity | 7 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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'); |
||
|
|
|||
| 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'); |
||
| 58 | } |
||
| 59 | |||
| 60 | public function getDossierQuery(): ActiveQuery |
||
| 69 | } |
||
| 70 | } |
||
| 71 |