ManagerController   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 87
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 29
loc 87
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 6 1
A indexAction() 0 8 1
A addAction() 14 26 4
A editAction() 15 26 4
A deleteAction() 0 12 2

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
 * @copyright Copyright (c) 2011 - 2014 Oleksandr Torosh (http://wezoom.net)
4
 * @author Oleksandr Torosh <[email protected]>
5
 */
6
7
namespace Seo\Controller;
8
9
use Application\Mvc\Controller;
10
use Seo\Form\ManagerAddForm;
11
use Seo\Form\ManagerForm;
12
use Seo\Model\Manager;
13
14
class ManagerController extends Controller
15
{
16
17
    public function initialize()
18
    {
19
        $this->setAdminEnvironment();
20
        $this->helper->activeMenu()->setActive('seo-manager');
21
        $this->view->languages_disabled = true;
0 ignored issues
show
Bug introduced by
Accessing languages_disabled on the interface Phalcon\Mvc\ViewInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
22
    }
23
24
    public function indexAction()
25
    {
26
        $this->view->entries = Manager::find([
0 ignored issues
show
Bug introduced by
Accessing entries on the interface Phalcon\Mvc\ViewInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Bug introduced by
Are you sure the assignment to $this->view->entries is correct as \Seo\Model\Manager::find...('order' => 'id DESC')) (which targets Phalcon\Mvc\Model::find()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
27
            'order' => 'id DESC'
28
        ]);
29
30
        $this->helper->title('SEO-Manager', true);
31
    }
32
33
    public function addAction()
34
    {
35
        $this->view->pick(['manager/edit']);
36
        $model = new Manager();
37
        $form = new ManagerForm();
38
39 View Code Duplication
        if ($this->request->isPost()) {
40
            $post = $this->request->getPost();
41
            $form->bind($post, $model);
42
            if ($form->isValid()) {
43
                if ($model->save()) {
44
                    $this->flash->success('This entry was posted');
45
                    $this->redirect($this->url->get() . 'seo/manager');
46
                } else {
47
                    $this->flashErrors($model);
48
                }
49
            } else {
50
                $this->flashErrors($form);
51
            }
52
        }
53
54
        $this->helper->title('Create SEO-Manager record', true);
55
56
        $this->view->model = $model;
0 ignored issues
show
Bug introduced by
Accessing model on the interface Phalcon\Mvc\ViewInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
57
        $this->view->form = $form;
0 ignored issues
show
Bug introduced by
Accessing form on the interface Phalcon\Mvc\ViewInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
58
    }
59
60
    public function editAction($id)
61
    {
62
        $model = Manager::findFirst($id);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $model is correct as \Seo\Model\Manager::findFirst($id) (which targets Phalcon\Mvc\Model::findFirst()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
63
        $form = new ManagerForm();
64
65 View Code Duplication
        if ($this->request->isPost()) {
66
            $form->bind($this->request->getPost(), $model);
67
            if ($form->isValid()) {
68
                if ($model->save()) {
0 ignored issues
show
Bug introduced by
The method save cannot be called on $model (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
69
                    $this->flash->success('SEO record edited');
70
                    $this->redirect($this->url->get() . 'seo/manager/edit/' . $id);
71
                } else {
72
                    $this->flashErrors($model);
73
                }
74
            } else {
75
                $this->flashErrors($form);
76
            }
77
        } else {
78
            $form->setEntity($model);
79
        }
80
81
        $this->helper->title('Editing SEO-manager record', true);
82
83
        $this->view->model = $model;
0 ignored issues
show
Bug introduced by
Accessing model on the interface Phalcon\Mvc\ViewInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
84
        $this->view->form = $form;
0 ignored issues
show
Bug introduced by
Accessing form on the interface Phalcon\Mvc\ViewInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
85
    }
86
87
    public function deleteAction($id)
88
    {
89
        $model = Manager::findFirst($id);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $model is correct as \Seo\Model\Manager::findFirst($id) (which targets Phalcon\Mvc\Model::findFirst()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
90
91
        if ($this->request->isPost()) {
92
            $model->delete();
0 ignored issues
show
Bug introduced by
The method delete cannot be called on $model (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
93
            $this->redirect($this->url->get() . 'seo/manager');
94
        }
95
96
        $this->view->model = $model;
0 ignored issues
show
Bug introduced by
Accessing model on the interface Phalcon\Mvc\ViewInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
97
        $this->helper->title('Deleting SEO-Manager record', true);
98
    }
99
100
}