Completed
Push — master ( 35046b...d215ab )
by Mikołaj
03:13
created

QuestionEdit::postEditAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 2
1
<?php
2
3
namespace Egzaminer\Question;
4
5
use Egzaminer\Admin\Dashboard as Controller;
6
7
class QuestionEdit extends Controller
8
{
9
    public function editAction($testId, $id)
10
    {
11
        $question = (new Questions($this->get('dbh')))->getByQuestionId($id);
12
        $answers = (new Answers($this->get('dbh')))->getAnswersByOneQuestionId($id);
13
14
        $this->render('admin-question', [
15
            'title'        => 'Edycja pytania',
16
            'id'           => $id,
17
            'testId'       => $testId,
18
            'question'     => $question,
19
            'answers'      => $answers,
20
            'templateType' => 'edit',
21
        ]);
22
    }
23
24 View Code Duplication
    public function postEditAction($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...
Coding Style introduced by
postEditAction uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
25
    {
26
        $editModel = new QuestionEditModel($this->get('dbh'));
27
28
        if ($editModel->edit($questionID, $_POST)) {
29
            $this->redirectWithMessage(
30
                '/admin/test/edit/'.$examID.'/question/edit/'.$questionID,
31
                'success',
32
                'Uaktualniono pomyślnie!'
33
            );
34
        } else {
35
            $this->redirectWithMessage(
36
                '/admin/test/edit/'.$examID.'/question/edit/'.$questionID,
37
                'warning',
38
                'Coś się zepsuło!'
39
            );
40
        }
41
    }
42
}
43