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