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

QuestionDeleteController::postDeleteAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 14
loc 14
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
3
namespace Egzaminer\Controller;
4
5
use Egzaminer\Model\QuestionDeleteModel;
6
use Egzaminer\Model\QuestionsModel;
7
8
class QuestionDeleteController extends AdminController
9
{
10
    /**
11
     * Delete question.
12
     *
13
     * GET /admin/exam/edit/[i:id]/question/del/[i:qid]
14
     *
15
     * @param int $examID
16
     * @param int $questionID
17
     *
18
     * @return void
19
     */
20 View Code Duplication
    public function deleteAction($examID, $questionID)
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...
21
    {
22
        $question = (new QuestionsModel($this->get('dbh')))->getByQuestionId($questionID);
23
24
        $this->render('admin/delete', [
25
            'title'   => 'Usuwanie pytania',
26
            'content' => 'Czy na pewno chcesz usunąć pytanie <i>'.$question['content'].'</i>?',
27
        ]);
28
    }
29
30
    /**
31
     * Delete question post action.
32
     *
33
     * POST /admin/exam/edit/[i:id]/question/del/[i:qid]
34
     *
35
     * @param int $examID
36
     * @param int $questionID
37
     *
38
     * @return void
39
     */
40 View Code Duplication
    public function postDeleteAction($examID, $questionID)
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...
41
    {
42
        $delModel = new QuestionDeleteModel($this->get('dbh'));
43
44
        if ($delModel->delete($questionID)) {
45
            $this->setMessage('success', 'Usunięto pomyślnie!');
46
            $this->redirect('/admin/exam/edit/'.$examID);
47
48
            return;
49
        }
50
51
        $this->setMessage('warning', 'Coś się zepsuło!');
52
        $this->redirect('/admin/exam/edit/'.$examID.'/question/del/'.$questionID);
53
    }
54
}
55