Completed
Push — master ( 6c9dac...d3ec32 )
by Rougin
02:22
created

Instance   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 3
c 5
b 1
f 1
lcom 0
cbo 1
dl 0
loc 20
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 3
1
<?php
2
3
namespace Rougin\SparkPlug;
4
5
/**
6
 * Instance
7
 *
8
 * Creates an instance based on SparkPlug class.
9
 * 
10
 * @package SparkPlug
11
 * @author  Rougin Royce Gutib <[email protected]>
12
 */
13
class Instance
14
{
15
    /**
16
     * Creates an instance of CodeIgniter based on the application path.
17
     * 
18
     * @param  string $appPath
19
     * @param  array  $server
20
     * @param  array  $globals
21
     * @return \CI_Controller
22
     */
23 12
    public static function create($appPath = '', array $server = [], array $globals = [])
0 ignored issues
show
Coding Style introduced by
create uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
create uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
24
    {
25 12
        $globals = (empty($globals)) ? $GLOBALS : $globals;
26 12
        $server = (empty($server)) ? $_SERVER : $server;
27
28 12
        $sparkPlug = new SparkPlug($globals, $server, $appPath);
29
        
30 12
        return $sparkPlug->getCodeIgniter();
31
    }
32
}
33