Conditions | 2 |
Paths | 2 |
Total Lines | 16 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 2.0023 |
Changes | 0 |
1 | <?php |
||
34 | 4 | public function associate(Users $user, Companies $company): array |
|
35 | { |
||
36 | 4 | $class = str_replace('UsersAssociated\\', 'UsersAssociated', substr_replace(get_class($this), '\UsersAssociated', strrpos(get_class($this), '\\'), 0)); |
|
37 | 4 | $usersAssociatedModel = new $class(); |
|
38 | 4 | $usersAssociatedModel->users_id = $user->getId(); |
|
39 | 4 | $usersAssociatedModel->companies_id = $company->getId(); |
|
40 | 4 | $usersAssociatedModel->apps_id = $this->di->getApp()->getId(); |
|
41 | 4 | $usersAssociatedModel->identify_id = $user->getId(); |
|
42 | 4 | $usersAssociatedModel->user_active = 1; |
|
43 | 4 | $usersAssociatedModel->user_role = Roles::existsById((int)$user->roles_id)->name; |
|
44 | |||
45 | 4 | if (!$usersAssociatedModel->save()) { |
|
46 | throw new Exception((string)current($usersAssociatedModel->getMessages())); |
||
47 | } |
||
48 | |||
49 | 4 | return $usersAssociatedModel->toArray(); |
|
50 | } |
||
52 |