|
3 | 3 |
|
4 | 4 | use ProspectOne\UserModule\Entity\Role; |
5 | 5 | use ProspectOne\UserModule\Entity\User; |
| 6 | +use ProspectOne\UserModule\Interfaces\UserInterface; |
6 | 7 | use Zend\Crypt\Password\Bcrypt; |
7 | 8 | use Zend\Math\Rand; |
8 | 9 | use Doctrine\ORM\EntityManager; |
@@ -98,28 +99,32 @@ public function addUser($data) |
98 | 99 |
|
99 | 100 | /** |
100 | 101 | * This method updates data of an existing user. |
101 | | - * @param User $user |
| 102 | + * @param UserInterface $user |
102 | 103 | * @param $data |
103 | 104 | * @return bool |
104 | 105 | * @throws \Exception |
105 | 106 | */ |
106 | | - public function updateUser(User $user, $data) |
| 107 | + public function updateUser(UserInterface $user, $data) |
107 | 108 | { |
108 | 109 | // Do not allow to change user email if another user with such email already exits. |
109 | 110 | if($user->getEmail()!=$data['email'] && $this->checkUserExists($data['email'])) { |
110 | 111 | throw new \Exception("Another user with email address " . $data['email'] . " already exists"); |
111 | 112 | } |
112 | | - |
| 113 | + |
| 114 | + if (!($user instanceof User)) { |
| 115 | + throw new \LogicException("Only instances of " . User::class . " should be passed"); |
| 116 | + } |
| 117 | + |
113 | 118 | $user->setEmail($data['email']); |
114 | | - $user->setFullName($data['full_name']); |
| 119 | + $user->setFullName($data['full_name']); |
115 | 120 | $user->setStatus($data['status']); |
116 | 121 |
|
117 | 122 | // Get role object based on role Id from form |
118 | 123 | /** @var Role $role */ |
119 | 124 | $role = $this->entityManager->find(Role::class, $data['role']); |
120 | 125 | // Set role to user |
121 | 126 | $user->addRole($role); |
122 | | - |
| 127 | + |
123 | 128 | // Apply changes to database. |
124 | 129 | $this->entityManager->flush(); |
125 | 130 |
|
|
0 commit comments