ExamModel::getInfo()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 3
nc 4
nop 1
1
<?php
2
3
namespace Egzaminer\Model;
4
5
use PDO;
6
7
class ExamModel extends AbstractModel
8
{
9
    public function getInfo(int $examID): array
10
    {
11
        $stmt = $this->db->prepare('SELECT id, title, questions, threshold, group_id
12
            FROM exams WHERE id = :id');
13
        $stmt->bindValue(':id', $examID, PDO::PARAM_INT);
14
        $stmt->execute();
15
16
        $data = $stmt->fetch(PDO::FETCH_ASSOC);
17
18
        if ($data['questions'] > 0) {
19
            $data['thresholdPercentages'] = round($data['threshold'] / $data['questions'] * 100);
20
        }
21
22
        if (empty($data)) {
23
            $data = [];
24
        }
25
26
        return $data;
27
    }
28
}
29