Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
20 / 20 |
| UserRepository | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
8 | |
100.00% |
20 / 20 |
| __construct(PersistentStorage $persistentStorage) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| save(User $user) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| getByEmail($email) | |
100.00% |
1 / 1 |
3 | |
100.00% |
8 / 8 |
|||
| getByCredentials($email, $password) | |
100.00% |
1 / 1 |
3 | |
100.00% |
8 / 8 |
|||
| <?php | |
| namespace Tdd; | |
| class UserRepository | |
| { | |
| /** @var PersistentStorage */ | |
| private $persistentStorage; | |
| public function __construct(PersistentStorage $persistentStorage) | |
| { | |
| $this->persistentStorage = $persistentStorage; | |
| } | |
| public function save(User $user) | |
| { | |
| $stmt = $this->persistentStorage->prepare('INSERT OR IGNORE INTO user (email, password, type) VALUES (?, ?, ?)'); | |
| return $stmt->execute(array($user->getEmail(), $user->getPassword(), $user->getType())); | |
| } | |
| public function getByEmail($email) | |
| { | |
| $stmt = $this->persistentStorage->prepare('SELECT * FROM user WHERE email = ? LIMIT 1'); | |
| if (!$stmt->execute(array($email))) | |
| { | |
| return null; // @codeCoverageIgnore | |
| } | |
| $row = $stmt->fetch(); | |
| if (!is_array($row)) | |
| { | |
| return null; | |
| } | |
| return new User($row['email'], $row['password'], $row['type']); | |
| } | |
| public function getByCredentials($email, $password) | |
| { | |
| $stmt = $this->persistentStorage->prepare('SELECT * FROM user WHERE email = ? AND password = ? LIMIT 1'); | |
| if (!$stmt->execute(array($email, $password))) | |
| { | |
| return null; // @codeCoverageIgnore | |
| } | |
| $row = $stmt->fetch(); | |
| if (!is_array($row)) | |
| { | |
| return null; | |
| } | |
| return new User($row['email'], $row['password'], $row['type']); | |
| } | |
| } |