Completed
Push — master ( ac011d...56c397 )
by Mikołaj
03:19
created

ExamAddModel::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 13
loc 13
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
3
namespace Egzaminer\Model;
4
5
use PDO;
6
7 View Code Duplication
class ExamAddModel extends AbstractModel
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    /**
10
     * Add exam.
11
     *
12
     * @param array $post
13
     *
14
     * @return int
15
     */
16
    public function add($post)
17
    {
18
        $stmt = $this->db->prepare('INSERT INTO exams (title, questions, threshold, group_id)
19
            VALUES (:title, :questions, :threshold, :group_id)'
20
        );
21
        $stmt->bindValue(':title', trim($post['title']), PDO::PARAM_STR);
22
        $stmt->bindValue(':questions', $post['questions'], PDO::PARAM_INT);
23
        $stmt->bindValue(':threshold', $post['threshold'], PDO::PARAM_INT);
24
        $stmt->bindValue(':group_id', $post['group_id'], PDO::PARAM_INT);
25
        $stmt->execute();
26
27
        return $this->db->lastInsertId();
28
    }
29
}
30