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

ExamAdd   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 20
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addAction() 0 6 1
A postAddAction() 0 10 2
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