ExamDeleteController::deleteAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

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