Completed
Branch erdiko2 (81b309)
by John
02:13
created

Ajax   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 38
loc 38
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A _before() 4 4 1
A setStatusCode() 6 6 2
A setErrors() 6 6 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
 * Ajax Controller
4
 *
5
 * @package     erdiko/controllers
6
 * @copyright   2012-2017 Arroyo Labs, Inc. http://www.arroyolabs.com
7
 * @author      John Arroyo <[email protected]>
8
 * @author      Andy Armstrong <[email protected]>
9
 */
10
namespace erdiko\controllers;
11
12
13 View Code Duplication
class Ajax extends \erdiko\Controller
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...
14
{
15
16
  /**
17
   * Contructor
18
   */
19
    public function __construct()
20
    {
21
        $this->_webroot = ERDIKO_ROOT;
0 ignored issues
show
Bug introduced by
The property _webroot does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
        $this->_response = new \erdiko\core\AjaxResponse;
0 ignored issues
show
Bug introduced by
The property _response does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
    }
24
25
    /** 
26
     * Before 
27
     */
28
    public function _before()
29
    {
30
        // Do nothing, it overrides the core before function which prepares for theming
31
    }
32
33
    /**
34
     * setStatusCode
35
     *
36
     */
37
    public function setStatusCode($code = null)
38
    {
39
        if (!empty($code)) {
40
            $this->_response->setStatusCode($code);
41
        }
42
    }
43
44
    public function setErrors($errors = null)
45
    {
46
        if (!empty($errors)) {
47
            $this->_response->setErrors($errors);
48
        }
49
    }
50
}
51