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

Instance::create()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 3
eloc 5
nc 4
nop 3
crap 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