ExamEditController::postEditAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Egzaminer\Controller;
4
5
use Egzaminer\Model\ExamEditModel;
6
use Egzaminer\Model\ExamModel;
7
use Egzaminer\Model\QuestionsModel;
8
9
class ExamEditController extends AdminController
10
{
11
    /**
12
     * Edit exam action.
13
     *
14
     * GET /admin/exam/edit/[i:id]
15
     *
16
     * @return string
17
     */
18
    public function editAction(int $examID): string
19
    {
20
        $exam = (new ExamModel($this->get('dbh')))->getInfo($examID);
21
        $questions = (new QuestionsModel($this->get('dbh')))->getByExamId($examID);
22
23
        return $this->render('admin/exam/edit', [
24
            'title'     => 'Edycja testu',
25
            'exam'      => $exam,
26
            'questions' => $questions,
27
        ]);
28
    }
29
30
    /**
31
     * Edit exam post action.
32
     *
33
     * POST /admin/exam/edit/[i:id]
34
     *
35
     * @return void
36
     */
37 View Code Duplication
    public function postEditAction(int $examID)
0 ignored issues
show
Duplication introduced by
This method 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...
38
    {
39
        $editModel = new ExamEditModel($this->get('dbh'));
40
41
        if ($editModel->edit($examID, $this->getFromRequest('post'))) {
42
            $this->setMessage('success', 'Uaktualniono pomyślnie!');
43
        } else {
44
            $this->setMessage('warning', 'Coś się zepsuło!');
45
        }
46
47
        $this->redirect('/admin/exam/edit/'.$examID);
48
    }
49
}
50