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

Api   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 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
 * Api Controller
4
 *
5
 * @package     erdiko/controllers
6
 * @copyright   2012-2017 Arroyo Labs, Inc. http://www.arroyolabs.com
7
 * @author      John Arroyo <[email protected]>
8
 */
9
namespace erdiko\controllers;
10
11
12 View Code Duplication
class Api 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...
13
{
14
15
  /**
16
   * Contructor
17
   */
18
    public function __construct()
19
    {
20
        $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...
21
        $this->_response = new \erdiko\core\ApiResponse;
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...
22
    }
23
24
  /**
25
   * setStatusCode
26
   *
27
   */
28
    public function setStatusCode($code = null)
29
    {
30
        if (!empty($code)) {
31
            $this->_response->setStatusCode($code);
32
        }
33
    }
34
35
    public function setErrors($errors = null)
36
    {
37
        if (!empty($errors)) {
38
            $this->_response->setErrors($errors);
39
        }
40
    }
41
}
42