ExamEditController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 29.27 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 12
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A editAction() 0 11 1
A postEditAction() 12 12 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\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