ItemEditController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 46.88 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
dl 15
loc 32
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 7

1 Method

Rating   Name   Duplication   Size   Complexity  
A edit() 15 24 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\Appearance\Menu\Item;
4
5
use Rudolf\Component\Alerts\Alert;
6
use Rudolf\Component\Alerts\AlertsCollection;
7
use Rudolf\Framework\Controller\AdminController;
8
use Rudolf\Framework\Model\FrontModel;
9
use Rudolf\Modules\Appearance\Menu\Model;
10
11
class ItemEditController extends AdminController
12
{
13
    /**
14
     * @param $id
15
     *
16
     * @throws \Exception
17
     */
18
    public function edit($id)
19
    {
20
        $model = new ItemEditModel();
21
        $view  = new ItemEditView();
22
23 View Code Duplication
        if (isset($_POST['update'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
24
            if ($model->edit($id, $_POST)) {
25
                AlertsCollection::add(new Alert(
26
                    'success',
27
                    'Zaktualizowano!'
28
                ));
29
                $this->redirectTo(DIR.'/admin/appearance/menu/edit-item/'.$id);
30
31
                return;
32
            }
33
            AlertsCollection::add(new Alert(
34
                'error',
35
                'Coś się zepsuło!'
36
            ));
37
        }
38
39
        $view->display($model->getInfo($id), (new Model())->getTypes(), (new FrontModel())->getMenuItems());
40
        $view->render();
41
    }
42
}
43