Completed
Push — master ( 35046b...d215ab )
by Mikołaj
03:13
created

ExamEdit::editAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 11
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace Egzaminer\Exam;
4
5
use Egzaminer\Admin\Dashboard as Controller;
6
use Egzaminer\Question\Questions;
7
8
class ExamEdit extends Controller
9
{
10
    public function editAction($examID)
11
    {
12
        $exam = (new ExamModel($this->get('dbh')))->getInfo($examID);
13
        $questions = (new Questions($this->get('dbh')))->getByExamId($examID);
14
15
        $this->render('admin-exam-edit', [
16
            'title'     => 'Edycja testu',
17
            'exam'      => $exam,
18
            'questions' => $questions,
19
        ]);
20
    }
21
22
    public function postEditAction($examID)
0 ignored issues
show
Coding Style introduced by
postEditAction uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
23
    {
24
        $editModel = new ExamEditModel($this->get('dbh'));
25
26
        if ($editModel->edit($examID, $_POST)) {
27
            $this->redirectWithMessage('/admin/test/edit/'.$examID, 'success', 'Uaktualniono pomyślnie!');
28
        } else {
29
            $this->redirectWithMessage('/admin/test/edit/'.$examID, 'warning', 'Coś się zepsuło!');
30
        }
31
    }
32
}
33