Permalink
Browse files

Change User Entity construction

  • Loading branch information...
1 parent 779eb8a commit 5ca7cecb1062dda0a406cd86677b791610a3a8aa @AlexKupreev committed Jun 9, 2014
Showing with 65 additions and 26 deletions.
  1. +46 −9 app/entity/User.php
  2. +6 −6 app/mock/repository/User.php
  3. +6 −3 app/repository/UserInterface.php
  4. +7 −8 features/bootstrap/FeatureContext.php
View
@@ -4,16 +4,53 @@
class User
{
- public $id;
- public $login;
- public $password;
- public $email;
+ /**
+ *
+ * @var int $id
+ */
+ protected $id;
- public function __construct($data)
+ /**
+ *
+ * @var string $login
+ */
+ protected $login;
+
+ /**
+ * Hashed password
+ * @var string $password
+ */
+ protected $password;
+
+ /**
+ *
+ * @var string $email
+ */
+ protected $email;
+
+ public function __construct($id, $login, $password, $email)
+ {
+ $this->id = (int)$id;
+ $this->login = (string)$login;
+ $this->password = (string)$password;
+ $this->email = (string)$email;
+ }
+
+ /**
+ * Returns user ID
+ * @return int
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Returns user login
+ * @return string
+ */
+ public function getLogin()
{
- $this->id = (int)$data['id'];
- $this->login = $data['login'];
- $this->password = $data['password'];
- $this->email = $data['email'];
+ return $this->login;
}
}
@@ -18,13 +18,13 @@ class User implements Repo\UserInterface
* @param array $data
* @return Entity\User
*/
- public function create(array $data)
+ public function create($id, $login, $password, $email)
{
- if (empty($data['id']) or ! $this->isFreeId($data['id'])) {
- $data['id'] = $this->getUniqId();
+ if (empty($id) or ! $this->isFreeId($id)) {
+ $id = $this->getUniqId();
}
- $user = new Entity\User($data);
- $this->storage[$user->id] = $user;
+ $user = new Entity\User($id, $login, $password, $email);
+ $this->storage[$user->getId()] = $user;
return $user;
}
@@ -41,7 +41,7 @@ public function getByLogin($login)
}
foreach ($this->storage as $user) {
- if (strcasecmp($user->login, $login) == 0) {
+ if (strcasecmp($user->getLogin(), $login) == 0) {
return $user;
}
}
@@ -5,10 +5,13 @@
interface UserInterface
{
/**
- * Creates a user from a data array
- * @param array $data
+ * Creates a User Entity
+ * @param int $id
+ * @param string $login
+ * @param string $password
+ * @param string $email
*/
- public function create(array $data);
+ public function create($id, $login, $password, $email);
/**
* Gets User Entity by id
@@ -59,13 +59,12 @@ public function followingUsers(TableNode $table)
$hash = $table->getHash();
foreach ($hash as $row) {
- $data = [
- 'id' => $row['id'],
- 'login' => $row['login'],
- 'password' => $this->passwordService->hash($row['password']),
- 'email' => $row['email'],
- ];
- $this->userRepo->create($data);
+ $this->userRepo->create(
+ $row['id'],
+ $row['login'],
+ $this->passwordService->hash($row['password']),
+ $row['email']
+ );
}
}
@@ -80,7 +79,7 @@ public function iAmARegisteredUser($login)
throw new Exception('No user found');
}
- $this->sessionService->setLoggedInUserId($user->id);
+ $this->sessionService->setLoggedInUserId($user->getId());
}
/**

0 comments on commit 5ca7cec

Please sign in to comment.