Completed
Push — master ( cceadc...3df73a )
by Mikołaj
04:41
created

DelController::del()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
namespace Rudolf\Modules\Users\One\Admin\Profile;
4
5
use Rudolf\Component\Alerts\Alert;
6
use Rudolf\Component\Alerts\AlertsCollection;
7
use Rudolf\Framework\Controller\AdminController;
8
9
class DelController extends AdminController
10
{
11
    /**
12
     * @param $id
13
     *
14
     * @throws \Exception
15
     */
16
    public function del($id)
0 ignored issues
show
Coding Style introduced by
del 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
        if (isset($_POST['delete'])) {
19
            if ((new DelModel())->del($id)) {
20
                AlertsCollection::add(new Alert(
21
                    'success',
22
                    'Poprawnie usunięto użytkownika'
23
                ));
24
                $this->redirect(DIR.'/admin/users');
25
            } else {
26
                AlertsCollection::add(new Alert(
27
                    'error',
28
                    'Wystąpił nieoczekiwany błąd'
29
                ));
30
            }
31
        }
32
33
        $view = new DelView();
34
        $view->display((new EditModel())->getUserInfoById($id));
35
        $view->render();
36
    }
37
}
38