Completed
Push — master ( 16c56e...12b690 )
by VEBER
02:08
created

Application   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 0
cbo 5
dl 0
loc 93
ccs 26
cts 26
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getKernel() 0 4 1
A doRun() 0 6 1
A __construct() 0 18 2
A registerCommands() 0 8 3
1
<?php
2
3
/**
4
 * This file is part of the CLIFramework package.
5
 *
6
 * (c) Arnaud VEBER <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CLIFramework;
13
14
use Symfony\Component\Console\Application as BaseApplication;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\HttpKernel\KernelInterface;
19
20
/**
21
 * Application.
22
 */
23
class Application extends BaseApplication
24
{
25
    /**
26
     * name
27
     *
28
     * @const NAME
29
     */
30
    const NAME = 'CLIFramework';
31
32
    /**
33
     * version
34
     *
35
     * @const VERSION
36
     */
37
    const VERSION = '0.0.1-dev';
38
39
    /**
40
     * The kernel.
41
     *
42
     * @var \Symfony\Component\HttpKernel\KernelInterface $kernel
43
     */
44
    private $kernel;
45
46
    /**
47
     * The container.
48
     *
49
     * @var \Symfony\Component\DependencyInjection\ContainerInterface $container
50
     */
51
    private $container;
52
53
    /**
54
     * Construct the application.
55
     *
56
     * @param \Symfony\Component\HttpKernel\KernelInterface $kernel
57
     */
58 4
    public function __construct(KernelInterface $kernel)
59
    {
60 4
        $this->kernel = $kernel;
61 4
        $this->container = $kernel->getContainer();
62
63 4
        parent::__construct(self::NAME, self::VERSION);
64
65 4
        if ($this->container->has('event_dispatcher')) {
66 3
            $this->setDispatcher($this->container->get('event_dispatcher'));
67 3
        }
68
69 4
        $this->getDefinition()->addOption(
70 4
            new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev')
71 4
        );
72 4
        $this->getDefinition()->addOption(
73 4
            new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.')
74 4
        );
75 4
    }
76
77
    /**
78
     * Get kernel.
79
     *
80
     * @return \Symfony\Component\HttpKernel\KernelInterface
81
     */
82 1
    public function getKernel()
83
    {
84 1
        return $this->kernel;
85
    }
86
87
    /**
88
     * Runs the current application.
89
     *
90
     * @param \Symfony\Component\Console\Input\InputInterface $input
91
     * @param \Symfony\Component\Console\Output\OutputInterface $output
92
     *
93
     * @return int
94
     */
95 2
    public function doRun(InputInterface $input, OutputInterface $output)
96
    {
97 2
        $this->registerCommands();
98
99 2
        return parent::doRun($input, $output);
100
    }
101
102
    /**
103
     * Register commands into the application
104
     *
105
     * @return void
106
     */
107 2
    protected function registerCommands()
108
    {
109 2
        if ($this->container->hasParameter('app.command.ids')) {
110 2
            foreach ($this->container->getParameter('app.command.ids') as $id) {
111 1
                $this->add($this->container->get($id));
112 2
            }
113 2
        }
114 2
    }
115
}
116