Config   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 66
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
B define() 0 25 2
1
<?php
2
/**
3
 * Aura\Cli Provider for Aura\Di
4
 *
5
 * PHP version 5
6
 *
7
 * Copyright (C) 2016 Jake Johns
8
 *
9
 * This software may be modified and distributed under the terms
10
 * of the MIT license.  See the LICENSE file for details.
11
 *
12
 * @category  Config
13
 * @package   Fusible\CliProvider
14
 * @author    Jake Johns <[email protected]>
15
 * @copyright 2016 Jake Johns
16
 * @license   http://jnj.mit-license.org/2016 MIT License
17
 * @link      https://github.com/fusible/fusible.cli-provider
18
 */
19
20
namespace Fusible\CliProvider;
21
22
use Aura\Di\Container;
23
use Aura\Di\ContainerConfig;
24
25
use Aura\Cli\CliFactory as Factory;
26
use Aura\Cli\Context\OptionFactory;
27
use Aura\Cli\Help;
28
29
/**
30
 * Config
31
 *
32
 * @category Config
33
 * @package  Fusible\CliProvider
34
 * @author   Jake Johns <[email protected]>
35
 * @license  http://jnj.mit-license.org/2016 MIT License
36
 * @link     https://github.com/fusible/fusible.cli-provider
37
 *
38
 * @see ContainerConfig
39
 */
40
class Config extends ContainerConfig
41
{
42
    const GLOBALS = 'GLOBALS';
43
44
    const FACTORY = 'aura/cli:factory';
45
    const CONTEXT = 'aura/cli:context';
46
    const STDIO   = 'aura/cli:stdio';
47
48
    /**
49
     * Globals
50
     *
51
     * @var array
52
     *
53
     * @access protected
54
     */
55
    protected $globals;
56
57
    /**
58
     * __construct
59
     *
60
     * @param array $globals GLOBALS array
61
     *
62
     * @access public
63
     */
64 4
    public function __construct(array $globals = null)
0 ignored issues
show
Coding Style introduced by
__construct 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...
65
    {
66 4
        $this->globals = (null === $globals) ? $GLOBALS : $globals;
67 4
    }
68
69
    /**
70
     * Define Aura\Cli factories, services, and params
71
     *
72
     * @param Container $di DI Container
73
     *
74
     * @return void
75
     *
76
     * @access public
77
     *
78
     * @SuppressWarnings(PHPMD.ShortVariable)
79
     */
80 4
    public function define(Container $di)
81
    {
82 4
        if (! isset($di->values[static::GLOBALS])) {
83 4
            $di->values[static::GLOBALS] = $this->globals;
84 4
        }
85
86 4
        $di->set(static::FACTORY, $di->lazyNew(Factory::class));
87
88 4
        $di->set(
89 4
            static::CONTEXT,
90 4
            $di->lazyGetCall(
91 4
                static::FACTORY,
92 4
                'newContext',
93 4
                $di->lazyValue(static::GLOBALS)
94 4
            )
95 4
        );
96
97 4
        $di->set(
98 4
            static::STDIO,
99 4
            $di->lazyGetCall(static::FACTORY, 'newStdio')
100 4
        );
101
102 4
        $di->params[Help::class]
103 4
            ['option_factory'] = $di->lazyNew(OptionFactory::class);
104 4
    }
105
}
106