Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.00% |
24 / 25 |
|
92.86% |
13 / 14 |
CRAP | |
0.00% |
0 / 1 |
| Message | |
96.00% |
24 / 25 |
|
92.86% |
13 / 14 |
14 | |
0.00% |
0 / 1 |
| getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUserId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getEmail | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNumber | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMessage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUserId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setEmail | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setNumber | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setMessage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| exists | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
1.02 | |||
| save | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| setId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Models; |
| 3 | |
| 4 | class Message { |
| 5 | private $id; |
| 6 | private $userId; |
| 7 | private $name; |
| 8 | private $email; |
| 9 | private $number; |
| 10 | private $message; |
| 11 | |
| 12 | // Getters |
| 13 | public function getId() { return $this->id; } |
| 14 | public function getUserId() { return $this->userId; } |
| 15 | public function getName() { return $this->name; } |
| 16 | public function getEmail() { return $this->email; } |
| 17 | public function getNumber() { return $this->number; } |
| 18 | public function getMessage() { return $this->message; } |
| 19 | |
| 20 | // Setters |
| 21 | public function setUserId($userId) { $this->userId = $userId; } |
| 22 | public function setName($name) { $this->name = $name; } |
| 23 | public function setEmail($email) { $this->email = $email; } |
| 24 | public function setNumber($number) { $this->number = $number; } |
| 25 | public function setMessage($message) { $this->message = $message; } |
| 26 | |
| 27 | public function exists($conn) { |
| 28 | $sql = "SELECT id FROM message WHERE user_id = ? AND message = ?"; |
| 29 | $stmt = $conn->prepare($sql); |
| 30 | $stmt->execute([$this->userId, $this->message]); |
| 31 | return $stmt->rowCount() > 0; |
| 32 | } |
| 33 | |
| 34 | public function save($conn) { |
| 35 | $sql = "INSERT INTO message (user_id, name, email, number, message) VALUES (?, ?, ?, ?, ?)"; |
| 36 | $stmt = $conn->prepare($sql); |
| 37 | return $stmt->execute([ |
| 38 | $this->userId, |
| 39 | $this->name, |
| 40 | $this->email, |
| 41 | $this->number, |
| 42 | $this->message |
| 43 | ]); |
| 44 | } |
| 45 | |
| 46 | public function setId($id) { $this->id = $id; } |
| 47 | } |