Completed
Branch master (b4ab83)
by Mikołaj
03:16
created

DelController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 25
loc 25
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A del() 22 22 3

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 Rudolf\Modules\Galleries\One\Admin;
4
5
use Rudolf\Framework\Controller\AdminController;
6
use Rudolf\Modules\Galleries\One;
7
8 View Code Duplication
class DelController extends AdminController
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    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...
11
    {
12
        // if data was send
13
        if (isset($_POST['delete'])) {
14
            $form = new DelForm();
15
            $form->handle(['id' => $id]);
16
            $form->setModel(new DelModel());
17
18
            if ($form->isValid()) {
19
                $form->delete();
20
                $this->redirect(DIR.'/admin/galleries');
21
            }
22
23
            $form->dispalyAlerts();
24
        }
25
26
        $gallery = (new One\Model())->getGalleryInfoById($id);
27
28
        $view = new DelView();
29
        $view->delGallery($gallery);
30
        $view->render('admin');
31
    }
32
}
33