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

QuestionDeleteController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 48.94 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 3
dl 23
loc 47
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteAction() 9 9 1
A postDeleteAction() 14 14 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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