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

ExamAdd::postAddAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
3
namespace Egzaminer\Exam;
4
5
use Egzaminer\Admin\Dashboard as Controller;
6
7
class ExamAdd extends Controller
8
{
9
    public function addAction()
10
    {
11
        $this->render('admin-exam-add', [
12
            'title' => 'Dodawanie testu',
13
        ]);
14
    }
15
16
    public function postAddAction()
0 ignored issues
show
Coding Style introduced by
postAddAction 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...
17
    {
18
        $model = new ExamAddModel($this->get('dbh'));
19
20
        if ($id = $model->add($_POST)) {
21
            $this->redirectWithMessage('/admin/test/edit/'.$id, 'success', 'Dodano pomyślnie');
22
        } else {
23
            $this->redirectWithMessage('/admin/test/add', 'warning', 'Coś się zepsuło');
24
        }
25
    }
26
}
27