Skip to content

Commit 9bb86ae

Browse files
committed
User -> UserInterface
1 parent cac0231 commit 9bb86ae

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/Service/UserManager.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use ProspectOne\UserModule\Entity\Role;
55
use ProspectOne\UserModule\Entity\User;
6+
use ProspectOne\UserModule\Interfaces\UserInterface;
67
use Zend\Crypt\Password\Bcrypt;
78
use Zend\Math\Rand;
89
use Doctrine\ORM\EntityManager;
@@ -98,28 +99,32 @@ public function addUser($data)
9899

99100
/**
100101
* This method updates data of an existing user.
101-
* @param User $user
102+
* @param UserInterface $user
102103
* @param $data
103104
* @return bool
104105
* @throws \Exception
105106
*/
106-
public function updateUser(User $user, $data)
107+
public function updateUser(UserInterface $user, $data)
107108
{
108109
// Do not allow to change user email if another user with such email already exits.
109110
if($user->getEmail()!=$data['email'] && $this->checkUserExists($data['email'])) {
110111
throw new \Exception("Another user with email address " . $data['email'] . " already exists");
111112
}
112-
113+
114+
if (!($user instanceof User)) {
115+
throw new \LogicException("Only instances of " . User::class . " should be passed");
116+
}
117+
113118
$user->setEmail($data['email']);
114-
$user->setFullName($data['full_name']);
119+
$user->setFullName($data['full_name']);
115120
$user->setStatus($data['status']);
116121

117122
// Get role object based on role Id from form
118123
/** @var Role $role */
119124
$role = $this->entityManager->find(Role::class, $data['role']);
120125
// Set role to user
121126
$user->addRole($role);
122-
127+
123128
// Apply changes to database.
124129
$this->entityManager->flush();
125130

0 commit comments

Comments
 (0)