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

Controller   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 488
Duplicated Lines 2.05 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A redirect() 0 5 1

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Controller often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Controller, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * Controller
4
 * Base request handler, All controllers should be a child this class
5
 * or one of the subclasses (e.g. controllers/Ajax or controllers/Api)
6
 *
7
 * @package     erdiko
8
 * @copyright   2012-2017 Arroyo Labs, Inc. http://www.arroyolabs.com
9
 * @author      John Arroyo <[email protected]>
10
 */
11
namespace erdiko;
12
13
use Interop\Container\ContainerInterface;
14
15
16
class Controller
17
{
18
    protected $container;
19
   
20
    public function __construct(ContainerInterface $container) 
21
    {
22
        $this->container = $container;
23
    }
24
25
    /**
26
     * Redirect to another url
27
     * @param string $url
28
     */
29
    public function redirect($url)
30
    {
31
        header("Location: $url");
32
        exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method redirect() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
33
    }
34
}