Completed
Branch master (7673a8)
by VEBER
03:49
created

Application::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4286
cc 2
eloc 10
nc 2
nop 1
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\DependencyInjection\ContainerInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
20
/**
21
 * Application.
22
 */
23
class Application extends BaseApplication
24
{
25
    const NAME = 'CLIFramework';
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
26
    const VERSION = '0.0.1-dev';
27
28
    /**
29
     * The kernel.
30
     *
31
     * @var \Symfony\Component\HttpKernel\KernelInterface $kernel
32
     */
33
    private $kernel;
34
35
    /**
36
     * The container.
37
     *
38
     * @var \Symfony\Component\DependencyInjection\ContainerInterface $container
39
     */
40
    private $container;
41
42
    /**
43
     * Construct the application.
44
     *
45
     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
0 ignored issues
show
Bug introduced by
There is no parameter named $container. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
46
     *
47
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
48
     */
49
    public function __construct(Kernel $kernel)
50
    {
51
        $this->kernel = $kernel;
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
52
        $this->container = $kernel->getContainer();
53
54
        parent::__construct(self::NAME, self::VERSION);
55
56
        if ($this->container->has('event_dispatcher')) {
57
            $this->setDispatcher($this->container->get('event_dispatcher'));
58
        }
59
60
        $this->getDefinition()->addOption(
61
            new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev')
62
        );
63
        $this->getDefinition()->addOption(
64
            new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.')
65
        );
66
    }
67
68
    /**
69
     * Get kernel.
70
     *
71
     * @return \Symfony\Component\HttpKernel\KernelInterface
72
     */
73
    public function getKernel()
74
    {
75
        return $this->kernel;
76
    }
77
78
    /**
79
     * Runs the current application.
80
     *
81
     * @param \Symfony\Component\Console\Input\InputInterface $input
82
     * @param \Symfony\Component\Console\Output\OutputInterface $output
83
     *
84
     * @return int
85
     */
86
    public function doRun(InputInterface $input, OutputInterface $output)
87
    {
88
        $this->registerCommands();
89
90
        return parent::doRun($input, $output);
91
    }
92
93
    /**
94
     * Register commands into the application
95
     *
96
     * @return void
97
     */
98
    protected function registerCommands()
99
    {
100
        if ($this->container->hasParameter('app.command.ids')) {
101
            foreach ($this->container->getParameter('app.command.ids') as $id) {
102
                $this->add($this->container->get($id));
103
            }
104
        }
105
    }
106
}
107